AWS OpenTelemetry Python Distro

0.17.0 · active · verified Sat Apr 11

The AWS OpenTelemetry Python Distro (`aws-opentelemetry-distro`) is a distribution of the OpenTelemetry Python SDK, pre-configured for AWS environments. It includes AWS-specific resource detectors, X-Ray compatible trace ID generation, and automatic instrumentation for AWS SDK (boto3/botocore) and popular frameworks. It aims to simplify the adoption of OpenTelemetry for applications running on AWS, providing a streamlined path to send traces, metrics, and logs to services like AWS X-Ray and Amazon CloudWatch. The current version is `0.17.0`, with releases typically aligning with upstream OpenTelemetry component updates and AWS-specific feature additions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the most basic usage: initializing the distro and creating a simple trace span. For traces to be actually collected and visible, you need to configure an OTLP exporter, typically via environment variables like `OTEL_EXPORTER_OTLP_ENDPOINT` pointing to an OpenTelemetry Collector or AWS X-Ray daemon.

import os
from aws_opentelemetry_distro import start_tracing
from opentelemetry import trace

# 1. Initialize the AWS OpenTelemetry Distro.
# This sets up the global trace provider, resource detectors, and default exporters
# based primarily on environment variables (e.g., OTEL_EXPORTER_OTLP_ENDPOINT).
# In AWS Lambda or ECS/EC2 with the ADOT Collector, these environment variables are often pre-configured.
start_tracing()

# 2. Get a tracer and create a span.
tracer = trace.get_tracer("my-application-tracer")

with tracer.start_as_current_span("my-aws-operation") as span:
    span.set_attribute("service.name", "my-app")
    span.set_attribute("aws.region", os.environ.get("AWS_REGION", "us-east-1"))
    print("Performing some instrumented work with AWS OpenTelemetry Distro...")
    # Simulate some work
    import time
    time.sleep(0.1)

print("Application finished. Spans were sent to the configured OTLP endpoint.")
print("To see output, ensure OTEL_EXPORTER_OTLP_ENDPOINT is set (e.g., to a local ADOT Collector or X-Ray daemon).")

view raw JSON →