OpenTelemetry Python - AWS SDK Extension
Installation
pip install opentelemetry-sdk-extension-aws
AWS X-Ray IDs Generator
The AWS X-Ray IDs Generator provides a custom IDs Generator to make
traces generated using the OpenTelemetry SDKs TracerProvider compatible
with the AWS X-Ray backend service trace ID format.
Usage
Configure the OTel SDK TracerProvider with the provided custom IDs Generator to make spans compatible with the AWS X-Ray backend tracing service.
Install the OpenTelemetry SDK package.
pip install opentelemetry-sdk
Next, use the provided AwsXRayIdGenerator to initialize the TracerProvider.
import opentelemetry.trace as trace
from opentelemetry.sdk.extension.aws.trace import AwsXRayIdGenerator
from opentelemetry.sdk.trace import TracerProvider
trace.set_tracer_provider(
TracerProvider(id_generator=AwsXRayIdGenerator())
)
API
- class opentelemetry.sdk.extension.aws.trace.aws_xray_id_generator.AwsXRayIdGenerator[source]
Bases:
IdGeneratorGenerates tracing IDs compatible with the AWS X-Ray tracing service. In the X-Ray system, the first 32 bits of the
TraceIdare the Unix epoch time in seconds. Since spans (AWS calls them segments) with an embedded timestamp more than 30 days ago are rejected, a purely randomTraceIdrisks being rejected by the service.See: https://docs.aws.amazon.com/xray/latest/devguide/xray-api-sendingdata.html#xray-api-traceids
- random_id_generator = <opentelemetry.sdk.trace.id_generator.RandomIdGenerator object>
- generate_span_id()[source]
Get a new span ID.
- Return type:
- Returns:
A 64-bit int for use as a span ID
- generate_trace_id()[source]
Get a new trace ID.
Implementations should at least make the 56 least significant bits uniformly random. Samplers like the TraceIdRatioBased sampler rely on this randomness to make sampling decisions.
If the implementation does randomly generate the 56 least significant bits, it should also implement is_trace_id_random to return True.
See the specification on TraceIdRatioBased.
- Return type:
- Returns:
A 128-bit int for use as a trace ID
- is_trace_id_random()[source]
Indicates whether generated trace IDs are random.
When True, the trace-id field will have the random-trace-id flag set in the W3C traceparent header. Per the W3C Trace Context specification, this indicates that at least the 7 rightmost bytes (56 bits) of the trace ID were generated randomly with uniform distribution.
See the W3C Trace Context specification.
- Return type:
- Returns:
True if this generator produces random IDs, False otherwise.