Skip to content

merge master

181d5cb
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

merge master
181d5cb
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden: code-review completed Mar 31, 2026 in 4m 15s

2 issues

code-review: Found 2 issues (1 medium, 1 low)

Medium

Span name can be None in new_invoke when run_name is not set - `sentry_sdk/integrations/langchain.py:960`

In new_invoke, the span name is set directly to run_name (line 960), which can be None if no run_name is configured. The old code had a fallback: f"invoke_agent {agent_name}" if agent_name else "invoke_agent". The new_stream function correctly handles this with a default span_name = "invoke_agent", but new_invoke does not. This inconsistency could result in spans with None names, causing unexpected behavior or errors in Sentry's span processing.

Low

Incorrect return type annotation and docstring in _get_available_tools - `sentry_sdk/integrations/langchain.py:757-772`

The _get_available_tools function has a return type annotation of tuple[Optional[str], Optional[List[Any]]] but actually returns only tools (a single value, not a tuple). The docstring also incorrectly says 'Get the agent name and available tools'. This was left over from when this was _get_request_data which returned both values. This will cause type checker errors for callers expecting a tuple.


Duration: 4m 10s · Tokens: 1.2M in / 14.3k out · Cost: $1.98 (+extraction: $0.00, +merge: $0.00, +fix_gate: $0.00)

Annotations

Check warning on line 960 in sentry_sdk/integrations/langchain.py

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: code-review

Span name can be None in new_invoke when run_name is not set

In `new_invoke`, the span name is set directly to `run_name` (line 960), which can be `None` if no run_name is configured. The old code had a fallback: `f"invoke_agent {agent_name}" if agent_name else "invoke_agent"`. The `new_stream` function correctly handles this with a default `span_name = "invoke_agent"`, but `new_invoke` does not. This inconsistency could result in spans with `None` names, causing unexpected behavior or errors in Sentry's span processing.