Module: Honeycomb
- Defined in:
- lib/honeycomb/span.rb,
lib/honeycomb/client.rb,
lib/honeycomb-beeline.rb,
lib/honeycomb/env_config.rb,
lib/honeycomb/beeline/version.rb,
lib/honeycomb-beeline/auto_install.rb
Defined Under Namespace
Constant Summary collapse
- USER_AGENT_SUFFIX =
"#{Beeline::GEM_NAME}/#{Beeline::VERSION}"
- ENV_CONFIG =
begin writekey = ENV['HONEYCOMB_WRITEKEY'] dataset = ENV['HONEYCOMB_DATASET'] || ENV['PWD'].split('/').last withouts = ENV['HONEYCOMB_WITHOUT'] || '' without = withouts.split(',').map(&:to_sym) if writekey {writekey: writekey, dataset: dataset, without: without}.freeze end end
- DEBUG =
if ENV.key?('HONEYCOMB_DEBUG') ENV['HONEYCOMB_DEBUG'].upcase.to_sym end
Class Attribute Summary collapse
-
.client ⇒ Object
readonly
Returns the value of attribute client.
Class Method Summary collapse
- .after_init(label, &block) ⇒ Object
- .init(writekey:, dataset:, logger: nil, without: [], **options) ⇒ Object
- .span(service_name:, name:, span_id: SecureRandom.uuid) ⇒ Object
- .trace_id ⇒ Object
- .with_span_id(span_id) ⇒ Object
- .with_trace_id(trace_id = SecureRandom.uuid) ⇒ Object
Class Attribute Details
.client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/honeycomb/client.rb', line 7 def client @client end |
Class Method Details
.after_init(label, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/honeycomb/client.rb', line 22 def after_init(label, &block) raise ArgumentError unless block_given? hook = if block.arity == 0 ->(_) { block.call } elsif block.arity > 1 raise ArgumentError, 'Honeycomb.after_init block should take 1 argument' else block end if @initialized @logger.debug "Running hook '#{label}' as Honeycomb already initialized" if @logger run_hook(label, hook) else after_init_hooks << [label, hook] end end |
.init(writekey:, dataset:, logger: nil, without: [], **options) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/honeycomb/client.rb', line 9 def init(writekey:, dataset:, logger: nil, without: [], **) = .merge(writekey: writekey, dataset: dataset) @logger = logger @without = without = {user_agent_addition: USER_AGENT_SUFFIX}.merge() @client = Libhoney::Client.new() after_init_hooks.each do |label, block| @logger.debug "Running hook '#{label}' after Honeycomb.init" if @logger run_hook(label, block) end end |
.span(service_name:, name:, span_id: SecureRandom.uuid) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/honeycomb/span.rb', line 27 def span(service_name:, name:, span_id: SecureRandom.uuid) event = client.event event.add_field :traceId, trace_id if trace_id event.add_field :serviceName, service_name event.add_field :name, name event.add_field :id, span_id start = Time.now with_span_id(span_id) do |parent_span_id| event.add_field :parentId, parent_span_id if parent_span_id yield end rescue Exception => e if event event.add_field :exception_class, e.class.name event.add_field :exception_message, e. end raise ensure if start && event finish = Time.now duration = finish - start event.add_field :durationMs, duration * 1000 event.send end end |
.trace_id ⇒ Object
15 16 17 |
# File 'lib/honeycomb/span.rb', line 15 def trace_id Thread.current[:honeycomb_trace_id] end |
.with_span_id(span_id) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/honeycomb/span.rb', line 19 def with_span_id(span_id) parent_span_id = Thread.current[:honeycomb_span_id] Thread.current[:honeycomb_span_id] = span_id yield parent_span_id ensure Thread.current[:honeycomb_span_id] = parent_span_id end |
.with_trace_id(trace_id = SecureRandom.uuid) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/honeycomb/span.rb', line 8 def with_trace_id(trace_id = SecureRandom.uuid) Thread.current[:honeycomb_trace_id] = trace_id yield trace_id ensure Thread.current[:honeycomb_trace_id] = nil end |