Stamp Airflow run identity onto agent runs and traces - #73275
Merged
pankajkoti merged 2 commits intoSep 17, 2026
Merged
pankajkoti merged 2 commits into
pankajkoti merged 2 commits into
Conversation
An agent run and the task instance that produced it shared no identifier, so a GenAI trace in an OTel backend could not be tied back to its task and a task had no handle on its own run. Observability surfaces had to reconstruct that join from timestamps. Giving the two a shared, per-attempt key makes the join exact and unblocks a downstream AI traces UI.
pankajkoti
force-pushed
the
stamp-airflow-run-identity-onto-agent-runs
branch
from
September 17, 2026 10:13
593b003 to
4a6cd33
Compare
Member
Author
pankajkoti
marked this pull request as ready for review
September 17, 2026 11:02
pankajkoti
requested review from
Lee-W,
ashb,
gopidesupavan and
kaxil
as code owners
September 17, 2026 11:02
kaxil
approved these changes
Sep 17, 2026
The first pass mutated a possibly caller-owned InstrumentationSettings object in place, so a settings instance shared across agent tasks or reused across HITL re-runs would carry the wrong run's identity and accumulate nested tracer wrappers. It also wrote run metadata to XCom regardless of do_xcom_push, guarded a task-instance id that is non-nullable at runtime, and omitted the run cost the docstring already promised. These changes keep the stamping per-run, honour the operator's XCom suppression flag, drop the dead guard, and surface cost.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Give an agent run and the Airflow task instance that produced it a shared
identifier, so a task's output can be joined to its GenAI trace without
reconstructing it from timestamps.
AgentOperator(and@task.agent) now:on each retry) as the pydantic-ai
run_id, so it surfaces onAgentRunResult.run_id, the run's messages, andgen_ai.agent.call.idonthe agent-run span
airflow.dag_id,airflow.task_id,airflow.dag_run.run_id,airflow.task_instance.try_number,airflow.task_instance.map_index,airflow.task_instance.id), so a span isfilterable by those directly rather than by walking up to the parent task span
run_idand tokenusageon XCom for a downstream taskRelies on the pydantic-ai
run_id=parameter (pydantic-ai#6615, added inv2.16.0). The provider already floors
pydantic-ai-slimat>=2.23.0, whichincludes it, so no dependency change is needed.
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.8) following the guidelines
🤖 Generated with Claude Code