fix(langchain): Set agent name as gen_ai.agent.name for chat and tool spans
#5877
3 issues
Medium
GEN_AI_AGENT_NAME not set in new_stream function - `sentry_sdk/integrations/langchain.py:1029-1030`
The new_stream function retrieves run_name at line 1020 but never sets SPANDATA.GEN_AI_AGENT_NAME on the span, unlike new_invoke which correctly sets it (line 967-968). This is an oversight in the refactoring - the old code had span.set_data(SPANDATA.GEN_AI_AGENT_NAME, agent_name) which was removed but not replaced. This breaks parity between streaming and non-streaming agent invocations and conflicts with the PR's stated goal to set agent name as gen_ai.agent.name.
Agent name (gen_ai.agent.name) not set on span in _wrap_agent_executor_stream - `sentry_sdk/integrations/langchain.py:1029-1033`
In the stream function _wrap_agent_executor_stream, the run_name is obtained via _get_run_name() (line 1020) and used in the span name (line 1024), but unlike _wrap_agent_executor_invoke (which sets SPANDATA.GEN_AI_AGENT_NAME on lines 967-968), the stream function never sets this span data. This creates inconsistent telemetry behavior between invoke and stream operations - streaming agents will not have the gen_ai.agent.name attribute set on their spans. This directly contradicts the PR title which claims to 'Set agent name as gen_ai.agent.name'.
Low
Missing test coverage for agent name extraction from metadata - `sentry_sdk/integrations/langchain.py:429-433`
The PR adds logic to extract lc_agent_name from kwargs.get("metadata") in on_chat_model_start, but the test file shows no tests for this feature. The skill instructions state that every PR should have appropriate test coverage. Without tests, it's unclear if the agent name extraction works correctly when metadata is present, absent, or contains an invalid type.
4 skills analyzed
| Skill | Findings | Duration | Cost |
|---|---|---|---|
| code-review | 2 | 4m 1s | $1.54 |
| find-bugs | 1 | 15m 43s | $2.86 |
| skill-scanner | 0 | 1m 34s | $0.44 |
| security-review | 0 | 3m 35s | $1.09 |
Duration: 24m 53s · Tokens: 3.9M in / 41.0k out · Cost: $5.95 (+extraction: $0.01, +merge: $0.00, +fix_gate: $0.01, +dedup: $0.01)