Skip to main content
https://travis-ci.org/Polyconseil/django-cid.png?branch=master

Logging is important. Anyone who has had a call at 3am to say the site is down knows this. Without quality logging it is almost impossible to work out what on earth is happening.

The more you log, the harder it is to track down exactly what the effects of a particular request are. Enter Django Correlation ID. Incoming requests are assigned a unique identifier. This can either happen in your public facing web server (e.g. nginx) or be applied by Django itself.

This correlation id (also known as request id) is then available through the Django request/response cycle and may be automatically included in all log messages. That way, you can easily link all log messages that relate to the same request:

2018-10-01T08:18:39.86+00:00 correlation_id=2433d5d4-27a3-4889-b14b-107a131368a3 Call to plug from cpoint=1
2018-10-01T08:18:39.90+00:00 correlation_id=72fbd7dd-a0ba-4f92-9ed0-0db358338e86 Call to state by cpoint=2 with {'state': {'B': 'idle', 'A': 'on_charge'}}
2018-10-01T08:18:39.92+00:00 correlation_id=2433d5d4-27a3-4889-b14b-107a131368a3 Ended rental=7 customer="John Smith" on plug

In this example, we can see that the first and the third log messages are tied to the same request, while the second message relates to a distinct request.

In addition to these logs, django-cid can include the correlation id:

  • in all SQL queries (as a comment);

  • in rendered templates;

  • as a header in the HTTP response generated by Django;

  • and possibly anywhere by using the API of django-cid, for example as an HTTP header on a request to another internal system of yours, which is especially useful in service-oriented architecture.

Documentation can be found at: https://django-correlation-id.readthedocs.org/

Sources are on GitHub: https://github.com/Polyconseil/django-cid

Supported versions

We currently support the following versions:

  • Django 2.2 with Python >= 3.5.

  • Django 3.0 with Python >= 3.6.

Other versions may work but are not supported.

History

2.1 (2020-06-22)

  • Add support of Django 3.0

  • backward incompatible: Drop support of Django 2.1.

2.0 (2019-09-27)

  • backward incompatible: Drop support of Python 3.4.

  • backward incompatible: Drop support of Django 1.11 and Django 2.0.

  • Add CID_GENERATOR setting to allow the customization of the correlation id.

1.3 (2018-10-09)

  • bugfix: Fix packaging bug (introduced in version 1.2) that caused two extra packages tests and sandbox to be installed.

1.2 (2018-10-08)

  • bugfix: Fix bug (introduced in version 1.0) that caused the correlation id to be reused across all requests that were processed by the same thread.

1.1 (2018-10-01)

  • Allow to concatenate an upstream correlation id with a locally-generated one, with a new CID_CONCATENATE_IDS setting.

1.0 (2018-10-01)

Warning: this release includes changes that are not backward compatible. Be sure to read the details below to know if and how you can migrate.

  • backward incompatible: Drop support of Django 1.10 and earlier.

  • backward incompatible: Drop support of Python 2.

  • Add support of Django 2. Version 0.x could already be used with Django 2 but tests were not run against it. They now are.

  • Generate cid outside of the middleware when GENERATE_CID is enabled, so that it’s available even if the middleware is not used.

  • Fix support of Django 1.11 in database backends.

  • Add PostGIS database backend.

  • Add CID_SQL_COMMENT_TEMPLATE to customize how the cid is included as comments in SQL queries.

  • backward incompatible: Change the app name to be used in INSTALLED_APPS.

    Migration from version 0.x: if you had cid in INSTALLED_APPS, replace it by cid.apps.CidAppConfig. If you did not, add the latter.

  • backward incompatible: Drop compatibility with MIDDLEWARE_CLASSES. You should use the MIDDLEWARE setting. If you already did, no change is necessary.

    If you really must use the old MIDDLEWARE_CLASSES setting, include CidOldStyleMiddleware instead of CidMiddleware.

0.2.0 (2016-12-06)

  • Added support for Django 1.10 middleware (thanks @qbey)

0.1.2 (2016-12-01)

  • Made CID repsonse header configurable, and optional (thanks @dbaty)

0.1.0 (2014-08-05)

  • First release on PyPI.

Metadata

Release files for django-cid 2.1

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-cid 2.1
File Size Uploaded
django-cid-2.1.tar.gz 18.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-cid 2.1
File Interpreter ABI Platform
django_cid-2.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 28.9 kB

Release files / django-cid-2.1.tar.gz

Download URL django-cid-2.1.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
766f2a0505a1335f3b516b1913472f662bbff8a16586629eb357fc679136effb
BLAKE2b-256 checksum
How to use checksums
209fad5221d59771d195cabd903918d61ba669b23359af3b7b0220c5c35774b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

Release files / django_cid-2.1-py2.py3-none-any.whl

Download URL django_cid-2.1-py2.py3-none-any.whl
Size 10.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
d520d02969018561ddf2e5f1629a14274977fc34fb81aa9e631f3cec688ce504
BLAKE2b-256 checksum
How to use checksums
406ac13910468ade9f2b806fb43b606f3d4439cd7ba17ec6b9b7752d67ef9d1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

Release history Release notifications | RSS feed

3.0

2 release files

2.4

2 release files

2.3

2 release files

2.2

2 release files

This release

2.1 This release

2 release files

2.0

2 release files

1.3

2 release files

1.2

2 release files

1.1

1 release file

1.0

1 release file

0.2.0

2 release files

0.1.2

2 release files

0.1.1

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