Skip to content

Emit OpenTelemetry spans around task callback invocations#67659

Open
dstandish wants to merge 1 commit into
apache:mainfrom
astronomer:otel-callback-spans
Open

Emit OpenTelemetry spans around task callback invocations#67659
dstandish wants to merge 1 commit into
apache:mainfrom
astronomer:otel-callback-spans

Conversation

@dstandish
Copy link
Copy Markdown
Contributor

Follow-up to #67347 (which added listener.<hook_name> spans). This wraps each task callback and pre/post-execute hook invocation in a callback.<kind> span, gated on task span detail level > 1.

Covered invocations (all routed through create_executable_runner(...).run(...) in task-sdk/.../task_runner.py):

  • the five state-change callbacks: on_execute_callback, on_success_callback, on_failure_callback, on_retry_callback, on_skipped_callback (centralized in _run_task_state_change_callbacks)
  • the pre_execute / post_execute hooks in _execute_task

The callback function name and index are recorded as span attributes; a raising state-change callback records ERROR status on its span and is still swallowed/logged as before.

Note: the span is added at the genuine call sites in task_runner.py, not pushed down into create_executable_runner/callback_runner.py, because that runner is also reused to execute the actual task body (python_callable) in the standard PythonOperator — wrapping there would mislabel the main task execution.

Tests: new TestCallbackSpans unit tests in test_task_runner.py (span presence/attributes at level 2, none at level 1, error recording for a raising callback, pre/post-execute gating) and the otel integration test now asserts callback.on_execute_callback_execute_task and callback.on_success_callbackfinalize.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 4.7)

Generated-by: Claude Code (Opus 4.7) following the guidelines

Wrap each task callback and pre/post-execute hook invocation in a
`callback.<kind>` span, gated on task span detail level > 1 — the
follow-up to the `listener.<hook_name>` spans added in apache#67347. Covers the
five state-change callbacks (on_execute/on_success/on_failure/on_retry/
on_skipped) and the pre_execute/post_execute hooks. The callback function
name and index are recorded as span attributes, and a raising callback
records ERROR status on its span.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant