Middleware that makes a request GUID available from anywhere and injects it into your logs.
Project description
GUID injection for Django
Django GUID attaches a GUID to the local thread of a request. The GUID is accessible from anywhere within the application throughout a request, making it possible to inject the GUID into the logs.
Free software: BSD License
Homepage: https://github.com/JonasKs/django-guid
Documentation: Incoming
Installation
Python package:
pip install django-guid
In your project’s settings.py add these settings:
Add the middleware to the middleware (To ensure the GUID to be injected in all logs, put it on top)
MIDDLEWARE = [
'django_guid.middleware.GuidMiddleware',
...
]
Add a filter to your LOGGING:
LOGGING = {
'filters': {
'correlation_id': {
'()': 'django_guid.log_filters.CorrelationId'
}
}
}
and put that filter in your handler:
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'medium',
'filters': ['correlation_id'],
}
}
and lastly make sure we add it to the format:
'medium': {
'format': '%(levelname)s %(asctime)s [%(correlation_id)s] %(name)s %(message)s'
}
Inspired by django-log-request-id with a django-crequest approach.
Changelog
0.2.0 - 2019-12-21
Features
Header name and header GUID validation can be specified through Django settings.
2019-12-20
Initial release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_guid-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e169410f3ae9bed162069520a495b42437de15203ce26cf1af7c7ec116410032 |
|
MD5 | beb73786af354dfba5a4e4c0bc649b98 |
|
BLAKE2b-256 | 00bd34d5989545bf8841226d74547758527b293105fe713a6a29f9e88e70a02c |