# Inject a GUID (Correlation-ID) into every log message in a Django request - Now with ASGI/async support for Django3.1 and 3.2!

**URL:** <https://forum.djangoproject.com/t/inject-a-guid-correlation-id-into-every-log-message-in-a-django-request-now-with-asgi-async-support-for-django3-1-and-3-2/4989>\
**Category:** Show & Tell\
**Created:** [October 28, 2020, 6:04pm UTC](https://forum.djangoproject.com/t/inject-a-guid-correlation-id-into-every-log-message-in-a-django-request-now-with-asgi-async-support-for-django3-1-and-3-2/4989 "2020-10-28T18:04:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JonasKs](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jonasks/32/557_2.png) [@JonasKs](https://forum.djangoproject.com/u/JonasKs)\
**Post date:** [October 28, 2020, 6:04pm UTC](https://forum.djangoproject.com/t/inject-a-guid-correlation-id-into-every-log-message-in-a-django-request-now-with-asgi-async-support-for-django3-1-and-3-2/4989/1 "2020-10-28T18:04:40Z")

</div>

[GitHub](https://github.com/JonasKs/django-guid) | [Read the docs](https://django-guid.readthedocs.io/en/latest/?badge=latest)

Hello! I’ve already done a show & tell on this package before, but this is a complete rewrite to make it support Django3.1 (and Django3.2) with full ASGI and async support so I hope it’s okay to post again! 🙂 Logs are great, but they are also often flooded. Django GUID allow you to attach a GUID to every log message that are triggered by a request.

Ever had a user of your Django website or API say “Hey, I got an error?” and wished they could give you an ID that you could find all log messages for? `django-guid` allows you to return the GUID as a header, so you can display it to your end users on successful or failed requests. Or maybe had an exception logger and wanted to get all logs for that request? Well, with Django GUID you can do that.

Have a look at the [extended example](https://django-guid.readthedocs.io/en/latest/extended_example.html) and try to do a `CTRL` + `F` for `99d44111e9174c5a9494275aa7f28858` to see all logs connected to one of the incoming requests to my stack.

I’d also like to give a thanks to @andrewgodwin for good talks on async, answering mails and for explaining me concepts [here on the forum](https://forum.djangoproject.com/t/the-trouble-with-middleware/19/16). A huge thanks to [@sondrelg](https://github.com/sondrelg/) as well for doing code reviews and rubber ducking with me. 🙂

---

<div class="post-metadata">

**Author:** ![mrchrisadams](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mrchrisadams/32/1904_2.png) [@mrchrisadams](https://forum.djangoproject.com/u/mrchrisadams)\
**Post date:** [October 29, 2020, 9:35am UTC](https://forum.djangoproject.com/t/inject-a-guid-correlation-id-into-every-log-message-in-a-django-request-now-with-asgi-async-support-for-django3-1-and-3-2/4989/2 "2020-10-29T09:35:37Z")

</div>

This is such a good idea, thanks Jonas!

Presumably with something like this, you’d be able to visualise these more easily using something like [Honeycomb](https://docs.honeycomb.io/getting-data-in/python/beeline/) or [Lightstep](https://docs.lightstep.com/docs/python-auto-instrumentation).

If you have to self host, I’m not so familiar with open source tools that would provide some degree of observability here, although I _think_ Grafana 7 can support this.

If anyone knows it would be great to have them some added, to give an idea of the options available.

---

<div class="post-metadata">

**Author:** ![JonasKs](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jonasks/32/557_2.png) [@JonasKs](https://forum.djangoproject.com/u/JonasKs)\
**Post date:** [October 29, 2020, 10:11am UTC](https://forum.djangoproject.com/t/inject-a-guid-correlation-id-into-every-log-message-in-a-django-request-now-with-asgi-async-support-for-django3-1-and-3-2/4989/3 "2020-10-29T10:11:44Z")

</div>

Thank you!

Personally we use it with Sentry and the [Sentry integration](https://django-guid.readthedocs.io/en/latest/integrations.html#sentry). Every time we have an exception, we can easily see the correlation ID and write `extra.correlation_id : <correlation_id>` in our Kibana search and get all logs for that request.

When end users experience errors they also only send us the correlation ID, and we can do the same. It’s honestly made our lifes a lot simpler.

I’ll check out both your links. If there is a need to configure some setting, creating an integration is very easy. Docs can be found [here](https://django-guid.readthedocs.io/en/latest/integrations.html#writing-your-own-integration). Right now integrations are not async, but we’ll look into that as well. (Pretty sure Sentry has async built in now)

Obviously PRs are very welcome too 🙂

---

<div class="post-metadata">

**Author:** ![JonasKs](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jonasks/32/557_2.png) [@JonasKs](https://forum.djangoproject.com/u/JonasKs)\
**Post date:** [January 20, 2021, 7:40pm UTC](https://forum.djangoproject.com/t/inject-a-guid-correlation-id-into-every-log-message-in-a-django-request-now-with-asgi-async-support-for-django3-1-and-3-2/4989/4 "2021-01-20T19:40:08Z")

</div>

I want to add that a Celery Integration is now available too. This means that if you spawn a Celery task from a Django request that same correlation ID will be in the Celery Tasks logs. If the Celery task is spawned from a Celery Beat, it will generate a new one.

You can read more about it in the [docs](https://django-guid.readthedocs.io/en/latest/integrations.html#celery).
