django-log-request-id
Django middleware and log filter to attach a unique ID to every log message generated as part of a request
Decision gist · record as of 2026-08-14
Yes. The package is actively maintained, has no known vulnerabilities, low install friction (one Django dependency), and solves a genuine debugging problem in Django applications. The permissive BSD-3-Clause license poses no barrier. The only caveat is that it relies on ContextVar, which the documentation acknowledges is unconventional for Django but is the only viable approach—verify compatibility with your specific Django version and async usage patterns if applicable.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Django and Python >= 3.10; request ID is stored in a ContextVar, which the documentation notes is not standard Django practice but is the only viable approach for this use case.
- Low friction: pure Python wheel with only django as a runtime dependency.
- Actively maintained with a recent release (155 days ago) and no known vulnerabilities.
License · maintenance · safety
BSD-3-Clause (permissive) — BSD-3-Clause permissive license allows use in most commercial and open-source projects with minimal restrictions—retain copyright notice and disclaimer.
last release 2026-03-12 (155 days) · last repo commit 2026-03-12 · 384 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 760,120 downloads/mo, #5,130 on PyPI
Alternatives
Verify before relying
pip install django-log-request-id
# In settings.py:
MIDDLEWARE = [
'log_request_id.middleware.RequestIDMiddleware',
# ...
]
# In logging config:
LOGGING = {
'filters': {'request_id': {'()': 'log_request_id.filters.RequestIDFilter'}},
'formatters': {'standard': {'format': '[%(request_id)s] %(message)s'}},
'handlers': {'console': {'filters': ['request_id'], 'formatter': 'standard', 'class': 'logging.StreamHandler'}},
}
# Then log normally:
import logging
logger = logging.getLogger(__name__)
logger.debug("Message with request ID attached")- Whether ContextVar-based storage has measurable performance impact in high-concurrency scenarios.
- Compatibility with async Django views and async middleware.
- Whether the package works with Django versions older than those in current support.
What it is and what it does
django-log-request-id is a Django middleware and logging filter that generates or extracts a unique identifier for each HTTP request and injects it into every log message produced during that request's lifecycle. The ID is stored in a ContextVar and automatically included in log output, allowing developers to grep or search logs to isolate all messages from a single request—essential for debugging high-traffic applications where logs from many concurrent requests are interleaved.
The package supports several configuration options: it can use a request ID from an incoming HTTP header (such as X-Request-Id from load balancers or proxies like Heroku), fall back to generating one if the header is missing, add the ID to the HttpRequest object for use in views, and optionally include it in response headers. It can also log all incoming requests with metadata like user ID. Setup requires adding the middleware to Django's MIDDLEWARE list and configuring a logging filter and formatter to include the request_id variable in log output.
Use it for
- Debugging multi-step request flows in high-traffic applications by searching logs for a single request ID across multiple modules and layers.
- Correlating logs from load balancers or proxies that generate their own request IDs with application-level logs.
- Building request tracing without a full distributed tracing system by embedding request IDs in application logs.
- Auditing user actions by logging all operations tied to a specific request ID.
- Monitoring and alerting on specific request patterns by filtering logs by request ID in log aggregation tools.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
The package is actively maintained, has no known vulnerabilities, low install friction (one Django dependency), and solves a genuine debugging problem in Django applications. The permissive BSD-3-Clause license poses no barrier. The only caveat is that it relies on ContextVar, which the documentation acknowledges is unconventional for Django but is the only viable approach—verify compatibility with your specific Django version and async usage patterns if applicable.
Install
django-log-request-id on PyPI
Before you install
Low friction: pure Python wheel with only django as a runtime dependency. Actively maintained with a recent release (155 days ago) and no known vulnerabilities.
Requires Django and Python >= 3.10; request ID is stored in a ContextVar, which the documentation notes is not standard Django practice but is the only viable approach for this use case.
License in practice
BSD-3-Clause permissive license allows use in most commercial and open-source projects with minimal restrictions—retain copyright notice and disclaimer.
Quickstart
pip install django-log-request-id
# In settings.py:
MIDDLEWARE = [
'log_request_id.middleware.RequestIDMiddleware',
# ...
]
# In logging config:
LOGGING = {
'filters': {'request_id': {'()': 'log_request_id.filters.RequestIDFilter'}},
'formatters': {'standard': {'format': '[%(request_id)s] %(message)s'}},
'handlers': {'console': {'filters': ['request_id'], 'formatter': 'standard', 'class': 'logging.StreamHandler'}},
}
# Then log normally:
import logging
logger = logging.getLogger(__name__)
logger.debug("Message with request ID attached")
Verify before relying
- Whether ContextVar-based storage has measurable performance impact in high-concurrency scenarios.
- Compatibility with async Django views and async middleware.
- Whether the package works with Django versions older than those in current support.
Package facts
| License | BSD-3-Clause permissive |
| Python support | Supports the current Python release >=3.10 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 1 packagedjango |
| Maintenance | Actively maintained 155 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 760,120 / month, #5,130 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
Evidence: django_log_request_id-2.1.2-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “correlate logs across modules”
- django-log-request-idAttaches a unique request ID to every log message generated during a…
- Flask-Log-Request-IDExtracts request IDs from incoming HTTP requests (from load balancers…
- opencensus-ext-loggingEnriches Python log records with OpenCensus trace context (trace ID,…
Give your agent the search over MCP, or paste the wish link into any chat.
More Dynamic Content packages
MarkupSafe provides a text object that escapes special characters so untrusted strings can be safely embedded in HTML and XML without injection attacks.
Jinja2 is a templating engine that renders dynamic content by combining templates with Python-like syntax and data, supporting template inheritance, macros, autoescaping, and sandboxed execution.
Soupsieve is a CSS selector library designed to work with Beautiful Soup 4 to select, match, and filter HTML and XML elements using modern CSS selectors from CSS level 1 through CSS level 4 specifications.
Install it if you use Beautiful Soup for HTML or XML parsing and want modern CSS selector support.
Werkzeug is a WSGI utility library providing request/response objects, URL routing, an interactive debugger, HTTP utilities, and a development server for building web applications.
Flask is a lightweight WSGI web application framework for building web applications in Python, from simple single-page sites to complex multi-route applications.
Mako compiles Python-embedded templates into Python modules for fast rendering, supporting layout inheritance, custom functions, and direct Python expressions within template syntax.
See also django-request-id · Flask-Log-Request-ID · asgi-correlation-id · django-guid · django-request-logging · django-structlog · flask-request-id-header · django-cid · django-xff · django-datadog-logger