Skip to main content

1. Add the OpenTelemetry Lambda Layer

Find the latest layer-python ARN for your AWS region from the opentelemetry-lambda releases page. Add the layer ARN to your function.

2. Add the Collector Lambda Extension

Find the latest layer-collector ARN for your AWS region from the opentelemetry-lambda releases page. Add the layer ARN to your function and then add the following collector.yaml file to the root of your Lambda deployment folder. Replace YOUR_TRACE0_ENV_API_KEY with the API key from your Trace0 environment.

3. Set Environment Variables

Add the following environment variables to your Lambda function.

4. Add Logger

To enable full log-trace correlation, configure Python’s logging module to write structured JSON to stdout, with a filter that injects the active trace ID and span ID into every log record.
Lambda’s Telemetry API automatically captures stdout/stderr and forwards it to the collector, which then exports it to Trace0.

5. Set HTTP request spans

For lambdas triggered via API Gateway, the HTTP request and response attributes are not set automatically on the lambda invocation span by the OTel Lambda auto-instrumentation. Therefore, they need to be set manually in your lambda code handler.

6. Deploy service

Deploy your service and watch traces, metrics, and logs appear in the Trace0 dashboard within seconds.

Example service

See our Python Lambda example app for a working service you can deploy to your AWS account.