django-request-id is a Python library for Django that augments each HTTP request with a unique ID, primarily for improved logging and tracing across services. It is currently at version 1.0.0 and maintains a stable release cadence, focusing on core functionality and compatibility with recent Django versions.
pip install django-request-idVerified import paths — ran on the pinned version, not inferred.
To quickly integrate `django-request-id`, add `request_id.middleware.RequestIDMiddleware` to your `MIDDLEWARE` setting. Crucially, configure your Django `LOGGING` settings to include `request_id.logging.RequestIDFilter` and apply it to your desired log handlers. Also, ensure your log formatters include `{request_id}` to display the unique ID.
Ensure `LOGGING['filters']['request_id']['()'] = 'request_id.logging.RequestIDFilter'` is set and `'filters': ['request_id']` is applied to your `LOGGING['handlers']` entries. Also, modify your formatter `format` strings to include `{request_id}`.Consult your proxy/load balancer documentation (e.g., Nginx, AWS ELB/ALB) to understand how `X-Request-ID` headers are handled and configure them to either pass through or strip/override as per your requirements.
Add `REQUEST_ID_HEADER = 'Your-Custom-Header'` and `REQUEST_ID_RESPONSE_HEADER = 'Your-Custom-Header'` to your `settings.py`.