Skip to content

Commit

Permalink
Fix correlation_id_context not considered in request patch (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
mauvilsa authored Jun 21, 2024
1 parent def880f commit 2ebc694
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
current_version = 4.16.0
commit = True
tag = True
tag_name = v{new_version}
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(?P<release>(\.dev|rc)[0-9]+)?
serialize =
{major}.{minor}.{patch}{release}
{major}.{minor}.{patch}

[bumpversion:file:setup.cfg]
search = version = {current_version}
Expand Down
2 changes: 2 additions & 0 deletions reconplogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions reconplogger_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2ebc694

Please sign in to comment.