Class: Jaeger::Extractors::B3CodecCommon

Inherits:
Object
  • Object
show all
Defined in:
lib/jaeger/extractors.rb

Class Method Summary collapse

Class Method Details

.extract(carrier, keys) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/jaeger/extractors.rb', line 96

def self.extract(carrier, keys)
  return nil if carrier[keys::TRACE_ID].nil? || carrier[keys::SPAN_ID].nil?

  trace_id = if carrier[keys::TRACE_ID].length <= 16
               TraceId.base16_hex_id_to_uint64(carrier[keys::TRACE_ID])
             else
               TraceId.base16_hex_id_to_uint128(carrier[keys::TRACE_ID])
             end

  span_id = TraceId.base16_hex_id_to_uint64(carrier[keys::SPAN_ID])
  parent_id = TraceId.base16_hex_id_to_uint64(carrier[keys::PARENT_SPAN_ID])
  flags = parse_flags(carrier[keys::FLAGS], carrier[keys::SAMPLED])

  return nil if span_id.zero? || trace_id.zero?

  SpanContext.new(
    trace_id: trace_id,
    parent_id: parent_id,
    span_id: span_id,
    flags: flags
  )
end