From 68ef029bb104f35c899f54acfadd684e81addbc8 Mon Sep 17 00:00:00 2001 From: Mauricio Villegas <5780272+mauvilsa@users.noreply.github.com> Date: Fri, 21 Jun 2024 15:04:46 +0200 Subject: [PATCH] Fix correlation_id_context not considered in request patch --- .bumpversion.cfg | 5 ++++- reconplogger.py | 2 ++ reconplogger_tests.py | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 05628bc..2e2739e 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -2,7 +2,10 @@ current_version = 4.16.0 commit = True tag = True -tag_name = v{new_version} +parse = (?P\d+)\.(?P\d+)\.(?P\d+)(?P(\.dev|rc)[0-9]+)? +serialize = + {major}.{minor}.{patch}{release} + {major}.{minor}.{patch} [bumpversion:file:setup.cfg] search = version = {current_version} diff --git a/reconplogger.py b/reconplogger.py index 041e087..5301044 100644 --- a/reconplogger.py +++ b/reconplogger.py @@ -24,6 +24,8 @@ def _request_patch(slf, *args, **kwargs): headers = kwargs.pop("headers", {}) if has_request_context() and g.correlation_id: headers["Correlation-ID"] = g.correlation_id + elif current_correlation_id.get() is not None: + headers["Correlation-ID"] = current_correlation_id.get() return slf.request_orig(*args, **kwargs, headers=headers) setattr( diff --git a/reconplogger_tests.py b/reconplogger_tests.py index 654fdc4..e2dafff 100755 --- a/reconplogger_tests.py +++ b/reconplogger_tests.py @@ -317,6 +317,13 @@ def get_id(): self.assertEqual(werkzeug_logger.handlers, logger.handlers) self.assertGreaterEqual(werkzeug_logger.level, reconplogger.WARNING) + correlation_id = str(uuid.uuid4()) + with reconplogger.correlation_id_context(correlation_id): + response = requests.get(f"http://localhost:{port}/id") + self.assertEqual(response.status_code, 200) + self.assertEqual(correlation_id, response.text) + self.assertEqual(correlation_id, response.headers["Correlation-ID"]) + with app.test_request_context(): correlation_id = str(uuid.uuid4()) reconplogger.set_correlation_id(correlation_id)