Skip to content

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

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

dstandish merged 38 commits into
apache:mainfrom
astronomer:parent-task-span

Conversation

@dstandish

@dstandish dstandish commented Mar 17, 2026 •

Copy link
Copy Markdown
Contributor

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

xBis7 commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

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

@xBis7 xBis7 left a comment

Copy link
Copy Markdown
Contributor

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

xBis7 commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

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.
@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.
aaron-y-chen pushed a commit to aaron-y-chen/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
c-premus added a commit to c-premus/airflow that referenced this pull request Apr 29, 2026
The execution API's _emit_task_span() was setting the
"airflow.task_instance.id" span attribute to the raw UUID object.
The OTEL SDK only accepts str/bytes/int/float/bool attribute values
(or homogeneous sequences thereof), so it dropped the attribute and
logged a warning per task state transition:

    Invalid type UUID for attribute 'airflow.task_instance.id'
    value. Expected one of ['bool', 'str', 'bytes', 'int', 'float']
    or a sequence of those types

The fix is to stringify the UUID, matching the convention already
used in the same module (e.g. bind_contextvars(ti_id=str(...))).

The bug was introduced in apache#63839 and ships in 3.2.0 / 3.2.1.

Signed-off-by: Chris <63758245+c-premus@users.noreply.github.com>
potiuk pushed a commit that referenced this pull request May 10, 2026
* Stringify task_instance.id when setting OTEL span attribute

The execution API's _emit_task_span() was setting the
"airflow.task_instance.id" span attribute to the raw UUID object.
The OTEL SDK only accepts str/bytes/int/float/bool attribute values
(or homogeneous sequences thereof), so it dropped the attribute and
logged a warning per task state transition:

    Invalid type UUID for attribute 'airflow.task_instance.id'
    value. Expected one of ['bool', 'str', 'bytes', 'int', 'float']
    or a sequence of those types

The fix is to stringify the UUID, matching the convention already
used in the same module (e.g. bind_contextvars(ti_id=str(...))).

The bug was introduced in #63839 and ships in 3.2.0 / 3.2.1.

Signed-off-by: Chris <63758245+c-premus@users.noreply.github.com>

* Add newsfragment for OTEL UUID attribute fix

Signed-off-by: Chris <63758245+c-premus@users.noreply.github.com>

* Drop newsfragment per review feedback

Reviewer (henry3260) noted the newsfragment isn't needed for this fix.

---------

Signed-off-by: Chris <63758245+c-premus@users.noreply.github.com>
potiuk pushed a commit that referenced this pull request May 10, 2026
…te (#66053) (#66645)

* Stringify task_instance.id when setting OTEL span attribute

The execution API's _emit_task_span() was setting the
"airflow.task_instance.id" span attribute to the raw UUID object.
The OTEL SDK only accepts str/bytes/int/float/bool attribute values
(or homogeneous sequences thereof), so it dropped the attribute and
logged a warning per task state transition:

    Invalid type UUID for attribute 'airflow.task_instance.id'
    value. Expected one of ['bool', 'str', 'bytes', 'int', 'float']
    or a sequence of those types

The fix is to stringify the UUID, matching the convention already
used in the same module (e.g. bind_contextvars(ti_id=str(...))).

The bug was introduced in #63839 and ships in 3.2.0 / 3.2.1.



* Add newsfragment for OTEL UUID attribute fix



* Drop newsfragment per review feedback

Reviewer (henry3260) noted the newsfragment isn't needed for this fix.

---------
(cherry picked from commit 8310049)

Signed-off-by: Chris <63758245+c-premus@users.noreply.github.com>
Co-authored-by: Chris Premus <63758245+c-premus@users.noreply.github.com>
jason810496 pushed a commit to jason810496/airflow that referenced this pull request May 11, 2026
…6053)

* Stringify task_instance.id when setting OTEL span attribute

The execution API's _emit_task_span() was setting the
"airflow.task_instance.id" span attribute to the raw UUID object.
The OTEL SDK only accepts str/bytes/int/float/bool attribute values
(or homogeneous sequences thereof), so it dropped the attribute and
logged a warning per task state transition:

    Invalid type UUID for attribute 'airflow.task_instance.id'
    value. Expected one of ['bool', 'str', 'bytes', 'int', 'float']
    or a sequence of those types

The fix is to stringify the UUID, matching the convention already
used in the same module (e.g. bind_contextvars(ti_id=str(...))).

The bug was introduced in apache#63839 and ships in 3.2.0 / 3.2.1.

Signed-off-by: Chris <63758245+c-premus@users.noreply.github.com>

* Add newsfragment for OTEL UUID attribute fix

Signed-off-by: Chris <63758245+c-premus@users.noreply.github.com>

* Drop newsfragment per review feedback

Reviewer (henry3260) noted the newsfragment isn't needed for this fix.

---------

Signed-off-by: Chris <63758245+c-premus@users.noreply.github.com>
vatsrahul1001 pushed a commit that referenced this pull request May 20, 2026
…te (#66053) (#66645)

* Stringify task_instance.id when setting OTEL span attribute

The execution API's _emit_task_span() was setting the
"airflow.task_instance.id" span attribute to the raw UUID object.
The OTEL SDK only accepts str/bytes/int/float/bool attribute values
(or homogeneous sequences thereof), so it dropped the attribute and
logged a warning per task state transition:

    Invalid type UUID for attribute 'airflow.task_instance.id'
    value. Expected one of ['bool', 'str', 'bytes', 'int', 'float']
    or a sequence of those types

The fix is to stringify the UUID, matching the convention already
used in the same module (e.g. bind_contextvars(ti_id=str(...))).

The bug was introduced in #63839 and ships in 3.2.0 / 3.2.1.



* Add newsfragment for OTEL UUID attribute fix



* Drop newsfragment per review feedback

Reviewer (henry3260) noted the newsfragment isn't needed for this fix.

---------
(cherry picked from commit 8310049)

Signed-off-by: Chris <63758245+c-premus@users.noreply.github.com>
Co-authored-by: Chris Premus <63758245+c-premus@users.noreply.github.com>
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.

4 participants