Skip to main content

Middleware that makes a request GUID available from anywhere and injects it into your logs.

Project description

https://img.shields.io/pypi/v/django-guid.svg https://img.shields.io/pypi/pyversions/django-guid.svg https://img.shields.io/pypi/djversions/django-guid.svg

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.

Installation

Python package:

pip install django-guid

In your project’s settings.py add these settings:

Add a filter to your LOGGING:

LOGGING = {
    'filters': {
        'correlation_id': {
            '()': 'django_guid_injection.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 and django-crequest

2019-12-20

  • Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-guid-0.1.1.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

django_guid-0.1.1-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page