Skip to main content

AWS Lambda OpenTelemetry tools for Python

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws_lambda_opentelemetry-0.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aws_lambda_opentelemetry-0.1.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file aws_lambda_opentelemetry-0.1.0.tar.gz.

File metadata

  • Download URL: aws_lambda_opentelemetry-0.1.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for aws_lambda_opentelemetry-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9764e6f07802ac0d51aafa8c71522a69fb22ff3fbe2a90ff200dfe99235892df
MD5 ba7b2e62677159aa117db8d9c409cc74
BLAKE2b-256 837a961c26732fb3f29b6ad7e85c4cf10a9ac25acf53e707df1d06670a60686d

See more details on using hashes here.

File details

Details for the file aws_lambda_opentelemetry-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: aws_lambda_opentelemetry-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for aws_lambda_opentelemetry-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 39ff9faa4f208e6d6c539706de69c458f71475801ddda0ccf2c874bf01fd5c80
MD5 5545adf5a3060c395144175bb4131d2b
BLAKE2b-256 c9be43aa92278f35384777787104edfbd51b7c0815f63f3c6f3f34fe73ce16a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page