build_tracer
Return a function that traces task execution. Catches all exceptions and updates result backend with the state and result.
def build_tracer(
name: string,
task: celery.app.task.Task,
loader: celery.loaders.base.BaseLoader = None,
hostname: string = None,
store_errors: boolean = True,
Info: type = TraceInfo,
eager: boolean = False,
propagate: boolean = False,
app: celery.Celery = None,
monotonic: callable = time.monotonic,
trace_ok_t: namedtuple = trace_ok_t,
IGNORE_STATES: set = IGNORE_STATES
) - > function
Return a function that traces task execution. Catches all exceptions and updates result backend with the state and result.
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | The display name of the task being traced. |
| task | celery.app.task.Task | The task instance to be executed and monitored. |
| loader | celery.loaders.base.BaseLoader = None | The loader used for task initialization and process cleanup hooks. |
| hostname | string = None | The worker hostname to record in the task metadata. |
| store_errors | boolean = True | Whether to persist error details to the result backend. |
| Info | type = TraceInfo | The class used to wrap task execution metadata and state handling. |
| eager | boolean = False | If true, the task is executed locally in the current process without a broker. |
| propagate | boolean = False | Whether to re-raise exceptions to the caller instead of catching them. |
| app | celery.Celery = None | The Celery application instance associated with the task. |
| monotonic | callable = time.monotonic | The clock function used to measure task execution duration. |
| trace_ok_t | namedtuple = trace_ok_t | The return type structure for successful trace results. |
| IGNORE_STATES | set = IGNORE_STATES | A set of task states that should not trigger the after_return hook. |
Returns
| Type | Description |
|---|---|
function | A trace_task function that wraps the task execution, handles state transitions (SUCCESS, RETRY, FAILURE), and manages result persistence. |