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:
opentelemetry.sdk.trace.id_generator.IdGenerator
Generates tracing IDs compatible with the AWS X-Ray tracing service. In the X-Ray system, the first 32 bits of the
TraceId
are 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 randomTraceId
risks 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
- static generate_trace_id()[source]¶
Get a new trace ID.
Implementations should at least make the 64 least significant bits uniformly random. Samplers like the
TraceIdRatioBased
sampler rely on this randomness to make sampling decisions.See the specification on TraceIdRatioBased.
- Return type
- Returns
A 128-bit int for use as a trace ID