class Honeycomb::Trace
Represents a Honeycomb
trace, which groups spans together
Constants
- INVALID_TRACE_ID
Attributes
fields[R]
id[R]
root_span[R]
Public Class Methods
new(builder:, context:, serialized_trace: nil, **options)
click to toggle source
# File lib/honeycomb/trace.rb, line 20 def initialize(builder:, context:, serialized_trace: nil, **options) trace_id, parent_span_id, trace_fields, dataset = internal_parse(serialized_trace: serialized_trace, **options) dataset && builder.dataset = dataset @id = trace_id || generate_trace_id @fields = trace_fields || {} @root_span = Span.new(trace: self, parent_id: parent_span_id, is_root: true, builder: builder, context: context, **options) end
Public Instance Methods
add_field(key, value)
click to toggle source
# File lib/honeycomb/trace.rb, line 35 def add_field(key, value) @fields[key] = value end
Private Instance Methods
generate_trace_id()
click to toggle source
# File lib/honeycomb/trace.rb, line 43 def generate_trace_id loop do id = SecureRandom.hex(16) return id unless id == INVALID_TRACE_ID end end
internal_parse(serialized_trace: nil, parser_hook: nil, **_options)
click to toggle source
# File lib/honeycomb/trace.rb, line 50 def internal_parse(serialized_trace: nil, parser_hook: nil, **_options) # previously we passed in the header directly as a string for us to parse # now we get passed the rack env to use as an argument to the provided # parser_hook. This preserves the current behaviour and allows us to # move forward with the new behaviour without breaking changes if serialized_trace.is_a?(Hash) && parser_hook parser_hook.call(serialized_trace) else parse serialized_trace end end