class Honeycomb::Client
Attributes
context[R]
error_backtrace_limit[R]
libhoney[R]
Public Class Methods
new(configuration:)
click to toggle source
# 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 @context = Context.new @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
Public Instance Methods
add_field(key, value)
click to toggle source
# File lib/honeycomb/client.rb, line 72 def add_field(key, value) return if context.current_span.nil? context.current_span.add_field("app.#{key}", value) end
add_field_to_trace(key, value)
click to toggle source
# File lib/honeycomb/client.rb, line 78 def add_field_to_trace(key, value) return if context.current_span.nil? context.current_span.trace.add_field("app.#{key}", value) end
start_span(name:, serialized_trace: nil, **fields) { |current_span| ... }
click to toggle source
# File lib/honeycomb/client.rb, line 50 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
with_field(key) { || ... }
click to toggle source
# File lib/honeycomb/client.rb, line 84 def with_field(key) yield.tap { |value| add_field(key, value) } end
with_trace_field(key) { || ... }
click to toggle source
# File lib/honeycomb/client.rb, line 88 def with_trace_field(key) yield.tap { |value| add_field_to_trace(key, value) } end
Private Instance Methods
add_exception_data(span, exception)
click to toggle source
# File lib/honeycomb/client.rb, line 111 def add_exception_data(span, exception) span.add_field("error", exception.class.name) span.add_field("error_detail", exception.message) return if error_backtrace_limit <= 0 span.add_field( "error_backtrace", exception .backtrace .take(error_backtrace_limit) .join("\n") .encode("UTF-8", invalid: :replace, undef: :replace, replace: "�"), ) span.add_field("error_backtrace_limit", error_backtrace_limit) span.add_field("error_backtrace_total_length", exception.backtrace.length) end
new_span_for_context(serialized_trace:)
click to toggle source
# File lib/honeycomb/client.rb, line 96 def new_span_for_context(serialized_trace:) if context.current_trace.nil? Trace.new( serialized_trace: serialized_trace, builder: libhoney.builder, context: context, **@additional_trace_options, ) else context.current_span.create_child end context.current_span end