Repository navigation
fix(server-utils): Create an invoke_agent span for LangGraph stream() - #25749
RulaKhaled wants to merge 4 commits into
Conversation
LangGraph runs the graph as soon as stream() is called, whether or not the stream is read, so the span ends on the run's own end or error callback. A break never reaches those callbacks, so it ends the span too. Co-Authored-By: Seongho.Bak <psh30095@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lpers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…allbacks invoke() and stream() now copy the config instead of writing Sentry's metadata and callbacks into the caller's object, and start from the parent run's callbacks when none are passed, as LangChain would. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Optional E2E testsSome optional checks were not successful. They do not block the merge. 3 not successful, 57 successful. See the run.
Successful checks
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6923219. Configure here.
| return graph; | ||
| } | ||
|
|
||
| const agentSpans = (): Span[] => endedSpans.filter(span => spanToStaticSpanJSON(span).op === 'gen_ai.invoke_agent'); |
There was a problem hiding this comment.
Hard-coded span op in new test
Low Severity
The new stream unit test filters agent spans by a hard-coded gen_ai.invoke_agent op string instead of the GEN_AI_INVOKE_AGENT constant from @sentry/conventions/op. Flagged because the review rules require test assertions on span ops to use those constants.
Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit 6923219. Configure here.


CompiledGraph.stream()produced nogen_ai.invoke_agentspan, so the chat and tool spans of a streamed run had no agent span above them.LangGraph runs the graph as soon as
stream()is called, whether or not anyone reads it, so the span now follows the run. It ends on the run's ownhandleChainEnd/handleChainError, and the output comes from the final state, the same wayinvoke()records it.invoke()keeps its single span. The shared setup also no longer writes Sentry's metadata and callbacks into the caller's config, and a graph seen by bothinstrumentStateGraph()and the integration is wrapped once, with the manual options winning.Known limitation. When a caller stops reading early, LangGraph keeps running the graph but never reports the run's end. After a
breakthe span ends at the break, so later nodes' spans start after it. Afterreader.cancel()or a client disconnecting fromnew Response(stream), the span never ends.Replaces #23615. Co-authored with @psh4607 from that PR.
Fixes #19626
🤖 Generated with Claude Code