Skip to content

fix(closes OPEN-10883): correct root step timestamp and use semantic step types#651

Open
viniciusdsmello wants to merge 1 commit into
mainfrom
vini/open-10883-review-openai-agents-sdk-integration-in-python
Open

fix(closes OPEN-10883): correct root step timestamp and use semantic step types#651
viniciusdsmello wants to merge 1 commit into
mainfrom
vini/open-10883-review-openai-agents-sdk-integration-in-python

Conversation

@viniciusdsmello
Copy link
Copy Markdown
Contributor

Summary

Review of the OpenAI Agents SDK tracing processor (OPEN-10883). Fixes three issues affecting how traces render in Openlayer.

1. Root step timestamp (the reported bug)

The synthetic "Agent Workflow" root step was constructed inside on_trace_end, so steps.Step.__init__ stamped its start_time with time.time() at trace-end. This placed the parent step after its own children on the timeline and produced an incorrect inferenceTimestamp for the whole trace — exactly the rendering issue reported. The correct start time was already captured in on_trace_start but never applied.

Fix: anchor the root step to the on_trace_start time, clamped to the earliest child's start time (defensive against minor SDK/wall-clock skew). This confirms the issue was in our instrumentation rather than the UI.

2. Semantic step types

agent, function, and handoff spans were all emitted as generic UserCallStep, so the backend bucketed them as user_call and lost dedicated rendering. They now use the SDK's typed steps via step_factoryAgentStep, ToolStep, HandoffStep — with their typed fields populated, matching the convention used by the langchain / google_adk / claude_agent_sdk integrations.

3. New SDK span types (openai-agents 0.4.2)

guardrail, mcp_tools, speech, transcription, and speech_group spans previously fell through to the generic handler. They are now parsed and mapped:

Span Step type (backend TraceType)
agent AgentStep (agent)
function, mcp_tools ToolStep (tool)
handoff HandoffStep (handoff)
guardrail GuardrailStep (guardrail)
generation/response/speech/transcription ChatCompletionStep (chat_completion)
speech_group UserCallStep (user_call) — voice container

The TracingProcessor interface itself is unchanged in 0.4.2.

Testing

  • Manual repro against authentic SDK span_data objects: timeline invariant (parent start ≤ all children), all 8 step-type mappings, and typed-field population all verified.
  • ruff check clean; import smoke test; conditional-import regression test (tests/test_integration_conditional_imports.py) passes.

🤖 Generated with Claude Code

@viniciusdsmello viniciusdsmello force-pushed the vini/open-10883-review-openai-agents-sdk-integration-in-python branch 3 times, most recently from ebf200d to c023520 Compare June 3, 2026 01:09
… types

Review of the OpenAI Agents SDK tracing processor (OPEN-10883). Addresses
several issues affecting how traces render in Openlayer:

1. Root step timestamp (the reported bug): the synthetic "Agent Workflow" root
   step was constructed inside on_trace_end, so steps.Step.__init__ stamped its
   start_time with time.time() at trace-end. This placed the parent step after
   its own children on the timeline and produced an incorrect inferenceTimestamp
   for the whole trace. The root step is now anchored to the start time captured
   in on_trace_start, clamped to the earliest child start time. This confirms
   the issue was in the instrumentation rather than the UI.

2. Step types: agent, function and handoff spans were all emitted as generic
   UserCallStep, so the backend bucketed them as user_call and lost dedicated
   rendering. They now use the SDK's typed steps via step_factory
   (AgentStep/ToolStep/HandoffStep) with their typed fields populated, matching
   the convention used by the langchain/google_adk/claude_agent_sdk integrations.

3. New SDK span types (openai-agents 0.4.2): guardrail, mcp_tools, speech,
   transcription and speech_group spans previously fell through to the generic
   handler. They are now parsed and mapped to GuardrailStep, ToolStep and
   ChatCompletionStep (speech/transcription) respectively; speech_group remains
   a generic container step. The TracingProcessor interface itself is unchanged.

4. Dangling spans: when a guardrail tripwire fires the SDK aborts in-flight
   spans without emitting on_span_end, leaving end_time None. on_trace_end now
   backfills those steps (bounded by their parent's end time) and flags them
   with metadata.incomplete so they render with a duration instead of no end.

Also adds a guardrail scenario to the existing
examples/tracing/openai/openai_agents_tracing.ipynb notebook so it exercises the
GUARDRAIL step type alongside the existing agent/tool/handoff steps.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@viniciusdsmello viniciusdsmello force-pushed the vini/open-10883-review-openai-agents-sdk-integration-in-python branch from c023520 to 2deef85 Compare June 3, 2026 02:13
@viniciusdsmello viniciusdsmello changed the title fix(openai-agents): correct root step timestamp and use semantic step types fix(closes OPEN-10883): correct root step timestamp and use semantic step types Jun 3, 2026
@viniciusdsmello viniciusdsmello self-assigned this Jun 3, 2026
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.

1 participant