Registry /
observability / opentelemetry-propagator-aws-xray
Install & Compatibility
Where this runs
tested against v1.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.000s · 19MB
17MB installed
● package 17MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
AWSXRayPropagator
✓ from opentelemetry.propagators.aws_xray import AWSXRayPropagator
✗ from opentelemetry.propagators.aws import AWSXRayPropagator
This quickstart demonstrates how to configure OpenTelemetry to use the AWS X-Ray Propagator and `AwsXRayIdGenerator`. It shows how to initialize the `TracerProvider` for X-Ray compatible trace IDs, set the global `AWSXRayPropagator`, and simulate injecting and extracting X-Ray trace context for distributed tracing.
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
from opentelemetry.sdk.trace.id_generator import AwsXRayIdGenerator
from opentelemetry.propagators.aws.xray import AWSXRayPropagator
from opentelemetry.propagate import set_global_textmap_propagator
from opentelemetry.trace import get_tracer_provider, set_tracer_provider, get_tracer, get_current_span
# 1. Configure TracerProvider with AwsXRayIdGenerator
# This ensures new traces generated by this application use AWS X-Ray compatible IDs.
provider = TracerProvider(id_generator=AwsXRayIdGenerator())
# For demonstration, we'll use a ConsoleSpanExporter.
# In a real application, you'd use an OTLPSpanExporter or similar.
processor = SimpleSpanProcessor(ConsoleSpanExporter())
provider.add_span_processor(processor)
set_tracer_provider(provider)
# 2. Set the global propagator to AWSXRayPropagator
# This enables automatic injection/extraction of X-Ray headers.
set_global_textmap_propagator(AWSXRayPropagator())
# 3. Obtain a tracer and create spans
tracer = get_tracer(__name__)
print("\n--- Creating an initial span and injecting context ---")
with tracer.start_as_current_span("my-xray-root-span") as root_span:
print(f"Root Span ID: {root_span.context.span_id:x}")
print(f"Root Trace ID: {root_span.context.trace_id:x}")
# Simulate injecting trace context into outgoing headers
carrier = {}
AWSXRayPropagator().inject(carrier)
print("Injected headers (simulating HTTP request outgoing):", carrier)
print("\n--- Simulating a new request receiving injected headers ---")
# Simulate receiving injected headers in a new context
# We start a new span, but its context will be derived from the extracted headers.
# Let's assume 'carrier' contains the headers from the previous step
received_carrier = carrier.copy()
# When a new span is started, OpenTelemetry automatically extracts context
# from the global propagator if it's available in the current context (e.g., from a request).
# For this example, we manually extract and then demonstrate a child span.
# Manually extract context for clarity, though it's often done automatically by instrumentations.
extracted_context = AWSXRayPropagator().extract(received_carrier)
with tracer.start_as_current_span("my-xray-child-span", context=extracted_context) as child_span:
print(f"Child Span ID: {child_span.context.span_id:x}")
print(f"Child Trace ID: {child_span.context.trace_id:x}")
print(f"Is child span linked to root? {root_span.context.trace_id == child_span.context.trace_id}")
# Further nested span
with tracer.start_as_current_span("nested-operation"):
print(" Inside nested operation.")
print("\n--- End of quickstart ---")
Upgrade
Version history
1.0.2latest on PyPI · released Aug 5, 2024
Audit
Dependencies
No dependency data recorded yet.