fix(api): map OpenInference tool definitions into real tool objects#4397
fix(api): map OpenInference tool definitions into real tool objects#4397mmabrouk wants to merge 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughSummary by CodeRabbit
WalkthroughOpenInferenceAdapter now extracts tool definitions from JSON-encoded span attributes ChangesTool Extraction Enhancement
🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
b512ea4 to
1ad49e4
Compare
Railway Preview Environment
|
What was broken
When you open a trace span in the playground (for example a LangChain agent span that uses tools), the tools did not load. They showed up as raw, unreadable blobs instead of proper tool cards.
The cause is in how we ingest OpenInference traces. OpenInference sends each tool as
llm.tools.{i}.tool.json_schema, where the value is the full OpenAI tool object encoded as a JSON string. Our adapter did a plain key rename and stored it almost as-is, so the span ended up like this:The real tool object is still a string buried under
tool.json_schema. The playground readstool.typeandtool.function.name, and neither exists at the top level here, so it has nothing to render.The fix
I changed the OpenInference adapter to parse the
json_schemastring and store the actual tool object atag.data.inputs.tools.{i}. Same data, correct shape:Now the playground reads
tool.typeandtool.function.namedirectly and renders the tools.Two things worth noting:
The raw
llm.tools.*attributes still stay on the span, so we lose no original data. If ajson_schemaever fails to parse, we keep the raw string instead of dropping it.This only changes how we map tools at ingestion time. Spans stored before this fix keep the old shape. You need a fresh trace to see the corrected one.
Tests
I added
test_openinference_adapter.py. It covers one tool, multiple tools, the parsed{type, function}shape, the absence of the old wrapper, the unparseable fallback, and a full round trip throughunmarshall_attributes(including an emptyproperties: {}and a two-tool list). The full OTLP unit suite (104 tests) passes and ruff is clean. I also verified it live: after restarting the API, new traces ingest tools in the correct shape and open in the playground.