Module: Datadog::OpenTracer::TextMapPropagator
- Extended by:
- Propagator
- Defined in:
- lib/datadog/opentracer/text_map_propagator.rb
Overview
OpenTracing propagator for Datadog::OpenTracer::Tracer
Constant Summary collapse
- BAGGAGE_PREFIX =
'ot-baggage-'.freeze
Class Method Summary collapse
-
.extract(carrier) ⇒ SpanContext?
Extract a SpanContext in TextMap format from the given carrier.
-
.inject(span_context, carrier) ⇒ Object
Inject a SpanContext into the given carrier.
Methods included from Propagator
Class Method Details
.extract(carrier) ⇒ SpanContext?
Extract a SpanContext in TextMap format from the given carrier.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/datadog/opentracer/text_map_propagator.rb', line 46 def extract(carrier) # First extract & build a Datadog context headers = DistributedHeaders.new(carrier) datadog_trace_digest = headers_to_trace_digest(headers) # Then extract any other baggage baggage = {} carrier.each do |key, value| baggage[item_to_baggage(key)] = value if baggage_item?(key) end SpanContextFactory.build( datadog_context: nil, datadog_trace_digest: datadog_trace_digest, baggage: baggage ) end |
.inject(span_context, carrier) ⇒ Object
Inject a SpanContext into the given carrier
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/datadog/opentracer/text_map_propagator.rb', line 19 def inject(span_context, carrier) # Inject baggage span_context.baggage.each do |key, value| carrier[BAGGAGE_PREFIX + key] = value end # Inject Datadog trace properties digest = if span_context.datadog_context && span_context.datadog_context.active_trace span_context.datadog_context.active_trace.to_digest else span_context.datadog_trace_digest end return unless digest carrier[Tracing::Distributed::Datadog::ORIGIN_KEY] = digest.trace_origin carrier[Tracing::Distributed::Datadog::PARENT_ID_KEY] = digest.span_id carrier[Tracing::Distributed::Datadog::SAMPLING_PRIORITY_KEY] = digest.trace_sampling_priority carrier[Tracing::Distributed::Datadog::TRACE_ID_KEY] = Datadog::Tracing::Utils::TraceId.to_low_order(digest.trace_id) nil end |