fix(langchain): Set agent name as gen_ai.agent.name for chat and tool spans
#5877
2 issues
Medium
Inconsistent GEN_AI_AGENT_NAME handling between invoke and stream - `sentry_sdk/integrations/langchain.py:964-965`
The new_invoke function still sets GEN_AI_AGENT_NAME on the span using run_name (line 964-965), while new_stream had this code removed entirely. This creates inconsistent telemetry behavior where invoke_agent spans will have different attributes depending on whether invoke() or stream() is called. According to the PR description, lc_agent_name should be used as the agent name source through callback handlers, suggesting the setting in new_invoke should also be removed.
GEN_AI_AGENT_NAME not set in _wrap_agent_executor_stream - `sentry_sdk/integrations/langchain.py:1023-1025`
The refactoring removed the code that sets GEN_AI_AGENT_NAME attribute in _wrap_agent_executor_stream, while the equivalent code was preserved in _wrap_agent_executor_invoke. The old code had if agent_name: span.set_data(SPANDATA.GEN_AI_AGENT_NAME, agent_name) which was not replaced when switching from agent_name to run_name. This causes inconsistent telemetry data between invoke and stream operations - stream operations will be missing the agent name attribute.
4 skills analyzed
| Skill | Findings | Duration | Cost |
|---|---|---|---|
| code-review | 1 | 4m 21s | $1.73 |
| find-bugs | 1 | 5m 7s | $2.34 |
| skill-scanner | 0 | 2m 29s | $0.65 |
| security-review | 0 | 2m 3s | $0.94 |
Duration: 14m · Tokens: 3.5M in / 34.5k out · Cost: $5.68 (+dedup: $0.01, +extraction: $0.00, +fix_gate: $0.00)