class OpenTelemetry::Trace::Propagation::TraceContext::TextMapExtractor

Extracts context from carriers in the W3C Trace Context format

def extract(carrier, context, &getter)

Returns:
  • (Context) - Updated context with span context from the header, or the original

Other tags:
    Yield: - if an optional getter is provided, extract will yield the carrier

Parameters:
  • getter (optional Callable) -- An optional callable that takes a carrier and a key and
  • context (Context) -- The context to be updated with extracted context
  • carrier (Carrier) -- The carrier to get the header from.
def extract(carrier, context, &getter)
  getter ||= default_getter
  header = getter.call(carrier, @traceparent_key)
  tp = TraceParent.from_string(header)
  tracestate = getter.call(carrier, @tracestate_key)
  span_context = Trace::SpanContext.new(trace_id: tp.trace_id,
                                        span_id: tp.span_id,
                                        trace_flags: tp.flags,
                                        tracestate: tracestate,
                                        remote: true)
  span = Trace::Span.new(span_context: span_context)
  context.set_value(ContextKeys.current_span_key, span)
rescue OpenTelemetry::Error
  context
end

def initialize(traceparent_key: 'traceparent',

Returns:
  • (TextMapExtractor) -

Parameters:
  • tracestate_key (String) -- The tracestate header key used in the carrier
  • traceparent_key (String) -- The traceparent header key used in the carrier
def initialize(traceparent_key: 'traceparent',
               tracestate_key: 'tracestate')
  @traceparent_key = traceparent_key
  @tracestate_key = tracestate_key
end