Skip to main content

AWS Lambda OpenTelemetry

OpenTelemetry instrumentation for AWS Lambda functions.


Installation

pip install aws-lambda-opentelemetry

Quick Start

from aws_lambda_opentelemetry import Instrumentor

instrumentor = Instrumentor(service="my-service")

@instrumentor.capture_lambda_handler
def handler(event, context):
    result = process(event)
    return {"statusCode": 200, "body": result}

@instrumentor.capture_method
def process(event):
    return event["body"].upper()

Features

  • capture_lambda_handler — Wraps Lambda handlers with automatic span creation, AWS attribute extraction, and force flush
  • capture_method — Wraps regular functions/methods as child spans
  • Automatic attribute extraction — Detects API Gateway, HTTP API, ALB, SQS, SNS, S3, DynamoDB, Kinesis, EventBridge, and CloudWatch Logs events
  • Cold start tracking — Automatically tracks cold start via faas.coldstart
  • SQS trace exporter — Export spans to SQS with optional gzip/deflate compression

Supported Event Sources

Source Detection Attributes
API Gateway (REST) requestContext.apiId HTTP method, route, protocol, user agent, body size
HTTP API (v2) requestContext.http HTTP method, route, protocol, user agent, body size
ALB/ELB requestContext.elb HTTP method, path, user agent, body size
SQS eventSource: aws:sqs Queue name, message count, messaging system
SNS eventSource: aws:sns Trigger type
S3 eventSource: aws:s3 Trigger type
DynamoDB Streams eventSource: aws:dynamodb Trigger type
Kinesis eventSource: aws:kinesis Trigger type
EventBridge source + detail-type Trigger type (timer or pubsub)
CloudWatch Logs awslogs.data Trigger type

Usage with Decorators

Lambda Handler

Both bare decorator and decorator-with-arguments styles are supported:

# Bare decorator
@instrumentor.capture_lambda_handler
def handler(event, context):
    ...

# With arguments
@instrumentor.capture_lambda_handler(name="my-handler")
def handler(event, context):
    ...

Methods and Functions

@instrumentor.capture_method
def my_function(x, y):
    return x + y

@instrumentor.capture_method(name="custom-span-name")
def another_function():
    ...

Child spans created by capture_method are automatically linked to the parent Lambda handler span.

Metadata

Release files for aws-lambda-opentelemetry 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-lambda-opentelemetry 0.1.0
File Size Uploaded
aws_lambda_opentelemetry-0.1.0.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aws-lambda-opentelemetry 0.1.0
File Interpreter ABI Platform
aws_lambda_opentelemetry-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.4 kB

Release files / aws_lambda_opentelemetry-0.1.0.tar.gz

Download URL aws_lambda_opentelemetry-0.1.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9764e6f07802ac0d51aafa8c71522a69fb22ff3fbe2a90ff200dfe99235892df
BLAKE2b-256 checksum
How to use checksums
837a961c26732fb3f29b6ad7e85c4cf10a9ac25acf53e707df1d06670a60686d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / aws_lambda_opentelemetry-0.1.0-py3-none-any.whl

Download URL aws_lambda_opentelemetry-0.1.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
39ff9faa4f208e6d6c539706de69c458f71475801ddda0ccf2c874bf01fd5c80
BLAKE2b-256 checksum
How to use checksums
c9be43aa92278f35384777787104edfbd51b7c0815f63f3c6f3f34fe73ce16a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page