Module: Datadog::DistributedTracing::Headers::B3
- Includes:
- Ext::DistributedTracing
- Defined in:
- lib/ddtrace/distributed_tracing/headers/b3.rb
Overview
B3 provides helpers to inject or extract headers for B3 style headers
Constant Summary
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
Class Method Details
.extract(env) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ddtrace/distributed_tracing/headers/b3.rb', line 25 def self.extract(env) # Extract values from headers # DEV: B3 doesn't have "origin" headers = Headers.new(env) trace_id = headers.id(B3_HEADER_TRACE_ID, 16) span_id = headers.id(B3_HEADER_SPAN_ID, 16) # We don't need to try and convert sampled since B3 supports 0/1 (AUTO_REJECT/AUTO_KEEP) sampling_priority = headers.number(B3_HEADER_SAMPLED) # Return early if this propagation is not valid return unless trace_id && span_id ::Datadog::Context.new(trace_id: trace_id, span_id: span_id, sampling_priority: sampling_priority) end |
.inject!(context, env) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ddtrace/distributed_tracing/headers/b3.rb', line 12 def self.inject!(context, env) return if context.nil? # DEV: We need these to be hex encoded env[B3_HEADER_TRACE_ID] = context.trace_id.to_s(16) env[B3_HEADER_SPAN_ID] = context.span_id.to_s(16) unless context.sampling_priority.nil? sampling_priority = DistributedTracing::Headers::Helpers.clamp_sampling_priority(context.sampling_priority) env[B3_HEADER_SAMPLED] = sampling_priority.to_s end end |