Class: OpenTelemetry::Propagator::OTTrace::TextMapPropagator
- Inherits:
-
Object
- Object
- OpenTelemetry::Propagator::OTTrace::TextMapPropagator
- Defined in:
- lib/opentelemetry/propagator/ottrace/text_map_propagator.rb
Overview
Propagates context using OTTrace header format
Instance Method Summary collapse
-
#extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) ⇒ Context
Extract OTTrace context from the supplied carrier and set the active span in the given context.
-
#fields ⇒ Array<String>
Returns the predefined propagation fields.
- #inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) ⇒ Object
Instance Method Details
#extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) ⇒ Context
Extract OTTrace context from the supplied carrier and set the active span in the given context. The original context will be returned if OTTrace cannot be extracted from the carrier.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/opentelemetry/propagator/ottrace/text_map_propagator.rb', line 49 def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) trace_id = optionally_pad_trace_id(getter.get(carrier, TRACE_ID_HEADER)) span_id = getter.get(carrier, SPAN_ID_HEADER) sampled = getter.get(carrier, SAMPLED_HEADER) return context unless valid?(trace_id: trace_id, span_id: span_id) span_context = Trace::SpanContext.new( trace_id: Array(trace_id).pack('H*'), span_id: Array(span_id).pack('H*'), trace_flags: as_trace_flags(sampled), remote: true ) span = OpenTelemetry::Trace.non_recording_span(span_context) Trace.context_with_span(span, parent_context: set_baggage(carrier: carrier, context: context, getter: getter)) 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+.
86 87 88 |
# File 'lib/opentelemetry/propagator/ottrace/text_map_propagator.rb', line 86 def fields FIELDS end |
#inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/opentelemetry/propagator/ottrace/text_map_propagator.rb', line 72 def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) span_context = Trace.current_span(context).context return unless span_context.valid? inject_span_context(span_context: span_context, carrier: carrier, setter: setter) inject_baggage(context: context, carrier: carrier, setter: setter) nil end |