root: fix celery task ID not being included in log

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-12-09 09:36:52 +01:00
parent 26b35c9b7b
commit 1ed2bddba7
2 changed files with 4 additions and 2 deletions

View File

@ -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

View File

@ -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,
}