Module: Datadog::OpenTracer::RackPropagator

Extended by:
Ext::DistributedTracing, Propagator
Includes:
Ext::DistributedTracing
Defined in:
lib/ddtrace/opentracer/rack_propagator.rb

Overview

OpenTracing propagator for Datadog::OpenTracer::Tracer

Constant Summary collapse

BAGGAGE_PREFIX =
'ot-baggage-'.freeze
BAGGAGE_PREFIX_FORMATTED =
'HTTP_OT_BAGGAGE_'.freeze

Constants included from Ext::DistributedTracing

Ext::DistributedTracing::B3_HEADER_SAMPLED, Ext::DistributedTracing::B3_HEADER_SINGLE, Ext::DistributedTracing::B3_HEADER_SPAN_ID, Ext::DistributedTracing::B3_HEADER_TRACE_ID, Ext::DistributedTracing::GRPC_METADATA_ORIGIN, Ext::DistributedTracing::GRPC_METADATA_PARENT_ID, Ext::DistributedTracing::GRPC_METADATA_SAMPLING_PRIORITY, Ext::DistributedTracing::GRPC_METADATA_TRACE_ID, Ext::DistributedTracing::HTTP_HEADER_ORIGIN, Ext::DistributedTracing::HTTP_HEADER_PARENT_ID, Ext::DistributedTracing::HTTP_HEADER_SAMPLING_PRIORITY, Ext::DistributedTracing::HTTP_HEADER_TRACE_ID, Ext::DistributedTracing::ORIGIN_KEY, Ext::DistributedTracing::PROPAGATION_EXTRACT_STYLE_ENV, Ext::DistributedTracing::PROPAGATION_INJECT_STYLE_ENV, Ext::DistributedTracing::PROPAGATION_STYLE_B3, Ext::DistributedTracing::PROPAGATION_STYLE_B3_SINGLE_HEADER, Ext::DistributedTracing::PROPAGATION_STYLE_DATADOG, Ext::DistributedTracing::SAMPLING_PRIORITY_KEY

Class Method Summary collapse

Methods included from Propagator

extract, inject

Class Method Details

.extract(carrier) ⇒ SpanContext?

Extract a SpanContext in Rack format from the given carrier.

Parameters:

  • carrier (Carrier)

    A carrier object of Rack type

Returns:

  • (SpanContext, nil)

    the extracted SpanContext or nil if none could be found



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ddtrace/opentracer/rack_propagator.rb', line 35

def extract(carrier)
  # First extract & build a Datadog context
  datadog_context = Datadog::HTTPPropagator.extract(carrier)

  # Then extract any other baggage
  baggage = {}
  carrier.each do |key, value|
    baggage[header_to_baggage(key)] = value if baggage_header?(key)
  end

  SpanContextFactory.build(datadog_context: datadog_context, baggage: baggage)
end

.inject(span_context, carrier) ⇒ Object

Inject a SpanContext into the given carrier

Parameters:



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ddtrace/opentracer/rack_propagator.rb', line 19

def inject(span_context, carrier)
  # Inject Datadog trace properties
  Datadog::HTTPPropagator.inject!(span_context.datadog_context, carrier)

  # Inject baggage
  span_context.baggage.each do |key, value|
    carrier[BAGGAGE_PREFIX + key] = value
  end

  nil
end