Skip to content

Add task.execute detail span around task execute callable#67877

Merged
dstandish merged 1 commit into
apache:mainfrom
astronomer:add-task-execute-detail-span
Jul 1, 2026
Merged

Add task.execute detail span around task execute callable#67877
dstandish merged 1 commit into
apache:mainfrom
astronomer:add-task-execute-detail-span

Conversation

@dstandish

Copy link
Copy Markdown
Contributor

Extracts the execute-callable invocation (including the execution-timeout wrapper) from _execute_task into a dedicated _run_execute_callable helper decorated with @detail_span("task.execute"). This emits a child span around the actual task execution when the task span detail level is greater than 1, giving finer-grained tracing of where time is spent within a task run.

Regular task failures mark the span as errored automatically via OpenTelemetry. AirflowTaskTimeout inherits from BaseException, which OpenTelemetry does not auto-record, so the timeout handler sets the span status to ERROR explicitly.


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

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

Comment thread task-sdk/src/airflow/sdk/execution_time/task_runner.py
Comment thread task-sdk/tests/task_sdk/execution_time/test_task_runner.py
Comment thread task-sdk/src/airflow/sdk/execution_time/task_runner.py Outdated

@uranusjr uranusjr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending Kaxil’s feedback

Comment thread task-sdk/tests/task_sdk/execution_time/test_task_runner.py
Comment thread task-sdk/src/airflow/sdk/execution_time/task_runner.py

@kaxil kaxil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM -- clean extraction, and the task.execute span now correctly nests the operator's child spans (verified the nesting mechanism end to end). Approving.

Two non-blocking questions left inline: the safeguard-tracker test doesn't assert tracker non-leakage (one extra assertion would pin it), and a confirm-intent note on the copy_context() snapshot now being taken after the pre-execute hooks. Neither gates merge. The timeout span-status follow-up is tracked in #69146.

When task span detail level is greater than 1, the actual execute call was not separately traced, making it hard to see how much of a task's runtime was spent in the operator's own work versus the surrounding setup. Wrapping the execute call in its own span gives that finer-grained breakdown.

The contextvars context the callable runs in is snapshotted inside the new helper, after the span is current, so spans the operator emits during execute nest under it rather than alongside it.
@dstandish dstandish force-pushed the add-task-execute-detail-span branch from e8eaacf to 68e21b7 Compare June 30, 2026 19:44
@dstandish dstandish merged commit b006a97 into apache:main Jul 1, 2026
195 of 196 checks passed
@dstandish dstandish deleted the add-task-execute-detail-span branch July 1, 2026 19:06
jason810496 added a commit that referenced this pull request Jul 2, 2026
PR #67877 wrapped the operator execute callable in a new task.execute
detail span, so operator-emitted spans now nest under it instead of
directly under _execute_task. Integration tests do not run on regular
PRs, so the expected span hierarchy in the OTel integration test was
not updated there and the canary build started failing.
github-actions Bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Jul 2, 2026
apache#69236)

PR apache#67877 wrapped the operator execute callable in a new task.execute
detail span, so operator-emitted spans now nest under it instead of
directly under _execute_task. Integration tests do not run on regular
PRs, so the expected span hierarchy in the OTel integration test was
not updated there and the canary build started failing.
(cherry picked from commit 55cdf67)

Co-authored-by: Jason(Zhe-You) Liu <68415893+jason810496@users.noreply.github.com>
jason810496 added a commit to jason810496/airflow that referenced this pull request Jul 2, 2026
The otel core integration was only triggered by observability sources,
so PRs changing the spans the task runner emits (like apache#67877) or the
otel integration tests themselves passed CI without running the tests
that assert the span hierarchy, and breakage surfaced only in canary
builds.
aws-airflow-bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Jul 2, 2026
apache#69236)

PR apache#67877 wrapped the operator execute callable in a new task.execute
detail span, so operator-emitted spans now nest under it instead of
directly under _execute_task. Integration tests do not run on regular
PRs, so the expected span hierarchy in the OTel integration test was
not updated there and the canary build started failing.
(cherry picked from commit 55cdf67)

Co-authored-by: Jason(Zhe-You) Liu <68415893+jason810496@users.noreply.github.com>
jason810496 added a commit that referenced this pull request Jul 3, 2026
#69250)

The otel core integration was only triggered by observability sources,
so PRs changing the spans the task runner emits (like #67877) or the
otel integration tests themselves passed CI without running the tests
that assert the span hierarchy, and breakage surfaced only in canary
builds.
vatsrahul1001 pushed a commit that referenced this pull request Jul 3, 2026
… code changes (#69250)

The otel core integration was only triggered by observability sources,
so PRs changing the spans the task runner emits (like #67877) or the
otel integration tests themselves passed CI without running the tests
that assert the span hierarchy, and breakage surfaced only in canary
builds.
(cherry picked from commit 5298431)

Co-authored-by: Jason(Zhe-You) Liu <68415893+jason810496@users.noreply.github.com>
vatsrahul1001 pushed a commit that referenced this pull request Jul 3, 2026
#69236)

PR #67877 wrapped the operator execute callable in a new task.execute
detail span, so operator-emitted spans now nest under it instead of
directly under _execute_task. Integration tests do not run on regular
PRs, so the expected span hierarchy in the OTel integration test was
not updated there and the canary build started failing.
(cherry picked from commit 55cdf67)

Co-authored-by: Jason(Zhe-You) Liu <68415893+jason810496@users.noreply.github.com>
potiuk added a commit that referenced this pull request Jul 3, 2026
…69359)

When task span detail level is greater than 1, the actual execute call was not separately traced, making it hard to see how much of a task's runtime was spent in the operator's own work versus the surrounding setup. Wrapping the execute call in its own span gives that finer-grained breakdown.

The contextvars context the callable runs in is snapshotted inside the new helper, after the span is current, so spans the operator emits during execute nest under it rather than alongside it.

(cherry picked from commit b006a97)

Co-authored-by: Daniel Standish <15932138+dstandish@users.noreply.github.com>
potiuk added a commit that referenced this pull request Jul 3, 2026
… code changes (#69250) (#69285)

The otel core integration was only triggered by observability sources,
so PRs changing the spans the task runner emits (like #67877) or the
otel integration tests themselves passed CI without running the tests
that assert the span hierarchy, and breakage surfaced only in canary
builds.
(cherry picked from commit 5298431)

Co-authored-by: Jason(Zhe-You) Liu <68415893+jason810496@users.noreply.github.com>
Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
@potiuk potiuk added this to the Airflow 3.3.1 milestone Jul 3, 2026
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.

4 participants