This release is a pre-release and may not be stable for production use.
sentry-lwa
Drop-in AwsLambdaIntegration for ASGI apps on AWS Lambda behind the
Lambda Web Adapter.
Why this exists
The Lambda Web Adapter ships its own Rust-based runtime interface client
(the lambda_http
crate) and uses it to poll the Lambda Runtime API directly. Your ASGI
app runs as a plain HTTP server behind it — awslambdaric is never
imported.
Sentry's native AwsLambdaIntegration monkeypatches awslambdaric's
bootstrap module. Under the Web Adapter, setup_once() finds nothing to
patch and returns early. The flush hook, timeout warning, and Lambda
context enrichment are all inert. Lambda freezes the execution
environment as soon as the response is sent, and any Sentry spans still
queued at that point are silently lost.
This is a known issue. Others have reported identical data loss with DataDog and OpenTelemetry:
- #466 — DataDog traces lost because Lambda freezes before post-response middleware completes
- #404 — maintainer confirms background tasks are killed on freeze, suggests the internal extension pattern as a workaround
- #590 —
the official
fastapi-background-tasksextension example does not work (still open)
What this does
sentry-lwa provides a single AwsLambdaIntegration that replaces the
native one. It:
- Registers an internal Lambda extension
that delays the freeze by holding off its
Nextcall until the Sentry transport queue is flushed. - Wraps
Starlette.__call__to bridge the ASGI request lifecycle to the extension thread. - Enriches every Sentry event with Lambda metadata (function name, ARN,
CloudWatch log link, execution duration) from the
x-amzn-lambda-contextheader. - Optionally fires a
ServerlessTimeoutWarning~1.5 s before the invocation deadline.
Works with any ASGI framework that runs on Starlette — FastAPI, MCP
servers via fastmcp, plain Starlette apps.
Installation
pip install sentry-lwa
Usage
Swap one import. Use whatever native Sentry integration your framework
needs — AwsLambdaIntegration handles everything that breaks under
the Web Adapter.
FastAPI
import sentry_sdk
from sentry_sdk.integrations.fastapi import FastApiIntegration
from sentry_lwa import AwsLambdaIntegration
sentry_sdk.init(
integrations=[
FastApiIntegration(),
AwsLambdaIntegration(timeout_warning=True),
],
)
MCP server (fastmcp)
import sentry_sdk
from sentry_sdk.integrations.mcp import MCPIntegration
from sentry_lwa import AwsLambdaIntegration
sentry_sdk.init(
integrations=[
MCPIntegration(),
AwsLambdaIntegration(timeout_warning=True),
],
)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
timeout_warning |
bool |
False |
Fire a ServerlessTimeoutWarning ~1.5 s before the invocation deadline |
Behaviour
- Inside Lambda — the extension registers with the Extensions API,
waits for each request to finish, flushes the Sentry queue (up to 2 s,
capped by the invocation deadline), then calls
Nextto release the freeze. Every Sentry event is enriched with Lambda metadata. - Outside Lambda (
AWS_LAMBDA_RUNTIME_APInot set) — the extension does not register and every request passes through unchanged. No overhead.
How it works
AwsLambdaIntegrationsubclasses the nativeAwsLambdaIntegrationbut does not callsuper().setup_once()(it would no-op under the Web Adapter).setup_once()wrapsStarlette.__call__with a layer that parses thex-amzn-lambda-contextheader, adds a per-request event processor to the Sentry scope, optionally starts a timeout warning thread, signals the extension thread when the request starts and finishes.setup_once_with_options()registers aSentryFlushExtension— an internal Lambda extension running in a background thread.- The extension thread (blocked on the INVOKE event from the Extensions
API) wakes when the ASGI thread signals done, calls
sentry_sdk.flush(), then callsNext— allowing Lambda to freeze.
Metadata
Release files for sentry-lwa 1.1.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sentry_lwa-1.1.0a1.tar.gz | 10.6 kB | Without provenance | Details for sentry_lwa-1.1.0a1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sentry_lwa-1.1.0a1-py3-none-any.whl | Python 3 | none | any | Details for sentry_lwa-1.1.0a1-py3-none-any.whl |
Total release size: 22.7 kB
Release files / sentry_lwa-1.1.0a1.tar.gz
| Download URL | sentry_lwa-1.1.0a1.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e9c3f0299dda232e676497426549ed7a4013bccd378b23c16fa279ab64e22db1
|
|
BLAKE2b-256 checksum How to use checksums |
382a23f3f402e9bb5ec76deb107668e4940f14c2f26e34a1247ac8d0c6dec3f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / sentry_lwa-1.1.0a1-py3-none-any.whl
| Download URL | sentry_lwa-1.1.0a1-py3-none-any.whl |
|---|---|
| Size | 12.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0f7fe79060904a8ac04edbf9b8dd49589d9200bf1b0ed481f73ac7aa88eb3b43
|
|
BLAKE2b-256 checksum How to use checksums |
f67af506170708f862c7f96f9eb2900939ccce5e6dc2b55691424ab76820f863
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for sentry-lwa 1.1.0a1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.