From f28209548b7c0c1f65ba7ebd62ee03d81d751d50 Mon Sep 17 00:00:00 2001 From: Jens L Date: Thu, 16 May 2024 13:33:00 +0200 Subject: [PATCH] root: include task_id in events and logs (#9749) Signed-off-by: Jens Langhammer --- authentik/root/celery.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/authentik/root/celery.py b/authentik/root/celery.py index a7120d9901..57105a75e3 100644 --- a/authentik/root/celery.py +++ b/authentik/root/celery.py @@ -63,7 +63,7 @@ def task_prerun_hook(task_id: str, task, *args, **kwargs): @task_postrun.connect -def task_postrun_hook(task_id, task, *args, retval=None, state=None, **kwargs): +def task_postrun_hook(task_id: str, task, *args, retval=None, state=None, **kwargs): """Log task_id on worker""" CTX_TASK_ID.set(...) LOGGER.info( @@ -73,14 +73,16 @@ def task_postrun_hook(task_id, task, *args, retval=None, state=None, **kwargs): @task_failure.connect @task_internal_error.connect -def task_error_hook(task_id, exception: Exception, traceback, *args, **kwargs): +def task_error_hook(task_id: str, exception: Exception, traceback, *args, **kwargs): """Create system event for failed task""" from authentik.events.models import Event, EventAction - LOGGER.warning("Task failure", exc=exception) + LOGGER.warning("Task failure", task_id=task_id.replace("-", ""), exc=exception) CTX_TASK_ID.set(...) if before_send({}, {"exc_info": (None, exception, None)}) is not None: - Event.new(EventAction.SYSTEM_EXCEPTION, message=exception_to_string(exception)).save() + Event.new( + EventAction.SYSTEM_EXCEPTION, message=exception_to_string(exception), task_id=task_id + ).save() def _get_startup_tasks_default_tenant() -> list[Callable]: