Class: OpenTelemetry::Propagator::Jaeger::TextMapPropagator
- Inherits:
-
Object
- Object
- OpenTelemetry::Propagator::Jaeger::TextMapPropagator
- Defined in:
- lib/opentelemetry/propagator/jaeger/text_map_propagator.rb
Overview
Propagates trace context using the Jaeger 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
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/opentelemetry/propagator/jaeger/text_map_propagator.rb', line 46 def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) header = getter.get(carrier, IDENTITY_KEY) return context unless header return context unless (match = header.match(TRACE_SPAN_IDENTITY_REGEX)) return context if match['trace_id'] =~ ZERO_ID_REGEX return context if match['span_id'] =~ ZERO_ID_REGEX sampling_flags = match['sampling_flags'].to_i span = build_span(match, sampling_flags) context = Jaeger.context_with_debug(context) if sampling_flags & DEBUG_FLAG_BIT != 0 context = context_with_extracted_baggage(carrier, context, getter) Trace.context_with_span(span, parent_context: 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
.
88 89 90 |
# File 'lib/opentelemetry/propagator/jaeger/text_map_propagator.rb', line 88 def fields FIELDS end |
#inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) ⇒ Object
Inject trace context into the supplied carrier.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/opentelemetry/propagator/jaeger/text_map_propagator.rb', line 67 def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) span_context = Trace.current_span(context).context return unless span_context.valid? flags = to_jaeger_flags(context, span_context) trace_span_identity_value = [ span_context.hex_trace_id, span_context.hex_span_id, '0', flags ].join(':') setter.set(carrier, IDENTITY_KEY, trace_span_identity_value) OpenTelemetry::Baggage.values(context: context).each do |key, value| baggage_key = 'uberctx-' + key encoded_value = CGI.escape(value) setter.set(carrier, baggage_key, encoded_value) end carrier end |