Skip to content

Stringify task_instance.id when setting OTEL span attribute - #66053

Merged
potiuk merged 3 commits into
apache:mainfrom
c-premus:fix/otel-ti-id-uuid-attr
May 10, 2026
Merged

potiuk merged 3 commits into
apache:mainfrom
c-premus:fix/otel-ti-id-uuid-attr

Conversation

@c-premus

@c-premus c-premus commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

closes: #66052

Summary

_emit_task_span() in the execution API 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), so it dropped the attribute and logged a warning per task state transition:

[warning  ] Invalid type UUID for attribute 'airflow.task_instance.id' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types [opentelemetry.attributes] correlation_id=... loc=__init__.py:119 ti_id=...

The fix stringifies the UUID, matching the convention already used at the top of the same module (bind_contextvars(ti_id=str(task_instance_id))).

Root cause

Introduced in #63839 (merged 2026-03-24, "Introduce parent task spans and nest worker and trigger spans under them"). First shipped in 3.2.0; reproducible on 3.2.1 and main.

Reproduction

  1. Run Airflow 3.2.x with native OTEL tracing enabled ([traces] otel_on = True and an OTLP endpoint).
  2. Trigger any DAG.
  3. docker logs <api-server> | grep "Invalid type UUID" — one warning per task state transition.

Impact

Cosmetic but noisy — the task itself runs fine, the span is still emitted with the other attributes (dag_id, task_id, run_id, try_number, map_index, state), only the TI UUID attribute is dropped. This prevents trace search by task instance ID in the trace backend.

Tests

Extended TestEmitTaskSpan.test_emit_task_span_sets_attributes to set a real UUID on the mock TI and assert the span attribute is present, equal to str(ti.id), and of type str.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code (Anthropic) following the guidelines

@boring-cyborg boring-cyborg Bot added area:API Airflow's REST/HTTP API area:task-sdk labels Apr 28, 2026
@boring-cyborg

boring-cyborg Bot commented Apr 28, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@henry3260 henry3260 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.

Thanks for your effort !

Comment thread airflow-core/newsfragments/66053.bugfix.rst Outdated
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>
Signed-off-by: Chris <63758245+c-premus@users.noreply.github.com>
Reviewer (henry3260) noted the newsfragment isn't needed for this fix.
@c-premus
c-premus force-pushed the fix/otel-ti-id-uuid-attr branch from 050d18f to 3b980b9 Compare April 29, 2026 11:06
@potiuk
potiuk merged commit 8310049 into apache:main May 10, 2026
140 checks passed
@boring-cyborg

boring-cyborg Bot commented May 10, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

@github-actions

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-2-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ v3-2-test PR Link

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:task-sdk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OTEL warning "Invalid type UUID for attribute 'airflow.task_instance.id'" floods api-server logs on task state updates

4 participants