AWS SDK extension for OpenTelemetry providing X-Ray ID generation and AWS resource detection
npx @tessl/cli install tessl/pypi-opentelemetry-sdk-extension-aws@2.1.0A comprehensive OpenTelemetry SDK extension providing AWS X-Ray tracing compatibility and automatic resource attribute detection for AWS services. This package bridges OpenTelemetry distributed tracing with AWS X-Ray by generating compatible trace IDs and automatically populating resource attributes when running on AWS infrastructure.
pip install opentelemetry-sdk-extension-awsFor X-Ray ID generation:
from opentelemetry.sdk.extension.aws.trace import AwsXRayIdGeneratorFor AWS resource detection:
from opentelemetry.sdk.extension.aws.resource.ec2 import AwsEc2ResourceDetector
from opentelemetry.sdk.extension.aws.resource.ecs import AwsEcsResourceDetector
from opentelemetry.sdk.extension.aws.resource.eks import AwsEksResourceDetector
from opentelemetry.sdk.extension.aws.resource.beanstalk import AwsBeanstalkResourceDetector
from opentelemetry.sdk.extension.aws.resource._lambda import AwsLambdaResourceDetectorimport opentelemetry.trace as trace
from opentelemetry.sdk.extension.aws.trace import AwsXRayIdGenerator
from opentelemetry.sdk.trace import TracerProvider
# Configure TracerProvider with X-Ray compatible ID generator
trace.set_tracer_provider(
TracerProvider(id_generator=AwsXRayIdGenerator())
)
# Use tracing as normal - IDs will be X-Ray compatible
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("operation"):
# Your application code here
passimport opentelemetry.trace as trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.extension.aws.resource.ec2 import AwsEc2ResourceDetector
from opentelemetry.sdk.resources import get_aggregated_resources
# Configure TracerProvider with automatic AWS resource detection
trace.set_tracer_provider(
TracerProvider(
resource=get_aggregated_resources([
AwsEc2ResourceDetector(),
])
)
)The extension consists of two main components:
Both components integrate seamlessly with OpenTelemetry's standard TracerProvider configuration, enabling applications to benefit from X-Ray compatibility and automatic resource detection without code changes beyond initial setup.
Generates OpenTelemetry trace and span IDs that are compatible with AWS X-Ray's format requirements. X-Ray requires trace IDs to embed Unix timestamps in the first 32 bits to ensure spans are not rejected by the service.
class AwsXRayIdGenerator:
def generate_span_id(self) -> int: ...
def generate_trace_id(self) -> int: ...Automatically detects and populates resource attributes when running on AWS services. Each detector focuses on a specific AWS service and extracts relevant metadata to enhance observability.
class AwsEc2ResourceDetector:
def detect(self) -> Resource: ...
class AwsEcsResourceDetector:
def detect(self) -> Resource: ...
class AwsEksResourceDetector:
def detect(self) -> Resource: ...
class AwsBeanstalkResourceDetector:
def detect(self) -> Resource: ...
class AwsLambdaResourceDetector:
def detect(self) -> Resource: ...from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace.id_generator import IdGenerator
# All resource detectors extend this base class
class ResourceDetector:
raise_on_error: bool
def detect(self) -> Resource: ...
# ID generator base class
class IdGenerator:
def generate_span_id(self) -> int: ...
def generate_trace_id(self) -> int: ...