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

GitHub | Read the docs

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! :slight_smile: 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 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. A huge thanks to @sondrelg as well for doing code reviews and rubber ducking with me. :slight_smile:

4 Likes

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 or Lightstep.

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.

Thank you!

Personally we use it with Sentry and the Sentry integration. 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. 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 :slight_smile:

1 Like