Class: OpenTelemetry::Propagator::GoogleCloudTraceContext::TextMapPropagator
- Inherits:
-
Object
- Object
- OpenTelemetry::Propagator::GoogleCloudTraceContext::TextMapPropagator
- Defined in:
- lib/opentelemetry/propagator/google_cloud_trace_context/text_map_propagator.rb
Overview
Propagates context using GoogleCloudTraceContext header 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
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/opentelemetry/propagator/google_cloud_trace_context/text_map_propagator.rb', line 100 def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) trace_parent_value = getter.get(carrier, CLOUD_TRACE_CONTEXT_KEY) return context unless trace_parent_value cloud_trace_context = CloudTraceContext.from_string(trace_parent_value) return context unless cloud_trace_context span_context = Trace::SpanContext.new(trace_id: cloud_trace_context.trace_id, span_id: cloud_trace_context.span_id, trace_flags: cloud_trace_context.flags, remote: true) span = Trace.non_recording_span(span_context) 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+.
119 120 121 |
# File 'lib/opentelemetry/propagator/google_cloud_trace_context/text_map_propagator.rb', line 119 def fields FIELDS 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 |
# File 'lib/opentelemetry/propagator/google_cloud_trace_context/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? setter.set(carrier, CLOUD_TRACE_CONTEXT_KEY, CloudTraceContext.from_span_context(span_context).to_s) nil end |