You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
openai_agents tracing: spans after a model call nest under its temporal:startActivity span instead of the turn #1855
When an agent running in a workflow calls a tool after a model call, the trace shows the tool's span nested inside the model call's temporal:startActivity span instead of next to it under the turn. This happens because the tracing interceptor makes temporal:startActivity the current Agents SDK span while it writes the span id into the activity header and never restores the previous span, so every span created afterwards in that context is parented to it. The fix is to keep the span current only while the header is captured.
Details
_ContextPropagationWorkflowOutboundInterceptor.start_activity (likewise start_child_workflow and start_local_activity) in temporalio/contrib/openai_agents/_trace_interceptor.py does:
Nothing resets the current span, and finish() in the done callback does not either (it could not safely: the callback runs in a copy of the contextvars context, so a token reset there raises ValueError). The span stays current until the enclosing span exits, and every span created in between without an explicit parent (tool calls, handoffs, guardrails within the same turn) is parented to it.
The interceptor is shared by the OpenAI platform and OpenTelemetry tracing modes, so both show the same nesting. tests/contrib/openai_agents/test_openai_tracing.py::test_tracing asserts turn → temporal:startActivity → temporal:executeActivity, which is the intended shape, but its workflow makes no tool calls, so this was not covered.
changed the title [-]openai_agents: temporal:startActivity span stays the current Agents SDK span after it finishes, so later spans nest under it[/-][+]openai_agents: temporal:startActivity stays the current Agents SDK span after finishing, misparenting later spans in the turn[/+]on Sep 11, 2026
changed the title [-]openai_agents: temporal:startActivity stays the current Agents SDK span after finishing, misparenting later spans in the turn[/-][+]openai_agents tracing: spans after a model call nest under its temporal:startActivity span instead of the turn[/+]on Sep 14, 2026
Activity
[-]openai_agents: temporal:startActivity span stays the current Agents SDK span after it finishes, so later spans nest under it[/-][+]openai_agents: temporal:startActivity stays the current Agents SDK span after finishing, misparenting later spans in the turn[/+][-]openai_agents: temporal:startActivity stays the current Agents SDK span after finishing, misparenting later spans in the turn[/-][+]openai_agents tracing: spans after a model call nest under its temporal:startActivity span instead of the turn[/+]Finish OpenAI Agents handle spans in the Context they were started in
Add native-tracing regression test for tool span parenting