root: include task_id in events and logs (#9749)
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
@ -63,7 +63,7 @@ def task_prerun_hook(task_id: str, task, *args, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
@task_postrun.connect
|
@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"""
|
"""Log task_id on worker"""
|
||||||
CTX_TASK_ID.set(...)
|
CTX_TASK_ID.set(...)
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
@ -73,14 +73,16 @@ def task_postrun_hook(task_id, task, *args, retval=None, state=None, **kwargs):
|
|||||||
|
|
||||||
@task_failure.connect
|
@task_failure.connect
|
||||||
@task_internal_error.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"""
|
"""Create system event for failed task"""
|
||||||
from authentik.events.models import Event, EventAction
|
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(...)
|
CTX_TASK_ID.set(...)
|
||||||
if before_send({}, {"exc_info": (None, exception, None)}) is not None:
|
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]:
|
def _get_startup_tasks_default_tenant() -> list[Callable]:
|
||||||
|
|||||||
Reference in New Issue
Block a user