Skip to content

Record OpenAI Agents SDK traces as the Airflow task's OpenTelemetry spans - #74769

Merged
kaxil merged 2 commits into
mainfrom
openai-agents-tracing
Oct 15, 2026
Merged

kaxil merged 2 commits into
mainfrom
openai-agents-tracing

Conversation

@kaxil

@kaxil kaxil commented Oct 14, 2026

Copy link
Copy Markdown
Member

The OpenAI Agents SDK traces runs with a system of its own rather than OpenTelemetry, and by default sends every trace, prompts and model output included, to OpenAI's backend, whatever model the agent runs. agent_framework_tracing() cannot reach it the way it reaches Strands and ADK. This adds AirflowTraceProcessor, an SDK trace processor that records each trace as OpenTelemetry spans under the task's span:

set_trace_processors([AirflowTraceProcessor()])  # Airflow only; add_trace_processor keeps OpenAI's export too
with agent_framework_tracing():
    answer = Runner.run_sync(agent, question).final_output

Stacked on the CI PR.

Design rationale

The user registers the processor; the helper does not mute OpenAI's export. The SDK has public add_trace_processor and set_trace_processors, but no public way to inspect or remove its default exporter. Muting it inside agent_framework_tracing() would mean reading the trace provider's private processor list. With an explicit processor the user picks, with the SDK's own calls, whether traces stay in Airflow or go to both.

Its own processor rather than an existing instrumentation. openinference-instrumentation-openai-agents and opentelemetry-instrumentation-openai-agents also convert the SDK's traces, but they would be a new dependency for an experimental adapter, they have content switches of their own that agent_framework_tracing() does not set, and they do not mask. This processor follows common.ai's content rule: prompts, completions, tool arguments and results, and the SDK's error messages (some of which are app-supplied text, such as an approval rejection reason) are recorded only when [common.ai] otel_export_enabled and capture_content are both on, and pass through the masker. JSON text is parsed before it is masked, so a secret holding a quote or backslash is not missed in its escaped form.

Each SDK span is the current span while it runs. Spans other instrumentation starts inside a tool or model call, such as an HTTP request, nest under that call rather than beside the agent tree. The task's identity attributes are stamped by the processor itself, so they are on the spans whichever tracer provider records them.

Spans use the GenAI convention names: invoke_agent, chat with the model and token counts (both the Chat Completions and Responses paths), and execute_tool. The SDK's own task and turn spans are named openai_agents.task and openai_agents.turn, so they are not confused with the Airflow task's span. The content rule now comes from one helper, _content_capture_enabled(), which agent_framework_tracing() uses too.

Gotchas

  • Turning the SDK's tracing off (set_tracing_disabled, RunConfig(tracing_disabled=True)) stops the processor receiving anything too.
  • With RunConfig(trace_include_sensitive_data=False) the SDK withholds the whole response on the Responses path, so those chat spans carry token counts but no model name.

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@kaxil
kaxil added this pull request to stack #74771 October 14, 2026 22:05
@kaxil kaxil closed this Oct 14, 2026
@kaxil kaxil reopened this Oct 14, 2026
@kaxil
kaxil force-pushed the openai-agents-tracing branch 2 times, most recently from 46945cb to 4812fdd Compare October 15, 2026 12:46
Base automatically changed from openai-agents-ci to main October 15, 2026 12:47
…pans

The SDK traces runs with a system of its own rather than OpenTelemetry, so
agent_framework_tracing() cannot reach it. AirflowTraceProcessor is an SDK
trace processor that records each trace as spans under the current span,
following the GenAI conventions for agents, model calls and tool calls, with
content left out unless [common.ai] capture_content is on and masked when
recorded. Registered with set_trace_processors it also stops the SDK's
default export to OpenAI; add_trace_processor keeps both.
@kaxil
kaxil force-pushed the openai-agents-tracing branch from 4812fdd to f0b8e8a Compare October 15, 2026 12:47

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

A few questions inline.


Drafted-by: Claude Code (Sonnet 5.5); reviewed by @pankajastro before posting

…pans

A span the SDK never finished now ends with its trace, and one whose
attributes fail to build still ends. Model calls start as CLIENT spans with
gen_ai.provider.name on the Responses path and server.address on the Chat
Completions path. A result that is a bare number or string is masked as text,
and the Responses output is serialized only when content is captured.
@kaxil
kaxil merged commit 53c83b9 into main Oct 15, 2026
86 checks passed
@kaxil
kaxil deleted the openai-agents-tracing branch October 15, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants