Render mcp_list_tools spans instead of leaving them blank - #330
Open
laminar-coding-agent[bot] wants to merge 1 commit into
Open
Render mcp_list_tools spans instead of leaving them blank#330laminar-coding-agent[bot] wants to merge 1 commit into
laminar-coding-agent[bot] wants to merge 1 commit into
Conversation
`_apply_mcp_span_data` recorded the MCP server name and the tool list it returned as `openai.agents.mcp.*` attributes and stopped there. The trace view reads `lmnr.span.input` / `lmnr.span.output`, so every one of those spans showed up empty even though the data was on it — on a 15-turn agent run that is 15 blank TOOL spans that look like broken instrumentation. Every other handler in the file already calls `set_lmnr_span_io`; this one now does too, with the server as input and the tool list as output. The custom attributes stay for anyone querying them in SQL.
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.
Why
On any Agents-SDK run with an MCP server, every
agents.mcp_toolsspan renders empty in the trace view. A 15-turn chi-bench run produces 15 blank TOOL spans, which reads as broken instrumentation.The data was never missing.
_apply_mcp_span_datawrote it toopenai.agents.mcp.server/openai.agents.mcp.result, and the trace view readslmnr.span.input/lmnr.span.output. It was the only_apply_*_span_datahandler in the file that never calledset_lmnr_span_io.What changed
_apply_mcp_span_datanow also sets span I/O — the server name as input, the returned tool list as output. Theopenai.agents.mcp.*attributes are unchanged, so anything querying them in SQL keeps working.Verification
New
tests/test_openai_agents_span_data.py(3 tests, hermetic — no SDK or OTEL provider needed):Covers the populated case plus the two partial ones (no server, no result), asserting that a
Nonefield records no attribute rather than anullpayload.Confirmed against a production trace before the fix — all 15 spans had
input len: 0 | output len: 0while carrying:Also documented in CLAUDE.md
Three related non-obvious behaviours found while diagnosing this, none of them bugs:
mcp_toolsspans are emitted once per turn even withcache_tools_list=True— the span wrapsserver.list_tools(), which checks the cache internally. Measured: first span 11ms (real round trip), the other 14 ~0.3ms.mcp_toolsspan parents to the trace root, not the agent span —agents/run.pycallsget_all_tools()before it startsagent_span(...). One sibling-of-the-agent span per run is upstream ordering, not a parenting bug.openai.agents.*attribute is not visible in the trace view at all, which is the general form of the bug fixed here.🤖 Generated with Claude Code
Note
Low Risk
Localized instrumentation change with unit tests; no auth, export, or API surface changes.
Overview
Fixes blank
mcp_tools/mcp_list_toolsspans in the Laminar trace UI. Those spans already hadopenai.agents.mcp.serverand.result, but the view only showslmnr.span.input/lmnr.span.output._apply_mcp_span_datanow callsset_lmnr_span_io: server name as input (when present) and the tool list as output. The customopenai.agents.mcp.*attributes are unchanged for SQL queries.Adds hermetic
tests/test_openai_agents_span_data.py(full case, no server, no result).CLAUDE.mddocuments OpenAI Agents tracing pitfalls (trace view vs custom attrs, per-turnmcp_toolsspans, first-turn parenting, tool defs on Responses only).Reviewed by Cursor Bugbot for commit fdafd3c. Bugbot is set up for automated code reviews on this repo. Configure here.