Skip to content

Introduce parent task spans and nest worker and trigger spans under them#63839

Merged
dstandish merged 38 commits intoapache:mainfrom
astronomer:parent-task-span
Mar 24, 2026
Merged

Introduce parent task spans and nest worker and trigger spans under them#63839
dstandish merged 38 commits intoapache:mainfrom
astronomer:parent-task-span

Conversation

@dstandish
Copy link
Copy Markdown
Contributor

@dstandish dstandish commented Mar 17, 2026

This lets us tie together the worker and trigger phases of task execution. Also lets us see the delta between task queued time and task start time.

example output

image

@dstandish
Copy link
Copy Markdown
Contributor Author

@xBis7 @ashb @nickstenning

@xBis7
Copy link
Copy Markdown
Contributor

xBis7 commented Mar 18, 2026

I changed the otel_test_dag.py to make task1 deferrable.

-@task
-def task1():
-    logger.info("starting task1")
+class Task1(BaseOperator):
+    def execute(self, context):
+        self.defer(
+            trigger=TimeDeltaTrigger(timedelta(minutes=1)),
+            method_name="execute_complete",
+        )
+
+    def execute_complete(self, context, event=None):
+        logger.info("starting task1")

-    with tracer.start_as_current_span("sub_span1") as s1:
-        s1.set_attribute("attr1", "val1")
-
-    logger.info("task1 finished.")
+        with tracer.start_as_current_span("sub_span1") as s1:
+            s1.set_attribute("attr1", "val1")
+        logger.info("task1 finished.")


with DAG(
    "otel_test_dag",
    default_args=args,
    schedule=None,
    catchup=False,
) as dag:
-    task1()
+    Task1(task_id="task1")

This is the result

image

The span for the task1 doesn't appear as a child of the dag_run span. It looks like that's the case in your screenshot as well.

@dstandish
Copy link
Copy Markdown
Contributor Author

The span for the task1 doesn't appear as a child of the dag_run span. It looks like that's the case in your screenshot as well.

oh interesting you are right thanks for pointing that out

this stuff is so tricky

Copy link
Copy Markdown
Contributor

@xBis7 xBis7 left a comment

Choose a reason for hiding this comment

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

@dstandish Thanks for the PR! I posted a few questions.

Comment thread airflow-core/src/airflow/executors/workloads/task.py
Comment thread airflow-core/src/airflow/models/taskinstance.py
Comment thread airflow-core/src/airflow/models/taskinstance.py Outdated
Comment thread airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py Outdated
@dstandish
Copy link
Copy Markdown
Contributor Author

The span for the task1 doesn't appear as a child of the dag_run span. It looks like that's the case in your screenshot as well.

ok @xBis7 i think i fixed it!

i updated the screen shot in the description. confirm when you have a chance!

@xBis7
Copy link
Copy Markdown
Contributor

xBis7 commented Mar 18, 2026

ok @xBis7 i think i fixed it!

i updated the screen shot in the description. confirm when you have a chance!

@dstandish I tested it locally and now it looks good!

This lets us tie together the worker and trigger phases of task execution. Also lets us see the delta between task queued time and task start time.
Copy link
Copy Markdown
Contributor

@xBis7 xBis7 left a comment

Choose a reason for hiding this comment

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

Thanks for addressing all my comments! You've mentioned that you tested it with mapped tasks and fixed an issue. Pending a green CI.

LGTM!

@dstandish dstandish requested a review from potiuk as a code owner March 23, 2026 16:55
Move all local opentelemetry and observability imports to the top of
each test file, fix TestMakeTaskCarrier fixture to also patch the
shared lib tracer so new_task_run_carrier(None) works correctly, and
fix assertion indentation in test_emit_dagrun_span_with_none_or_empty_carrier.
Comment thread airflow-core/src/airflow/jobs/triggerer_job_runner.py
Comment thread airflow-core/src/airflow/models/taskmap.py
test_insert_mapping_includes_context_carrier and
test_clear_task_instances_resets_context_carrier only patched
airflow.models.taskinstance.tracer, but new_task_run_carrier uses the
tracer from airflow._shared.observability.traces. Without patching that,
older OTel versions (LowestDeps CI) produce an invalid span and an empty
carrier. Apply the same fix already used in TestMakeTaskCarrier.
@dstandish dstandish merged commit 0dc4d33 into apache:main Mar 24, 2026
143 of 144 checks passed
@dstandish dstandish deleted the parent-task-span branch March 24, 2026 01:56
vatsrahul1001 pushed a commit that referenced this pull request Mar 25, 2026
…hem (#63839)

This lets us tie together the worker and trigger phases of task execution. Also lets us see the delta between task queued time and task start time.
nailo2c pushed a commit to nailo2c/airflow that referenced this pull request Mar 30, 2026
…hem (apache#63839)

This lets us tie together the worker and trigger phases of task execution. Also lets us see the delta between task queued time and task start time.
vatsrahul1001 pushed a commit that referenced this pull request Mar 30, 2026
…hem (#63839)

This lets us tie together the worker and trigger phases of task execution. Also lets us see the delta between task queued time and task start time.

(cherry picked from commit 0dc4d33)
Suraj-kumar00 pushed a commit to Suraj-kumar00/airflow that referenced this pull request Apr 7, 2026
…hem (apache#63839)

This lets us tie together the worker and trigger phases of task execution. Also lets us see the delta between task queued time and task start time.
abhijeets25012-tech pushed a commit to abhijeets25012-tech/airflow that referenced this pull request Apr 9, 2026
…hem (apache#63839)

This lets us tie together the worker and trigger phases of task execution. Also lets us see the delta between task queued time and task start time.
xBis7 added a commit to xBis7/airflow that referenced this pull request Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API area:Executors-core LocalExecutor & SequentialExecutor area:task-sdk area:Triggerer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants