Skip to main content
License Latest PyPI version Supports Wheel format

Augments each request with unique request_id attribute and provides request id logging helpers.

Developed and used at en.ig.ma software shop.

Quickstart

  1. Include django-request-id in your requirements.txt file.

  2. Add request_id to INSTALLED_APPS (necessary only if you are going to use the {% request_id %} template tag).

  3. Add request_id.middleware.RequestIdMiddleware at the top of the MIDDLEWARE Django setting.

  4. The app integrates with the standard Python/Django logging by defining a filter that puts a request_id variable in scope of every log message.

    First add a filter definition to the Django LOGGING settings:

    "filters": {
        "request_id": {
            "()": "request_id.logging.RequestIdFilter"
        }
    }

    Then enable the filter for related handlers:

    "handlers": {
        "console": {
            ...
            "filters": ["request_id"],
        }
     }

    And finally modify formatter output format to include the %(request_id) placeholder:

    "formatters": {
        "console": {
            "format": "%(asctime)s - %(levelname)-5s [%(name)s] request_id=%(request_id)s %(message)s"
        }
    }

    A full Django logging config example may look like this:

    LOGGING= {
        "version": 1,
        "disable_existing_loggers": False,
        "filters": {
            "request_id": {
                "()": "request_id.logging.RequestIdFilter"
            }
        },
        "formatters": {
            "console": {
                "format": "%(asctime)s - %(levelname)-5s [%(name)s] request_id=%(request_id)s %(message)s",
                "datefmt": "%H:%M:%S"
            }
        },
        "handlers": {
            "console": {
                "level": "DEBUG",
                "filters": ["request_id"],
                "class": "logging.StreamHandler",
                "formatter": "console"
            }
        },
        "loggers": {
            "": {
                "level": "DEBUG",
                "handlers": ["console"]
            }
        }
    }
  5. Make sure that your web server adds a X-Request-ID header to each request (and logs it in the server log for further matching of the server and app log entries).

    If you can’t generate the X-Request-Id header at the web server level then simply set REQUEST_ID_HEADER = None in your project settings and the app will generate a unique id value automatically instead of retrieving it from the wsgi environment.

    For more info on server configs see server-config.

Dependencies

None.

Documentation and demo

The full documentation is at http://django-request-id.rtfd.org.

There’s also an instant demo example that can be run from the cloned repository:

python demo.py

See the integration in action on Heroku:

Deply

License

django-request-id is released under the MIT license.

Other Resources

Commercial Support

This app and many other help us build better software and focus on delivering quality projects faster. We would love to help you with your next project so get in touch by dropping an email at en@ig.ma.

History

1.0.0 (2016-10-23)

  • Django 1.10 compatibility

0.1.0 (2014-01-30)

  • First release

Release files for django-request-id 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-request-id 1.0.0
File Size Uploaded
django-request-id-1.0.0.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-request-id 1.0.0
File Interpreter ABI Platform
django_request_id-1.0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 18.4 kB

Release files / django-request-id-1.0.0.tar.gz

Download URL django-request-id-1.0.0.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0eb7ef17e21ff5efe5014e5b3cc6d22fc3396d4ea9d5b353bba2c43107998368
BLAKE2b-256 checksum
How to use checksums
9760386d2d55d606518482e2780034d03f2c6b444139a81403a74a723365965c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_request_id-1.0.0-py2.py3-none-any.whl

Download URL django_request_id-1.0.0-py2.py3-none-any.whl
Size 11.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
f7f296a7c6de44193af9461c72cbdb6a12887fffe00a7dcfa0f43a4ec67e4643
BLAKE2b-256 checksum
How to use checksums
c2ce0455f018d3457a36a7bdd971b735fd7d0fd725ef203d0388ff6175766161
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page