fix: resolve TypeError when passing non-iterable ToolNode objects to langchain instrumentation tools extraction#4049
Conversation
…langchain instrumentation tools extraction
📝 WalkthroughWalkthroughThe changes extend the agent wrapper's tool-definition extraction to conditionally iterate over a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/opentelemetry-instrumentation-langchain/tests/test_langgraph.py (1)
558-591: Test adequately covers the fix; consider strengthening the assertion.The test validates that the
create_agentspan is produced withGEN_AI_TOOL_DEFINITIONSwhen aToolNodeis passed — which is exactly the regression case. To make the test guard against future regressions wheretools_by_nameiteration silently yields zero definitions, consider additionally asserting the tool name is present in the serialized definitions:✅ Optional stronger assertion
assert create_span.attributes[GenAIAttributes.GEN_AI_AGENT_NAME] == "ToolNodeAgent" assert GenAIAttributes.GEN_AI_TOOL_DEFINITIONS in create_span.attributes + import json as _json + tool_defs = _json.loads(create_span.attributes[GenAIAttributes.GEN_AI_TOOL_DEFINITIONS]) + assert any(t.get("name") == "get_weather" for t in tool_defs)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/opentelemetry-instrumentation-langchain/tests/test_langgraph.py` around lines 558 - 591, The test should additionally assert that the serialized tool definitions actually include the tool's name to prevent silent regressions; in test_create_react_agent_with_toolnode after locating create_span (from create_react_agent with ToolNode) deserialize or inspect create_span.attributes[GenAIAttributes.GEN_AI_TOOL_DEFINITIONS] and assert it contains "get_weather" (the tool defined via `@tool`) so the ToolNode -> tools_by_name serialization is validated.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/opentelemetry-instrumentation-langchain/tests/test_langgraph.py`:
- Around line 558-591: The test should additionally assert that the serialized
tool definitions actually include the tool's name to prevent silent regressions;
in test_create_react_agent_with_toolnode after locating create_span (from
create_react_agent with ToolNode) deserialize or inspect
create_span.attributes[GenAIAttributes.GEN_AI_TOOL_DEFINITIONS] and assert it
contains "get_weather" (the tool defined via `@tool`) so the ToolNode ->
tools_by_name serialization is validated.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 43da2013-62c3-4925-9846-f1bb140d44fe
📒 Files selected for processing (2)
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/patch.pypackages/opentelemetry-instrumentation-langchain/tests/test_langgraph.py
feat(instrumentation): ...orfix(instrumentation): ....Summary by CodeRabbit
Release Notes
Bug Fixes
Tests