django-tracer
Generate a UUID for all requests to Django to be used in logging and error reporting for traceability.
Why?
Why would you want to use this silly little thing? Well in a containerized, orchestrated, microservice world with centralized logging it's often hard to figure out where things have gone wrong.
This little middleware adds a UUID to the normal Django request object which you can use to add to add to things like:
- All of your log messages
- Error reports to Sentry/Rollbar/etc
- Pass along to other internal services
Along with generating and attaching a UUID to each request, the middleware also automatically adds the UUID to the response headers as X-Request-ID so anyone consuming your responses, say as an API, can use that as a reference point for reporting errors back to you.
Installation
First you need to install it via pip:
pip install django-tracer
Then just add tracer to INSTALLED_APPS in your settings.
Then add tracer.middleware.RequestID to the top of your MIDDLEWARE settings.
Usage with standard logging
import logging
from django.http import HttpResponse
logger = logging.getLogger(__name__)
def some_view(request):
""" simple log example """
logger.info("Whee!", extra={'request_id': request.id})
return HttpResponse("example content")
Other ways to use this Request ID
There are several other places you may consider wanting to use the ID to improve traceability:
- Pass it as an argument to any Celery tasks you generate so there is a clear path between the incoming request and the tasks that were generated from it
- Pass it as a header or argument to other internal APIs or services
- Attach it to a bound structlog object so it is always included in your log output
Thanks!
Special thanks to Rolf Håvard Blindheim for graciously turning over the name django-tracer to us to be able to use it for this project.
Need help?
REVSYS can help with your Python, Django, and infrastructure projects. If you have a question about this project, please open a GitHub issue. If you love us and want to keep track of our goings-on, here's where you can find us online:
Metadata
Release files for django-tracer 0.9.3
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 |
|---|---|---|---|---|
| django-tracer-0.9.3.tar.gz | 3.5 kB | Without provenance | Details for django-tracer-0.9.3.tar.gz |
Release files / django-tracer-0.9.3.tar.gz
| Download URL | django-tracer-0.9.3.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1f1b6dc228a45992b0df966cf348208e30254ecf3c188641fbb3671b90698374
|
|
BLAKE2b-256 checksum How to use checksums |
de9b48f604ba67aa0ef4bc118ae573a934682264f3c86d61aef1a682173bdc35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5
|
Security for django-tracer 0.9.3
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.