kaxil opened a new pull request, #74769:
URL: https://github.com/apache/airflow/pull/74769
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:
```python
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](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#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](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
is needed.
* When adding dependency, check compliance with the [ASF 3rd Party License
Policy](https://www.apache.org/legal/resolved.html#category-x).
* For significant user-facing changes create newsfragment:
`{pr_number}.significant.rst`, in
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
You can add this file in a follow-up commit after the PR is created so you
know the PR number.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]