Class: OpenTelemetry::Propagator::XRay::TextMapPropagator
- Inherits:
-
Object
- Object
- OpenTelemetry::Propagator::XRay::TextMapPropagator
- Defined in:
- lib/opentelemetry/propagator/xray/text_map_propagator.rb
Overview
Propagates context in carriers in the xray single header format
Direct Known Subclasses
Instance Method Summary collapse
-
#extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) ⇒ Context
Extract trace context from the supplied carrier.
-
#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
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/opentelemetry/propagator/xray/text_map_propagator.rb', line 51 def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) header = getter.get(carrier, XRAY_CONTEXT_KEY) return context unless header match = parse_header(header) return context unless match span_context = Trace::SpanContext.new( trace_id: to_trace_id(match['trace_id']), span_id: to_span_id(match['span_id']), trace_flags: to_trace_flags(match['sampling_state']), tracestate: to_trace_state(match['trace_state']), remote: true ) span = OpenTelemetry::Trace.non_recording_span(span_context) context = XRay.context_with_debug(context) if match['sampling_state'] == 'd' Trace.context_with_span(span, parent_context: context) rescue OpenTelemetry::Error context end |
#inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) ⇒ Object
Inject trace context into the supplied carrier.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/opentelemetry/propagator/xray/text_map_propagator.rb', line 80 def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) span_context = Trace.current_span(context).context return unless span_context.valid? sampling_state = if XRay.debug?(context) 'd' elsif span_context.trace_flags.sampled? '1' else '0' end ot_trace_id = span_context.hex_trace_id xray_trace_id = "1-#{ot_trace_id[0..7]}-#{ot_trace_id[8..ot_trace_id.length]}" parent_id = span_context.hex_span_id xray_value = "Root=#{xray_trace_id};Parent=#{parent_id};Sampled=#{sampling_state}" setter.set(carrier, XRAY_CONTEXT_KEY, xray_value) nil end |