Class: NewRelic::Agent::OpenTelemetry::Context::Propagation::TracePropagator

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/opentelemetry/context/propagation/trace_propagator.rb

Instance Method Summary collapse

Instance Method Details

#extract(carrier, context: ::OpenTelemetry::Context.current, getter: ::OpenTelemetry::Context::Propagation.text_map_getter) ⇒ Object

The return value for this method should be an instance of the OpenTelemetry Context class. The return value of #accept_distributed_trace_headers is a transaction, so we cannot use it to extract the context.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/new_relic/agent/opentelemetry/context/propagation/trace_propagator.rb', line 23

def extract(carrier, context: ::OpenTelemetry::Context.current, getter: ::OpenTelemetry::Context::Propagation.text_map_getter)
  carrier_format = determine_format(getter)
  trace_context = NewRelic::Agent::DistributedTracing::TraceContext.parse(
    carrier: carrier,
    format: carrier_format,
    trace_state_entry_key: Transaction::TraceContext::AccountHelpers.trace_state_entry_key
  )
  tp = trace_context.trace_parent
  span_context = ::OpenTelemetry::Trace::SpanContext.new(
    trace_id: tp['trace_id'],
    span_id: tp['parent_id'],
    trace_flags: tp['trace_flags'],
    tracestate: trace_context.trace_state_payload,
    remote: true
  )
  span = ::OpenTelemetry::Trace.non_recording_span(span_context)

  ::OpenTelemetry::Trace.context_with_span(span, parent_context: context)
rescue StandardError => e
  NewRelic::Agent.logger.error("Unable to extract context: #{e.message}")
  context
end

#inject(carrier, context: ::OpenTelemetry::Context.current, setter: nil) ⇒ Object

The carrier is the object carrying the headers The context argument is a no-op, as the OpenTelemetry context is not used The setter argument is a no-op, added for consistency with the OpenTelemetry API



14
15
16
17
# File 'lib/new_relic/agent/opentelemetry/context/propagation/trace_propagator.rb', line 14

def inject(carrier, context: ::OpenTelemetry::Context.current, setter: nil)
  # TODO: determine if we need to update this method to take Context into account
  NewRelic::Agent::DistributedTracing.insert_distributed_trace_headers(carrier)
end