asgi-correlation-id
Middleware correlating project logs to individual requests
What it is and what it does
This package provides ASGI middleware that attaches a unique correlation ID to each incoming HTTP request, either by reading an existing ID from a header (like X-Request-ID or X-Correlation-ID) or by generating a new one. The middleware stores this ID in a way that makes it accessible to your application's logging system, allowing you to tag all log messages from a single request with the same ID.
The primary use case is request tracing: when logs from different parts of your application are all tagged with the same correlation ID, you can easily retrieve and correlate all logs belonging to a single user request. The package integrates with Python's standard logging module via a filter and supports customization of header names, ID generation, validation, and transformation.
Use it for:
- Debugging production issues by filtering logs to show only those from a specific user request.
- Tracing requests across multiple services when correlation IDs are propagated through HTTP headers.
- Integrating with error tracking services to group errors by the request that triggered them.
- Auditing and compliance logging where you need to track all actions during a specific request.
- Correlating logs from multiple handlers or middleware layers processing the same incoming request.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
ASGI middleware that reads or generates correlation IDs for incoming requests and makes them available to logging, enabling you to trace all logs from a single HTTP request.
Yes. The package is production-stable (Development Status 5), has no known vulnerabilities, minimal dependencies, and solves a common observability problem in ASGI applications. Install it if you need to correlate logs across your application; the setup overhead is low and the debugging value is high.
Install
asgi-correlation-id on PyPI
pip
pip install asgi-correlation-iduv
uv add asgi-correlation-idpoetry
poetry add asgi-correlation-idInstalling asgi-correlation-id
Before you install
Low friction: pure Python wheel with a single runtime dependency on starlette. Actively maintained with recent releases; last commit 2026-06-09 and 638 repository stars indicate steady adoption and support.
License in practice
MIT license (permissive) places no restrictions on use, modification, or distribution in commercial or private projects.
Quickstart
pip install asgi-correlation-id
from asgi_correlation_id import CorrelationIdMiddleware
from starlette.applications import Starlette
app = Starlette()
app.add_middleware(CorrelationIdMiddleware)
# Configure logging to include %(correlation_id)s in format string
Requires Python 3.10 or later; logging must be configured separately to include correlation_id in the format string.
Verify before relying
- Performance overhead of correlation ID generation and storage per request under high throughput.
- Compatibility with async context propagation in complex middleware stacks beyond Starlette.
- Whether correlation IDs propagate correctly through background tasks or worker processes.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — starlette |
| Maintenance | actively maintained — 66 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 6,892,349/month — #1,818 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: asgi_correlation_id-5.0.1-py3-none-any.whl
Keywords: asgi, fastapi, starlette, async, correlation, correlation-id, request-id, x-request-id, tracing, logging, middleware, sentry
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
django-guidAttaches a unique correlation ID to all logs…
permissive · top 15,000 on PyPI
starlette-contextMiddleware for Starlette that stores and…
permissive · top 5,000 on PyPI
flask-request-id-headerFlask middleware that automatically adds or…
unclear · top 15,000 on PyPI
django-cidAssigns unique correlation IDs to incoming HTTP…
permissive · top 15,000 on PyPI
timing-asgiTiming-asgi is an ASGI middleware that…
unclear · top 15,000 on PyPI
django-request-idAttaches a unique request ID to each Django…
permissive · top 15,000 on PyPI
django-log-request-idAttaches a unique request ID to every log…
permissive · top 15,000 on PyPI
opentelemetry-instrumentation-asgiProvides ASGI middleware for OpenTelemetry that…
permissive · top 1,000 on PyPI
asgi-csrfASGI middleware that protects web applications…
permissive · top 15,000 on PyPI
brotli-asgiBrotliMiddleware adds Brotli compression to…
permissive · top 15,000 on PyPI