Class: OpenTelemetry::Trace::Propagation::TraceContext::TextMapInjector
- Inherits:
-
Object
- Object
- OpenTelemetry::Trace::Propagation::TraceContext::TextMapInjector
- Defined in:
- lib/opentelemetry/trace/propagation/trace_context/text_map_injector.rb
Overview
Injects context into carriers using the W3C Trace Context format
Instance Method Summary collapse
-
#initialize(default_setter = Context::Propagation.text_map_setter) ⇒ TextMapInjector
constructor
Returns a new TextMapInjector that injects 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 context using the specified setter
19 20 21 |
# File 'lib/opentelemetry/trace/propagation/trace_context/text_map_injector.rb', line 19 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.
30 31 32 33 34 35 36 37 38 |
# File 'lib/opentelemetry/trace/propagation/trace_context/text_map_injector.rb', line 30 def inject(carrier, context, setter = nil) return carrier unless (span_context = span_context_from(context)) setter ||= @default_setter setter.set(carrier, TRACEPARENT_KEY, TraceParent.from_span_context(span_context).to_s) setter.set(carrier, TRACESTATE_KEY, span_context.tracestate.to_s) unless span_context.tracestate.empty? carrier end |