From 1ed2bddba788315d93b46aa67af6edb1e4feb9ad Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 9 Dec 2021 09:36:52 +0100 Subject: [PATCH] root: fix celery task ID not being included in log Signed-off-by: Jens Langhammer --- authentik/core/middleware.py | 2 ++ authentik/root/celery.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/authentik/core/middleware.py b/authentik/core/middleware.py index 67ac896cb..5dadd1f27 100644 --- a/authentik/core/middleware.py +++ b/authentik/core/middleware.py @@ -65,4 +65,6 @@ def structlog_add_request_id(logger: Logger, method_name: str, event_dict: dict) """If threadlocal has authentik defined, add request_id to log""" if hasattr(LOCAL, "authentik"): event_dict.update(LOCAL.authentik) + if hasattr(LOCAL, "authentik_task"): + event_dict.update(LOCAL.authentik_task) return event_dict diff --git a/authentik/root/celery.py b/authentik/root/celery.py index 4698253b6..7267ae59a 100644 --- a/authentik/root/celery.py +++ b/authentik/root/celery.py @@ -43,9 +43,9 @@ def after_task_publish_hook(sender=None, headers=None, body=None, **kwargs): # pylint: disable=unused-argument @task_prerun.connect -def task_prerun_hook(task_id, task, *args, **kwargs): +def task_prerun_hook(task_id: str, task, *args, **kwargs): """Log task_id on worker""" - request_id = "task-" + uuid4().hex[5:] + request_id = "task-" + task_id.replace("-", "") LOCAL.authentik_task = { "request_id": request_id, }