Class: OpenTelemetry::Trace::Propagation::TraceContext::TextMapPropagator
- Inherits:
-
Object
- Object
- OpenTelemetry::Trace::Propagation::TraceContext::TextMapPropagator
- Defined in:
- lib/opentelemetry/trace/propagation/trace_context/text_map_propagator.rb
Overview
Propagates trace context using the W3C Trace Context format
Instance Method Summary collapse
-
#extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) ⇒ Context
Extract trace context from the supplied carrier.
-
#fields ⇒ Array<String>
Returns the predefined propagation fields.
-
#inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) ⇒ Object
Inject trace context into the supplied carrier.
Instance Method Details
#extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) ⇒ Context
Extract trace context from the supplied carrier. If extraction fails, the original context will be returned
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/opentelemetry/trace/propagation/trace_context/text_map_propagator.rb', line 47 def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) trace_parent_value = getter.get(carrier, TRACEPARENT_KEY) return context unless trace_parent_value tp = TraceParent.from_string(trace_parent_value) tracestate = Tracestate.from_string(getter.get(carrier, TRACESTATE_KEY)) span_context = Trace::SpanContext.new(trace_id: tp.trace_id, span_id: tp.span_id, trace_flags: tp.flags, tracestate: tracestate, remote: true) span = OpenTelemetry::Trace.non_recording_span(span_context) OpenTelemetry::Trace.context_with_span(span, parent_context: context) rescue OpenTelemetry::Error context end |
#fields ⇒ Array<String>
Returns the predefined propagation fields. If your carrier is reused, you should delete the fields returned by this method before calling inject
.
69 70 71 |
# File 'lib/opentelemetry/trace/propagation/trace_context/text_map_propagator.rb', line 69 def fields FIELDS end |
#inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) ⇒ Object
Inject trace context into the supplied carrier.
26 27 28 29 30 31 32 33 |
# File 'lib/opentelemetry/trace/propagation/trace_context/text_map_propagator.rb', line 26 def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) span_context = Trace.current_span(context).context return unless span_context.valid? 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? nil end |