Skip to content

fix span description

56ec48f
Select commit
Loading
Failed to load commit list.
Open

fix(langchain): Set agent name as gen_ai.agent.name for chat and tool spans #5877

fix span description
56ec48f
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden: find-bugs completed Mar 31, 2026 in 6m 26s

2 issues

find-bugs: Found 2 issues (2 low)

Low

AttributeError if metadata=None prevents subsequent span data from being set - `sentry_sdk/integrations/langchain.py:429`

If langchain passes metadata=None explicitly in kwargs, kwargs.get("metadata", {}) returns None (not {}), causing .get("lc_agent_name") to raise AttributeError. While capture_internal_exceptions() suppresses this, the remaining span data (DATA_FIELDS, tools, prompts/messages) will not be recorded since they're in the same with block. The safer pattern is (kwargs.get("metadata") or {}).get("lc_agent_name").

GEN_AI_AGENT_NAME not set when using run_name in stream function - `sentry_sdk/integrations/langchain.py:1032-1033`

In new_stream, when agent_name (from metadata) is None but run_name is available, the span name correctly uses run_name (line 1022-1023), but GEN_AI_AGENT_NAME is not set (lines 1032-1033 only check agent_name is not None). This is inconsistent with new_invoke which sets GEN_AI_AGENT_NAME when run_name is set (lines 963-964). Users expecting consistent agent name data between invoke and stream will not see the agent name in stream spans when using run_name configuration.


Duration: 6m 20s · Tokens: 2.3M in / 19.7k out · Cost: $2.84 (+extraction: $0.01, +merge: $0.00, +fix_gate: $0.01)