fix(langchain): Set agent name as gen_ai.agent.name for chat and tool spans
#5877
2 issues
find-bugs: Found 2 issues (1 medium, 1 low)
Medium
new_invoke ignores lc_agent_name metadata unlike new_stream - `sentry_sdk/integrations/langchain.py:961-968`
The new_invoke function does not check kwargs.get('metadata', {}).get('lc_agent_name') like new_stream does. When users pass metadata={'lc_agent_name': 'MyAgent'} to invoke(), the agent name from metadata is ignored and only run_name (from args) is considered. This contradicts the PR's stated goal of setting agent name as gen_ai.agent.name and creates inconsistent behavior between invoke() and stream() methods.
Low
Misleading docstring in _get_available_tools describes removed functionality - `sentry_sdk/integrations/langchain.py:762-764`
The _get_available_tools function has a docstring that says 'Get the agent name and available tools for the agent' but after the refactoring, this function only returns tools - the agent name retrieval was moved to _get_run_name. This documentation mismatch could confuse developers maintaining this code.
Duration: 6m 20s · Tokens: 2.2M in / 21.4k out · Cost: $3.09 (+extraction: $0.00, +merge: $0.00, +fix_gate: $0.01)
Annotations
Check warning on line 968 in sentry_sdk/integrations/langchain.py
sentry-warden / warden: find-bugs
new_invoke ignores lc_agent_name metadata unlike new_stream
The `new_invoke` function does not check `kwargs.get('metadata', {}).get('lc_agent_name')` like `new_stream` does. When users pass `metadata={'lc_agent_name': 'MyAgent'}` to `invoke()`, the agent name from metadata is ignored and only `run_name` (from args) is considered. This contradicts the PR's stated goal of setting agent name as `gen_ai.agent.name` and creates inconsistent behavior between `invoke()` and `stream()` methods.