django-log-request-id is a Django middleware and log filter that automatically attaches a unique request ID to every log message generated as part of a web request. This greatly simplifies tracing and debugging in complex or distributed systems by allowing all related log entries for a single request to be easily correlated. The current version is 2.1.2, and the library maintains an active release cadence with frequent updates.
pip install django-log-request-idVerified import paths — ran on the pinned version, not inferred.
To integrate django-log-request-id, first add the `RequestIDMiddleware` to the top of your `MIDDLEWARE` setting. Then, define `RequestIDFilter` in your `LOGGING` configuration, and ensure your logging handlers use this filter and your formatters include `%(request_id)s` to display the unique ID.
Review your code for any reliance on `requests.Session` passthrough. If necessary, refactor to handle session management explicitly within your application logic.
Ensure `'log_request_id.middleware.RequestIDMiddleware'` is the first or one of the first entries in your `MIDDLEWARE` setting.
Upgrade to version 2.1.0 or later. If you do not wish to log user attributes, set `LOG_USER_ATTRIBUTE = None` in your Django settings. If you log user attributes, be aware of potential session side effects in older versions.
Ensure your Django project uses a supported Django version (e.g., Django 3.0+ for 1.7.0). Always check the library's `requires_python` and Django compatibility matrix before upgrading.
Set `LOG_REQUEST_ID_HEADER` in your Django settings to the correct `META` key for your custom request ID header. For example, if your header is `X-My-Request-ID`, set `LOG_REQUEST_ID_HEADER = 'HTTP_X_MY_REQUEST_ID'`.
Ensure that `log_request_id.filters.RequestIDFilter` is correctly defined in your `LOGGING['filters']` setting and then explicitly applied to the relevant handlers in your `LOGGING['handlers']` configuration. For example: `LOGGING = {..., 'filters': {'request_id': {'()': 'log_request_id.filters.RequestIDFilter'}}, 'handlers': {'console': {'filters': ['request_id'], ...}}, ...}`Verify that `log_request_id.middleware.RequestIDMiddleware` is placed at the very top of your `MIDDLEWARE` list in `settings.py` to ensure it captures every request. Additionally, confirm that the `log_request_id.filters.RequestIDFilter` is correctly configured and applied to your logging handlers and that your formatter includes `%(request_id)s`.
Install the package using pip: `pip install django-log-request-id`. After installation, double-check that the middleware path (`'log_request_id.middleware.RequestIDMiddleware'`) and filter path (`'log_request_id.filters.RequestIDFilter'`) are correctly specified in your `settings.py`.
No dependency data recorded yet.