# Django GUID

Now with ASGI support!

Django GUID attaches a unique correlation ID/request ID to all your log outputs for every request. In other words, all logs connected to a request now has a unique ID attached to it, making debugging simple.

Which version of Django GUID you should use depends on your Django version and whether you run `ASGI` or `WSGI` servers. To determine which Django-GUID version you should use, please see the table below.

Django version | Django-GUID version
--- | ---
3.1.1 or above | 3.x.x - ASGI and WSGI
3.0.0 - 3.1.0 | 2.x.x - Only WSGI
2.2.x | 2.x.x - Only WSGI

Django GUID >= 3.0.0 uses `ContextVar` to store and access the GUID. Previous versions stored the GUID to an object, making it accessible by using the ID of the current thread.

Resources:

- Free software: BSD License

- Documentation: https://django-guid.readthedocs.io

- Homepage: https://github.com/snok/django-guid

Examples

Log output with a GUID:

    INFO ... [773fa6885e03493498077a273d1b7f2d] project.views This is a DRF view log, and should have a GUID.
    WARNING ... [773fa6885e03493498077a273d1b7f2d] project.services.file Some warning in a function
    INFO ... [0d1c3919e46e4cd2b2f4ac9a187a8ea1] project.views This is a DRF view log, and should have a GUID.
    INFO ... [99d44111e9174c5a9494275aa7f28858] project.views This is a DRF view log, and should have a GUID.
    WARNING ... [0d1c3919e46e4cd2b2f4ac9a187a8ea1] project.services.file Some warning in a function
    WARNING ... [99d44111e9174c5a9494275aa7f28858] project.services.file Some warning in a function

Log output without a GUID:

    INFO ... project.views This is a DRF view log, and should have a GUID.
    WARNING ... project.services.file Some warning in a function
    INFO ... project.views This is a DRF view log, and should have a GUID.
    INFO ... project.views This is a DRF view log, and should have a GUID.
    WARNING ... project.services.file Some warning in a function
    WARNING ... project.services.file Some warning in a function

# Contents

- Installation
- Configuration
  - 1. Installed Apps
  - 2. Middleware
  - 3. Logging Configuration
  - 4. Django GUID Logger (Optional)
  - 5. Django Management commands (Optional)
- Settings
  - GUID_HEADER_NAME
  - VALIDATE_GUID
  - RETURN_HEADER
  - EXPOSE_HEADER
  - INTEGRATIONS
  - IGNORE_URLS
  - UUID_LENGTH
  - UUID_FORMAT
- API
  - Getting started
  - get_guid()
  - set_guid()
  - clear_guid()
  - Example usage
- Integrations
  - Available integrations
    - Sentry
    - Celery
  - Writing your own integration
    - Method descriptions
- Extended example
  - Experiment
- Troubleshooting
  - Turn on Django debug logging
  - Run Django with warnings enabled
  - Use the demo project as a reference
  - Read the official logging docs
  - Ask for help
- Upgrading Django-GUID 2.x.x to 3.x.x
  - 1. Change Middleware
  - 2. Change API functions (if you used them)
- Publish django-guid
  - Publishing to test-PyPi
  - Publishing to PyPi
  - Read the docs
- Changelog
  - 3.2.1 - 13.12.2021
  - 3.2.0 - 04.12.2020
  - 3.1.0 - 18.11.2020
  - 3.0.1 - 12.11.2020
  - 3.0.0 - 28.10.2020 - Full Django3.1+(ASGI/async) support!
  - 2.2.0 - 04.11.2020
  - 2.1.0 - 03.11.2020
  - 2.0.0 - 02.03.2020
  - 1.1.1 - 12.02.2020
  - 1.1.0 - 10.02.2020
  - 1.0.1 - 08.02.2020
  - 1.0.0 - 14.01.2020
  - 0.3.1 - 13.01.2020
  - 0.3.0 - 10.01.2020
  - 0.2.3 - 09.01.2020
  - 0.2.2 - 21.12.2019
  - 0.2.1 - 21.12.2019
  - 0.2.0 - 21.12.2019
  - 20.10.2019