Class: Honeycomb::Client
- Inherits:
-
Object
- Object
- Honeycomb::Client
- Extended by:
- Forwardable
- Defined in:
- lib/honeycomb/client.rb
Overview
The Honeycomb Beeline client
Instance Attribute Summary collapse
-
#libhoney ⇒ Object
readonly
Returns the value of attribute libhoney.
Instance Method Summary collapse
- #add_field(key, value) ⇒ Object
- #add_field_to_trace(key, value) ⇒ Object
-
#initialize(configuration:) ⇒ Client
constructor
A new instance of Client.
- #start_span(name:, serialized_trace: nil, **fields) ⇒ Object
- #with_field(key) ⇒ Object
- #with_trace_field(key) ⇒ Object
Constructor Details
permalink #initialize(configuration:) ⇒ Client
Returns a new instance of Client.
17 18 19 20 21 22 23 24 25 26 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 |
# File 'lib/honeycomb/client.rb', line 17 def initialize(configuration:) @libhoney = configuration.client # attempt to set the user_agent_addition, this will only work if the # client has not sent an event prior to being passed in here. This should # be most cases @libhoney.instance_variable_set(:@user_agent_addition, Honeycomb::Beeline::USER_AGENT_SUFFIX) @libhoney.add_field "meta.beeline_version", Honeycomb::Beeline::VERSION @libhoney.add_field "meta.local_hostname", configuration.host_name integrations = Honeycomb.integrations_to_load @libhoney.add_field "meta.instrumentations_count", integrations.count @libhoney.add_field "meta.instrumentations", integrations.map(&:to_s).to_s # maybe make `service_name` a required parameter @libhoney.add_field "service_name", configuration.service_name @libhoney.add_field "service.name", configuration.service_name @context = Context.new @context.classic = configuration.classic? @additional_trace_options = { presend_hook: configuration.presend_hook, sample_hook: configuration.sample_hook, parser_hook: configuration.http_trace_parser_hook, propagation_hook: configuration.http_trace_propagation_hook, } @error_backtrace_limit = configuration.error_backtrace_limit.to_i configuration.after_initialize(self) at_exit do libhoney.close end end |
Instance Attribute Details
permalink #libhoney ⇒ Object (readonly)
Returns the value of attribute libhoney.
13 14 15 |
# File 'lib/honeycomb/client.rb', line 13 def libhoney @libhoney end |
Instance Method Details
permalink #add_field(key, value) ⇒ Object
[View source]
75 76 77 78 79 |
# File 'lib/honeycomb/client.rb', line 75 def add_field(key, value) return if context.current_span.nil? context.current_span.add_field("app.#{key}", value) end |
permalink #add_field_to_trace(key, value) ⇒ Object
[View source]
81 82 83 84 85 |
# File 'lib/honeycomb/client.rb', line 81 def add_field_to_trace(key, value) return if context.current_span.nil? context.current_span.trace.add_field("app.#{key}", value) end |
permalink #start_span(name:, serialized_trace: nil, **fields) ⇒ Object
[View source]
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/honeycomb/client.rb', line 53 def start_span(name:, serialized_trace: nil, **fields) current_span = new_span_for_context(serialized_trace: serialized_trace) fields.each do |key, value| current_span.add_field(key, value) end current_span.add_field("name", name) return current_span unless block_given? begin yield current_span rescue StandardError => e add_exception_data(current_span, e) raise e ensure current_span.send end end |
permalink #with_field(key) ⇒ Object
[View source]
87 88 89 |
# File 'lib/honeycomb/client.rb', line 87 def with_field(key) yield.tap { |value| add_field(key, value) } end |
permalink #with_trace_field(key) ⇒ Object
[View source]
91 92 93 |
# File 'lib/honeycomb/client.rb', line 91 def with_trace_field(key) yield.tap { |value| add_field_to_trace(key, value) } end |