Class: Hermes::TraceContext

Inherits:
Object
  • Object
show all
Defined in:
lib/hermes/trace_context.rb

Instance Method Summary collapse

Constructor Details

#initialize(origin_event_headers = {}) ⇒ TraceContext

Returns a new instance of TraceContext.



10
11
12
# File 'lib/hermes/trace_context.rb', line 10

def initialize(origin_event_headers = {})
  @origin_event_headers = origin_event_headers.to_h
end

Instance Method Details

#parent_spanObject



22
23
24
# File 'lib/hermes/trace_context.rb', line 22

def parent_span
  origin_event_headers.fetch(Hermes::B3PropagationModelHeaders.span_id_key, nil)
end

#serviceObject



26
27
28
# File 'lib/hermes/trace_context.rb', line 26

def service
  Hermes.configuration.application_prefix or raise "missing application prefix!"
end

#spanObject



18
19
20
# File 'lib/hermes/trace_context.rb', line 18

def span
  @span ||= [trace[0..last_trace_index_for_span], DELIMITER, service_seed_for_span, DELIMITER, uuid].join
end

#traceObject



14
15
16
# File 'lib/hermes/trace_context.rb', line 14

def trace
  @trace ||= origin_event_headers.fetch(Hermes::B3PropagationModelHeaders.trace_id_key, SecureRandom.hex(32))
end