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]: