Module: Datadog::HTTPPropagator

Includes:
Ext::DistributedTracing
Defined in:
lib/ddtrace/propagation/http_propagator.rb

Overview

HTTPPropagator helps extracting and injecting HTTP headers.

Constant Summary

Constants included from Ext::DistributedTracing

Ext::DistributedTracing::HTTP_HEADER_PARENT_ID, Ext::DistributedTracing::HTTP_HEADER_SAMPLING_PRIORITY, Ext::DistributedTracing::HTTP_HEADER_TRACE_ID, Ext::DistributedTracing::SAMPLING_PRIORITY_KEY

Class Method Summary collapse

Class Method Details

.extract(env) ⇒ Object

extract returns a context containing the span ID, trace ID and sampling priority defined in env.



20
21
22
23
24
25
26
# File 'lib/ddtrace/propagation/http_propagator.rb', line 20

def self.extract(env)
  headers = DistributedHeaders.new(env)
  return Datadog::Context.new unless headers.valid?
  Datadog::Context.new(trace_id: headers.trace_id,
                       span_id: headers.parent_id,
                       sampling_priority: headers.sampling_priority)
end

.inject!(context, env) ⇒ Object

inject! popolates the env with span ID, trace ID and sampling priority



11
12
13
14
15
16
# File 'lib/ddtrace/propagation/http_propagator.rb', line 11

def self.inject!(context, env)
  env[HTTP_HEADER_TRACE_ID] = context.trace_id.to_s
  env[HTTP_HEADER_PARENT_ID] = context.span_id.to_s
  env[HTTP_HEADER_SAMPLING_PRIORITY] = context.sampling_priority.to_s
  env.delete(HTTP_HEADER_SAMPLING_PRIORITY) unless context.sampling_priority
end