Class: OpenTelemetry::Propagator::B3::Single::TextMapInjector
- Inherits:
-
Object
- Object
- OpenTelemetry::Propagator::B3::Single::TextMapInjector
- Defined in:
- lib/opentelemetry/propagator/b3/single/text_map_injector.rb
Overview
Injects context into carriers using the b3 single header format
Instance Method Summary collapse
-
#initialize(default_setter = Context::Propagation.text_map_setter) ⇒ TextMapInjector
constructor
Returns a new TextMapInjector that injects b3 context using the specified setter.
-
#inject(carrier, context, setter = nil) ⇒ Object
Set the span context on the supplied carrier.
Constructor Details
#initialize(default_setter = Context::Propagation.text_map_setter) ⇒ TextMapInjector
Returns a new TextMapInjector that injects b3 context using the specified setter
22 23 24 |
# File 'lib/opentelemetry/propagator/b3/single/text_map_injector.rb', line 22 def initialize(default_setter = Context::Propagation.text_map_setter) @default_setter = default_setter end |
Instance Method Details
#inject(carrier, context, setter = nil) ⇒ Object
Set the span context on the supplied carrier.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/opentelemetry/propagator/b3/single/text_map_injector.rb', line 33 def inject(carrier, context, setter = nil) span_context = Trace.current_span(context).context return unless span_context.valid? sampling_state = if B3.debug?(context) 'd' elsif span_context.trace_flags.sampled? '1' else '0' end b3_value = "#{span_context.hex_trace_id}-#{span_context.hex_span_id}-#{sampling_state}" setter ||= @default_setter setter.set(carrier, B3_CONTEXT_KEY, b3_value) carrier end |