Class: OpenTelemetry::Propagator::XRay::LambdaTextMapPropagator
- Inherits:
-
TextMapPropagator
- Object
- TextMapPropagator
- OpenTelemetry::Propagator::XRay::LambdaTextMapPropagator
- Defined in:
- lib/opentelemetry/propagator/xray/lambda_text_map_propagator.rb
Overview
Implementation of AWS X-Ray Trace Header propagation with special handling for Lambda's _X_AMZN_TRACE_ID environment variable
Constant Summary collapse
- AWS_TRACE_HEADER_ENV_KEY =
'_X_AMZN_TRACE_ID'
Instance Method Summary collapse
-
#extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) ⇒ Context
Extract trace context from the supplied carrier or from Lambda environment variable If extraction fails, the original context will be returned.
Methods inherited from TextMapPropagator
Instance Method Details
#extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) ⇒ Context
Extract trace context from the supplied carrier or from Lambda environment variable If extraction fails, the original context will be returned
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/opentelemetry/propagator/xray/lambda_text_map_propagator.rb', line 35 def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) # Check if the original input context already has a valid span span_context = Trace.current_span(context).context # If original context is valid, just return it - do not extract from carrier return context if span_context.valid? # First try to extract from the carrier using the standard X-Ray propagator xray_context = super # Check if we successfully extracted a context from the carrier span_context = Trace.current_span(xray_context).context return xray_context if span_context.valid? # If not, check for the Lambda environment variable trace_header = ENV.fetch(AWS_TRACE_HEADER_ENV_KEY, nil) return xray_context unless trace_header # Create a carrier with the trace header and extract from it env_carrier = { XRAY_CONTEXT_KEY => trace_header } super(env_carrier, context: xray_context, getter: getter) rescue OpenTelemetry::Error context end |