{"id":13415767,"url":"https://github.com/snok/django-guid","last_synced_at":"2026-05-05T06:07:27.955Z","repository":{"id":40467309,"uuid":"229243355","full_name":"snok/django-guid","owner":"snok","description":"Inject an ID into every log message from a Django request. ASGI compatible, integrates with Sentry, and works with Celery","archived":false,"fork":false,"pushed_at":"2024-07-18T17:21:59.000Z","size":32043,"stargazers_count":430,"open_issues_count":11,"forks_count":25,"subscribers_count":8,"default_branch":"main","last_synced_at":"2024-07-31T01:19:54.530Z","etag":null,"topics":["asgi","celery","correlation","correlation-id","django","django-correlation-id","django-guid","django-rest-framework","django3","guid","logging","request-id","sentry","tracing"],"latest_commit_sha":null,"homepage":"https://django-guid.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/snok.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":"docs/contributing.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-20T10:25:27.000Z","updated_at":"2024-07-31T01:20:09.042Z","dependencies_parsed_at":"2024-01-06T10:00:14.800Z","dependency_job_id":"532c5f77-e9a3-4e90-b9d7-b16eddcedc20","html_url":"https://github.com/snok/django-guid","commit_stats":{"total_commits":155,"total_committers":10,"mean_commits":15.5,"dds":0.5548387096774193,"last_synced_commit":"ee1d9fac6baf22fdb60e1fb51629e3a3bb836151"},"previous_names":["jonasks/django-guid"],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snok%2Fdjango-guid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snok%2Fdjango-guid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snok%2Fdjango-guid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snok%2Fdjango-guid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/snok","download_url":"https://codeload.github.com/snok/django-guid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254328385,"owners_count":22052632,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asgi","celery","correlation","correlation-id","django","django-correlation-id","django-guid","django-rest-framework","django3","guid","logging","request-id","sentry","tracing"],"created_at":"2024-07-30T21:00:51.964Z","updated_at":"2026-05-05T06:07:22.906Z","avatar_url":"https://github.com/snok.png","language":"Python","funding_links":[],"categories":["Third-Party Packages","Python"],"sub_categories":["Logging"],"readme":".. raw:: html\n\n    \u003cp align=\"center\"\u003e\n        \u003ch1 align=\"center\"\u003eDjango GUID\u003c/h1\u003e\n    \u003c/p\u003e\n    \u003cp align=\"center\"\u003e\n      \u003cem\u003eNow with ASGI support!\u003c/em\u003e\n    \u003c/p\u003e\n\n.. raw:: html\n\n    \u003cp align=\"center\"\u003e\n      \u003ca href=\"https://pypi.org/pypi/django-guid\"\u003e\n          \u003cimg src=\"https://img.shields.io/pypi/v/django-guid.svg\" alt=\"Package version\"\u003e\n      \u003c/a\u003e\n      \u003ca href=\"https://pypi.python.org/pypi/django-guid#downloads\"\u003e\n          \u003cimg src=\"https://img.shields.io/badge/python-3.8+-blue.svg\" alt=\"Downloads\"\u003e\n      \u003c/a\u003e\n      \u003ca href=\"https://pypi.python.org/pypi/django-guid\"\u003e\n          \u003cimg src=\"https://img.shields.io/pypi/djversions/django-guid?color=0C4B33\u0026logo=django\u0026logoColor=white\u0026label=django\" alt=\"Django versions\"\u003e\n      \u003c/a\u003e\n      \u003c/a\u003e\n      \u003ca href=\"https://img.shields.io/badge/ASGI-supported-brightgreen.svg\"\u003e\n          \u003cimg src=\"https://img.shields.io/badge/ASGI-supported-brightgreen.svg\" alt=\"ASGI\"\u003e\n      \u003c/a\u003e\n      \u003ca href=\"https://img.shields.io/badge/WSGI-supported-brightgreen.svg\"\u003e\n          \u003cimg src=\"https://img.shields.io/badge/WSGI-supported-brightgreen.svg\" alt=\"WSGI\"\u003e\n      \u003c/a\u003e\n    \u003c/p\u003e\n    \u003cp align=\"center\"\u003e\n      \u003ca href=\"https://django-guid.readthedocs.io/en/latest/?badge=latest\"\u003e\n          \u003cimg src=\"https://readthedocs.org/projects/django-guid/badge/?version=latest\" alt=\"Docs\"\u003e\n      \u003c/a\u003e\n\n      \u003ca href=\"https://codecov.io/gh/snok/django-guid\"\u003e\n          \u003cimg src=\"https://codecov.io/gh/snok/django-guid/branch/master/graph/badge.svg\" alt=\"Codecov\"\u003e\n      \u003c/a\u003e\n\n      \u003ca href=\"https://github.com/psf/black\"\u003e\n          \u003cimg src=\"https://img.shields.io/badge/code%20style-black-000000.svg\" alt=\"Black\"\u003e\n      \u003c/a\u003e\n      \u003ca href=\"https://github.com/pre-commit/pre-commit\"\u003e\n          \u003cimg src=\"https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit\u0026logoColor=white\" alt=\"Pre-commit\"\u003e\n      \u003c/a\u003e\n    \u003c/p\u003e\n\n\n--------------\n\n\nDjango GUID attaches a unique correlation ID/request ID to all your log outputs for every request.\nIn other words, all logs connected to a request now has a unique ID attached to it, making debugging simple.\n\n--------------\n\n\n**Resources**:\n\n* Free software: MIT License\n* Documentation: https://django-guid.readthedocs.io\n* Homepage: https://github.com/snok/django-guid\n\n--------------\n\n\n**Examples**\n\nLog output with a GUID:\n\n.. code-block:: flex\n\n    INFO ... [773fa6885e03493498077a273d1b7f2d] project.views This is a DRF view log, and should have a GUID.\n    WARNING ... [773fa6885e03493498077a273d1b7f2d] project.services.file Some warning in a function\n    INFO ... [0d1c3919e46e4cd2b2f4ac9a187a8ea1] project.views This is a DRF view log, and should have a GUID.\n    INFO ... [99d44111e9174c5a9494275aa7f28858] project.views This is a DRF view log, and should have a GUID.\n    WARNING ... [0d1c3919e46e4cd2b2f4ac9a187a8ea1] project.services.file Some warning in a function\n    WARNING ... [99d44111e9174c5a9494275aa7f28858] project.services.file Some warning in a function\n\n\nLog output without a GUID:\n\n.. code-block:: flex\n\n    INFO ... project.views This is a DRF view log, and should have a GUID.\n    WARNING ... project.services.file Some warning in a function\n    INFO ... project.views This is a DRF view log, and should have a GUID.\n    INFO ... project.views This is a DRF view log, and should have a GUID.\n    WARNING ... project.services.file Some warning in a function\n    WARNING ... project.services.file Some warning in a function\n\n\nSee the `documentation \u003chttps://django-guid.readthedocs.io\u003e`_ for more examples.\n\n************\nInstallation\n************\n\nInstall using pip:\n\n.. code-block:: bash\n\n    pip install django-guid\n\n\n********\nSettings\n********\n\nPackage settings are added in your ``settings.py``:\n\n.. code-block:: python\n\n    DJANGO_GUID = {\n        'GUID_HEADER_NAME': 'Correlation-ID',\n        'VALIDATE_GUID': True,\n        'RETURN_HEADER': True,\n        'EXPOSE_HEADER': True,\n        'INTEGRATIONS': [],\n        'IGNORE_URLS': [],\n        'UUID_LENGTH': 32,\n    }\n\n\n\n**Optional Parameters**\n\n* :code:`GUID_HEADER_NAME`\n        The name of the GUID to look for in a header in an incoming request. Remember that it's case insensitive.\n\n    Default: Correlation-ID\n\n* :code:`VALIDATE_GUID`\n        Whether the :code:`GUID_HEADER_NAME` should be validated or not.\n        If the GUID sent to through the header is not a valid GUID (:code:`uuid.uuid4`).\n\n    Default: True\n\n* :code:`RETURN_HEADER`\n        Whether to return the GUID (Correlation-ID) as a header in the response or not.\n        It will have the same name as the :code:`GUID_HEADER_NAME` setting.\n\n    Default: True\n\n* :code:`EXPOSE_HEADER`\n        Whether to return :code:`Access-Control-Expose-Headers` for the GUID header if\n        :code:`RETURN_HEADER` is :code:`True`, has no effect if :code:`RETURN_HEADER` is :code:`False`.\n        This is allows the JavaScript Fetch API to access the header when CORS is enabled.\n\n    Default: True\n\n* :code:`INTEGRATIONS`\n        Whether to enable any custom or available integrations with :code:`django_guid`.\n        As an example, using :code:`SentryIntegration()` as an integration would set Sentry's :code:`transaction_id` to\n        match the GUID used by the middleware.\n\n    Default: []\n\n* :code:`IGNORE_URLS`\n        URL endpoints where the middleware will be disabled. You can put your health check endpoints here.\n\n    Default: []\n\n* :code:`UUID_LENGTH`\n        Lets you optionally trim the length of the package generated UUIDs.\n\n    Default: 32\n\n*************\nConfiguration\n*************\n\nOnce settings have set up, add the following to your projects' ``settings.py``:\n\n1. Installed Apps\n=================\n\nAdd :code:`django_guid` to your :code:`INSTALLED_APPS`:\n\n.. code-block:: python\n\n    INSTALLED_APPS = [\n        ...\n        'django_guid',\n    ]\n\n\n2. Middleware\n=============\n\nAdd the :code:`django_guid.middleware.guid_middleware` to your ``MIDDLEWARE``:\n\n.. code-block:: python\n\n    MIDDLEWARE = [\n        'django_guid.middleware.guid_middleware',\n        ...\n     ]\n\n\nIt is recommended that you add the middleware at the top, so that the remaining middleware loggers include the requests GUID.\n\n3. Logging Configuration\n========================\n\nAdd :code:`django_guid.log_filters.CorrelationId` as a filter in your ``LOGGING`` configuration:\n\n.. code-block:: python\n\n    LOGGING = {\n        ...\n        'filters': {\n            'correlation_id': {\n                '()': 'django_guid.log_filters.CorrelationId'\n            }\n        }\n    }\n\nPut that filter in your handler:\n\n.. code-block:: python\n\n    LOGGING = {\n        ...\n        'handlers': {\n            'console': {\n                'class': 'logging.StreamHandler',\n                'formatter': 'medium',\n                'filters': ['correlation_id'],\n            }\n        }\n    }\n\nAnd make sure to add the new ``correlation_id`` filter to one or all of your formatters:\n\n.. code-block:: python\n\n    LOGGING = {\n        ...\n        'formatters': {\n            'medium': {\n                'format': '%(levelname)s %(asctime)s [%(correlation_id)s] %(name)s %(message)s'\n            }\n        }\n    }\n\n\nIf these settings were confusing, please have a look in the demo projects'\n`settings.py \u003chttps://github.com/snok/django-guid/blob/master/demoproj/settings.py\u003e`_ file for a complete example.\n\n4. Django GUID Logger (Optional)\n================================\n\nIf you wish to see the Django GUID middleware outputs, you may configure a logger for the module.\nSimply add django_guid to your loggers in the project, like in the example below:\n\n.. code-block:: python\n\n    LOGGING = {\n        ...\n        'loggers': {\n            'django_guid': {\n                'handlers': ['console', 'logstash'],\n                'level': 'WARNING',\n                'propagate': False,\n            }\n        }\n    }\n\nThis is especially useful when implementing the package, if you plan to pass existing GUIDs to the middleware, as misconfigured GUIDs will not raise exceptions, but will generate warning logs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnok%2Fdjango-guid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsnok%2Fdjango-guid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnok%2Fdjango-guid/lists"}