Class: OpenTelemetry::Propagator::B3::Single::TextMapInjector
- Inherits:
-
Object
- Object
- OpenTelemetry::Propagator::B3::Single::TextMapInjector
- Includes:
- Context::Propagation::DefaultSetter
- 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(b3_key: 'b3') ⇒ TextMapInjector
constructor
Returns a new TextMapInjector that extracts b3 context using the specified header keys.
-
#inject(carrier, context, &setter) {|Carrier, String, String| ... } ⇒ Object
Set the span context on the supplied carrier.
Constructor Details
#initialize(b3_key: 'b3') ⇒ TextMapInjector
Returns a new TextMapInjector that extracts b3 context using the specified header keys
22 23 24 |
# File 'lib/opentelemetry/propagator/b3/single/text_map_injector.rb', line 22 def initialize(b3_key: 'b3') @b3_key = b3_key end |
Instance Method Details
#inject(carrier, context, &setter) {|Carrier, String, String| ... } ⇒ Object
Set the span context on the supplied carrier.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/opentelemetry/propagator/b3/single/text_map_injector.rb', line 35 def inject(carrier, context, &setter) 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.call(carrier, @b3_key, b3_value) carrier end |