diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 861baa5..4057d12 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,7 +40,7 @@ jobs: fail-fast: false matrix: python-version: [ "3.7", "3.8", "3.9" ] - django-version: [ "3.1.1", "3.1.2" ] + django-version: [ "3.1.1", "3.1.2", "3.1.3" ] steps: - name: Check out repository uses: actions/checkout@v2 diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6ee9799..2500b0d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,8 +1,15 @@ Changelog ========= +`3.0.1`_ - 12.11.2020 +--------------------- + +**Bugfix** + +* Importing an integration before a `SECRET_KEY` was set would cause a circular import. + -`3.0.0`_ - 2020-11-04 - Full Django3.1+(ASGI/async) support! +`3.0.0`_ - 28.10.2020 - Full Django3.1+(ASGI/async) support! ------------------------------------------------------------ Brings full async/ASGI (as well as the old WSGI) support to Django GUID using ContextVars instead of thread locals. @@ -15,7 +22,7 @@ If you've already implemented ``django-guid`` in your project and are currently see the `upgrading docs`_. -`2.2.0`_ - 2020-11-04 +`2.2.0`_ - 04.11.2020 --------------------- **Features** @@ -26,7 +33,7 @@ see the `upgrading docs`_. * Added docs for the new setting -`2.1.0`_ - 2020-11-03 +`2.1.0`_ - 03.11.2020 --------------------- **Features** @@ -38,7 +45,7 @@ see the `upgrading docs`_. * Added docs for integrations -`2.0.0`_ - 2020-03-02 +`2.0.0`_ - 02.03.2020 --------------------- **This version contains backwards incompatible changes. Read the entire changelog before upgrading** @@ -58,7 +65,7 @@ see the `upgrading docs`_. * Restructured README and docs. -`1.1.1`_ - 2020-02-12 +`1.1.1`_ - 12.02.2020 --------------------- **Improvements** @@ -66,7 +73,7 @@ see the `upgrading docs`_. * Fixed ``EXPOSE_HEADER`` documentation issue. New release has to be pushed to fix PyPi docs. -`1.1.0`_ - 2020-02-10 +`1.1.0`_ - 10.02.2020 --------------------- **Features** @@ -75,7 +82,7 @@ see the `upgrading docs`_. -`1.0.1`_ - 2020-02-08 +`1.0.1`_ - 08.02.2020 --------------------- **Bugfix** @@ -96,7 +103,7 @@ see the `upgrading docs`_. -`1.0.0`_ - 2020-01-14 +`1.0.0`_ - 14.01.2020 --------------------- **Features** @@ -120,7 +127,7 @@ see the `upgrading docs`_. -`0.3.1`_ - 2020-01-13 +`0.3.1`_ - 13.01.2020 --------------------- **Improvements** @@ -135,7 +142,7 @@ see the `upgrading docs`_. -`0.3.0`_ - 2020-01-10 +`0.3.0`_ - 10.01.2020 --------------------- **Features** @@ -149,7 +156,7 @@ see the `upgrading docs`_. * Improved the README with more information and a list of all the available settings -`0.2.3`_ - 2020-01-09 +`0.2.3`_ - 09.01.2020 --------------------- **Improvements** @@ -161,7 +168,7 @@ see the `upgrading docs`_. * Improved logging -`0.2.2`_ - 2019-12-21 +`0.2.2`_ - 21.12.2019 --------------------- **Improvements** @@ -169,7 +176,7 @@ see the `upgrading docs`_. * Removed the mandatory DJANGO_GUID settings in settings.py. Added an example project to demonstrate how to set the project up -`0.2.1`_ - 2019-12-21 +`0.2.1`_ - 21.12.2019 --------------------- **Improvements** @@ -177,15 +184,15 @@ see the `upgrading docs`_. * Workflow added, better docstrings, easier to read flow -`0.2.0`_ - 2019-12-21 +`0.2.0`_ - 21.12.2019 --------------------- **Features** * Header name and header GUID validation can be specified through Django settings -2019-12-20 ------------------- +20.10.2019 +---------- * Initial release @@ -205,3 +212,4 @@ see the `upgrading docs`_. .. _2.2.0: https://github.com/snok/django-guid/compare/2.1.0...2.2.0 .. _3.0.0: https://github.com/snok/django-guid/compare/2.2.0...3.0.0 .. _upgrading docs: https://django-guid.readthedocs.io/en/latest/upgrading.html +.. _3.0.1: https://github.com/snok/django-guid/compare/3.0.0...3.0.1 diff --git a/demoproj/views/async_views.py b/demoproj/views/async_views.py index f0a1911..43739c4 100644 --- a/demoproj/views/async_views.py +++ b/demoproj/views/async_views.py @@ -16,10 +16,8 @@ async def index_view(request: HttpRequest) -> JsonResponse: :return: JsonResponse """ logger.info('This log message should have a GUID') - loop = asyncio.get_event_loop() - - task_one = loop.create_task(useless_function()) - task_two = loop.create_task(useless_function()) + task_one = asyncio.create_task(useless_function()) + task_two = asyncio.create_task(useless_function()) results = await asyncio.gather(task_one, task_two) return JsonResponse({'detail': f'It worked! Useless function response is {results}'}) diff --git a/django_guid/__init__.py b/django_guid/__init__.py index 4fbc445..fa894fc 100644 --- a/django_guid/__init__.py +++ b/django_guid/__init__.py @@ -1,4 +1,4 @@ from django_guid.api import clear_guid, get_guid, set_guid # noqa F401 -__version__ = '3.0.0' +__version__ = '3.0.1' default_app_config = 'django_guid.apps.DjangoGuidConfig' diff --git a/docs/configuration.rst b/docs/configuration.rst new file mode 100644 index 0000000..8d756f2 --- /dev/null +++ b/docs/configuration.rst @@ -0,0 +1,104 @@ +************* +Configuration +************* + +Once django guid has been installed, add the following to your projects' ``settings.py``: + + +1. Installed Apps +----------------- + +Add :code:`django_guid` to your :code:`INSTALLED_APPS`: + +.. code-block:: python + + INSTALLED_APPS = [ + ... + 'django_guid', + ] + + + +2. Middleware +------------- + +Add the :code:`django_guid.middleware.guid_middleware` to your ``MIDDLEWARE``: + +.. code-block:: python + + MIDDLEWARE = [ + 'django_guid.middleware.guid_middleware', + ... + ] + + +It is recommended that you add the middleware at the top, so that the remaining middleware loggers include the requests GUID. + +3. Logging Configuration +------------------------ + +Add :code:`django_guid.log_filters.CorrelationId` as a filter in your ``LOGGING`` configuration: + +.. code-block:: python + + LOGGING = { + ... + 'filters': { + 'correlation_id': { + '()': 'django_guid.log_filters.CorrelationId' + } + } + } + +Put that filter in your handler: + +.. code-block:: python + + LOGGING = { + ... + 'handlers': { + 'console': { + 'class': 'logging.StreamHandler', + 'formatter': 'medium', + 'filters': ['correlation_id'], + } + } + } + +And make sure to add the new ``correlation_id`` filter to one or all of your formatters: + +.. code-block:: python + + LOGGING = { + ... + 'formatters': { + 'medium': { + 'format': '%(levelname)s %(asctime)s [%(correlation_id)s] %(name)s %(message)s' + } + } + } + + +If these settings were confusing, please have a look in the demo projects' +`settings.py `_ file for a complete example. + +4. Django GUID Logger (Optional) +-------------------------------- + +If you wish to see the Django GUID middleware outputs, you may configure a logger for the module. +Simply add django_guid to your loggers in the project, like in the example below: + +.. code-block:: python + + LOGGING = { + ... + 'loggers': { + 'django_guid': { + 'handlers': ['console', 'logstash'], + 'level': 'WARNING', + 'propagate': False, + } + } + } + +This 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. diff --git a/docs/index.rst b/docs/index.rst index b29a614..4c5ad08 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -114,12 +114,13 @@ Contents :maxdepth: 3 install - upgrading + configuration settings api integrations extended_example troubleshooting contributing + upgrading publish changelog diff --git a/docs/install.rst b/docs/install.rst index 96bd65b..868974a 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -9,107 +9,8 @@ Install using pip: pip install django-guid +Install using poetry: -Configuration -============= - -Once settings have set up, add the following to your projects' ``settings.py``: - - -1. Installed Apps ------------------ - -Add :code:`django_guid` to your :code:`INSTALLED_APPS`: - -.. code-block:: python - - INSTALLED_APPS = [ - ... - 'django_guid', - ] - - - -2. Middleware -------------- - -Add the :code:`django_guid.middleware.guid_middleware` to your ``MIDDLEWARE``: - -.. code-block:: python - - MIDDLEWARE = [ - 'django_guid.middleware.guid_middleware', - ... - ] - - -It is recommended that you add the middleware at the top, so that the remaining middleware loggers include the requests GUID. - -3. Logging Configuration ------------------------- - -Add :code:`django_guid.log_filters.CorrelationId` as a filter in your ``LOGGING`` configuration: - -.. code-block:: python - - LOGGING = { - ... - 'filters': { - 'correlation_id': { - '()': 'django_guid.log_filters.CorrelationId' - } - } - } - -Put that filter in your handler: - -.. code-block:: python - - LOGGING = { - ... - 'handlers': { - 'console': { - 'class': 'logging.StreamHandler', - 'formatter': 'medium', - 'filters': ['correlation_id'], - } - } - } - -And make sure to add the new ``correlation_id`` filter to one or all of your formatters: - -.. code-block:: python - - LOGGING = { - ... - 'formatters': { - 'medium': { - 'format': '%(levelname)s %(asctime)s [%(correlation_id)s] %(name)s %(message)s' - } - } - } - - -If these settings were confusing, please have a look in the demo projects' -`settings.py `_ file for a complete example. - -4. Django GUID Logger (Optional) --------------------------------- - -If you wish to see the Django GUID middleware outputs, you may configure a logger for the module. -Simply add django_guid to your loggers in the project, like in the example below: - -.. code-block:: python - - LOGGING = { - ... - 'loggers': { - 'django_guid': { - 'handlers': ['console', 'logstash'], - 'level': 'WARNING', - 'propagate': False, - } - } - } +.. code-block:: bash -This 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. + poetry add django-guid diff --git a/pyproject.toml b/pyproject.toml index c3242ed..cb8bee5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "django-guid" -version = "3.0.0" # Remember to also change __init__.py version +version = "3.0.1" # Remember to also change __init__.py version description = "Middleware that enables single request-response cycle tracing by injecting a unique ID into project logs" authors = ["Jonas Krüger Svensson "] license = "BSD-4-Clause"