GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server-utils): Instrument LangGraph stream executions by psh4607 · Pull Request #23615 · getsentry/sentry-javascript

Conversation

@psh4607

@psh4607 psh4607 commented Aug 26, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

LangGraph CompiledGraph.stream() now creates the same gen_ai.invoke_agent parent span as invoke() and keeps it active until stream consumption finishes. The shared wrapper is used by manual server-runtime instrumentation and diagnostics-channel auto-instrumentation.

Root cause

The compile and create-agent wrappers only patched invoke(). stream() returned an async iterable without an agent span, so callback-created child spans became roots. Ending a span when stream() resolves would also be too early because graph work continues while the stream is consumed.

The implementation preserves the original stream object, observes async-iterator and ReadableStream consumption paths, forwards chunks unchanged, records accumulated response attributes when enabled, and ends the span on completion, cancellation, or error. It also suppresses LangGraph's internal invoke() to stream() call per compiled graph so existing invoke instrumentation does not emit duplicate agent spans.

JS-1858

Fixes #19626

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@psh4607
psh4607 force-pushed the fix/JS-1858/langgraph-stream-instrumentation branch 2 times, most recently from f632689 to bbd119d Compare August 26, 2026 04:20
@psh4607
psh4607 marked this pull request as ready for review August 26, 2026 04:27
@psh4607
psh4607 requested review from a team as code owners August 26, 2026 04:27
@psh4607
psh4607 requested review from JPeer264 and isaacs and removed request for a team August 26, 2026 04:27
sentry[bot]
sentry Bot reviewed Aug 26, 2026
View reviewed changes
Comment thread packages/server-utils/src/ai/langgraph/streaming.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

cursor[bot]
cursor Bot reviewed Aug 26, 2026
View reviewed changes
Comment thread packages/server-utils/src/ai/langgraph/streaming.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/server-utils/src/ai/langgraph/streaming.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

cursor[bot]
cursor Bot reviewed Aug 26, 2026
View reviewed changes

@cursor cursor Bot left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/server-utils/src/ai/langgraph/streaming.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

sentry[bot]
sentry Bot reviewed Aug 26, 2026
View reviewed changes
Comment thread packages/server-utils/src/ai/langgraph/streaming.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

👋 @isaacs, @JPeer264, @getsentry/team-javascript-sdks — Please review this PR when you get a chance!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RulaKhaled
RulaKhaled self-requested a review September 2, 2026 12:40
@JPeer264
JPeer264 removed request for a team, JPeer264 and isaacs September 2, 2026 13:09
psh4607 added 5 commits September 3, 2026 10:29
@psh4607
fix(server-utils): Instrument LangGraph stream executions
82e75eb
Fixes getsentry#19626
@psh4607
fix(server-utils): Complete LangGraph stream spans
591bb2b
Handle ReadableStream consumption and record accumulated stream responses.
@psh4607
fix(server-utils): Preserve LangGraph pipe lifecycle
7b86b35
Record source chunks and complete spans across pipeTo and pipeThrough consumption.
@psh4607
fix(server-utils): Preserve pipeThrough errors
ca15369
Throw for locked pipeThrough inputs and forward asynchronous pipeline failures through the returned readable.
@psh4607
fix(server-utils): Keep span open on pipeThrough preconditions
cb32555
Preserve the native TypeError for locked pipeThrough inputs without reporting an internal stream failure or ending the active span.
@psh4607
psh4607 force-pushed the fix/JS-1858/langgraph-stream-instrumentation branch from 10f506d to cb32555 Compare September 3, 2026 01:33
sentry[bot]
sentry Bot reviewed Sep 3, 2026
View reviewed changes
Comment thread packages/server-utils/src/ai/langgraph/index.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/server-utils/src/ai/langgraph/index.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@RulaKhaled

RulaKhaled commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Thanks for digging into this! the stream lifecycle work is in good shape. i just kicked off the CI workflow, meanwhile there are a couple of comments to look at

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

RulaKhaled
RulaKhaled reviewed Sep 6, 2026
View reviewed changes
Comment thread packages/server-utils/src/ai/langgraph/index.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/server-utils/test/ai/lib/tracing/langgraph-stream.test.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/server-utils/src/ai/langgraph/streaming.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/server-utils/src/ai/langgraph/streaming.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you apply the label PR: no-auto-close I will leave it alone ... forever!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the PR: stale label Sep 28, 2026
@mydea
mydea requested a review from andreiborza September 29, 2026 11:37
@s1gr1d s1gr1d added the external PR from an external contributor label Sep 29, 2026
sentry[bot]
sentry Bot reviewed Oct 6, 2026
View reviewed changes
Comment thread packages/server-utils/src/ai/langgraph/streaming.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/server-utils/src/ai/langgraph/streaming.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@psh4607
fix(server-utils): Preserve spans on stream caller errors
a78a23e
sentry[bot]
sentry Bot reviewed Oct 6, 2026
View reviewed changes
Comment thread packages/server-utils/src/ai/langgraph/streaming.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/server-utils/src/ai/langgraph/streaming.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@psh4607
fix(server-utils): Reconcile LangGraph streaming with develop
5fd009c
sentry[bot]
sentry Bot reviewed Oct 6, 2026
View reviewed changes
Comment thread packages/server-utils/src/ai/langgraph/streaming.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@psh4607
fix(server-utils): Preserve stream outcomes on recording failures
5396574
sentry[bot]
sentry Bot reviewed Oct 6, 2026
View reviewed changes
Comment thread packages/server-utils/src/ai/langgraph/index.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/server-utils/src/ai/langgraph/streaming.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@andreiborza

andreiborza commented Oct 7, 2026

Copy link
Copy Markdown
Member

Hi @psh4607 thanks for working on this! Could you address the bot comments and fix the merge conflicts please?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

👋 @andreiborza — Please review this PR when you get a chance!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

1 similar comment
@github-actions

github-actions Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

👋 @andreiborza — Please review this PR when you get a chance!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andreiborza andreiborza added the Waiting for: Community label Oct 13, 2026
@github-actions

github-actions Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

👋 @andreiborza — Please review this PR when you get a chance!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

andreiborza
andreiborza requested changes Oct 16, 2026
View reviewed changes

@andreiborza andreiborza left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you address the bot comments and fix the merge conflicts please?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
RulaKhaled and others added 4 commits October 21, 2026 15:33
@RulaKhaled
Merge branch 'develop' into fix/JS-1858/langgraph-stream-instrumentation
a809823
@RulaKhaled @claude
fix(server-utils): Address LangGraph stream review feedback
29855c7
Wrap each compiled graph once when manual and auto instrumentation both
see it, stop closing a source iterator that already threw, and keep
streaming when recording a chunk fails. Add a LangGraph v1 stream suite.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RulaKhaled @claude
fix(server-utils): Harden LangGraph stream span lifecycle
2847297
Record only the root graph's output from subgraph and multi-mode chunks,
treat a caller's cancel as a finished run, and route tee/pipeTo/
pipeThrough through the instrumented reader (shared with Mistral) so
those consumers end the span. Manual instrumentation now wins over the
integration, and an unpatchable stream is returned to the caller.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RulaKhaled @claude
ref(server-utils): Simplify LangGraph stream lifecycle
a6d40c8
Reuse core handleCallbackErrors for reader and cancel settling, move the
unpatchable-stream fallback into instrumentStreamResult, end the span
once a locked cancel takes effect, and skip output recording for stream
modes that don't carry the graph output.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cursor[bot]
cursor Bot reviewed Oct 22, 2026
View reviewed changes

@cursor cursor Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ 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 a6d40c8. Configure here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/server-utils/src/ai/langgraph/streaming.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/server-utils/src/ai/langgraph/index.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@RulaKhaled @claude
fix(server-utils): Keep stream errors after a rejected LangGraph cancel
aac1c7a
A cancel that rejects no longer leaves the stream marked as cancelled,
so a later read failure still ends the agent span as an error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RulaKhaled RulaKhaled added the Accept Bundlesize Increase label Oct 22, 2026
RulaKhaled and others added 5 commits October 22, 2026 16:01
@RulaKhaled
Merge branch 'develop' into fix/JS-1858/langgraph-stream-instrumentation
53c76fb
@RulaKhaled @claude
fix(server-utils): Check pipe options before locking a LangGraph stream
e5b4875
pipeThrough without a readable side, or pipeTo/pipeThrough with an
invalid signal, took the source reader before the native call threw,
leaving the stream locked and its span open.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RulaKhaled
Merge branch 'fix/JS-1858/langgraph-stream-instrumentation' of https:…
1dc0f5b
…//github.com/psh4607/sentry-javascript into fix/JS-1858/langgraph-stream-instrumentation
@RulaKhaled @claude
style(server-utils): Format LangGraph streaming test
04be605
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RulaKhaled @claude
test(server-utils): Drop @langchain/core import from LangGraph stream…
a31f417
… test

@langchain/core is not a dependency of @sentry/server-utils, so the
import only resolved through hoisting and fails under CI's isolated
install. A local chunk with concat() exercises the same merge path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RulaKhaled RulaKhaled mentioned this pull request Oct 26, 2026
fix(server-utils): Create an invoke_agent span for LangGraph stream() #25749
Merged
@RulaKhaled

RulaKhaled commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

closing this in favour of #25749.

while getting this mergeable we found the span is tied to the wrong event. it ends when the caller finishes reading the stream, but langgraph runs the graph whether or not anyone reads it, so a stream nobody reads never sent its span. most of the review rounds here came from that.

#25749 ends the span on the run's own end/error callback instead, which drops most of the stream patching. the invoke/stream suppression from this PR carries over, and @psh4607 is co-author on it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RulaKhaled RulaKhaled closed this Oct 26, 2026
RulaKhaled added a commit that referenced this pull request Nov 5, 2026
@RulaKhaled @psh4607 @claude
fix(server-utils): Create an invoke_agent span for LangGraph stream() (…
eb0e92e
…#25749)

`CompiledGraph.stream()` produced no `gen_ai.invoke_agent` span, 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
own `handleChainEnd`/`handleChainError`, and the output comes from the
final state, the same way `invoke()` 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 both
`instrumentStateGraph()` 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 `break` the
span ends at the break, so later nodes' spans start after it. After
`reader.cancel()` or a client disconnecting from `new Response(stream)`,
the span never ends.

Replaces #23615. Co-authored with @psh4607 from that PR.

Fixes #19626

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Seongho.Bak <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
43081j pushed a commit to 43081j/sentry-javascript that referenced this pull request Nov 9, 2026
@RulaKhaled @psh4607
@claude @43081j
fix(server-utils): Create an invoke_agent span for LangGraph stream() (…
5af6fb4
…getsentry#25749)

`CompiledGraph.stream()` produced no `gen_ai.invoke_agent` span, 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
own `handleChainEnd`/`handleChainError`, and the output comes from the
final state, the same way `invoke()` 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 both
`instrumentStateGraph()` 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 `break` the
span ends at the break, so later nodes' spans start after it. After
`reader.cancel()` or a client disconnecting from `new Response(stream)`,
the span never ends.

Replaces getsentry#23615. Co-authored with @psh4607 from that PR.

Fixes getsentry#19626

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Seongho.Bak <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@sentry sentry[bot] sentry[bot] left review comments
@RulaKhaled RulaKhaled RulaKhaled left review comments
@cursor cursor[bot] cursor[bot] left review comments
@andreiborza andreiborza andreiborza requested changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

Accept Bundlesize Increase external PR from an external contributor Waiting for: Community

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

instrumentLangGraph does not instrument stream(), only invoke()

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@psh4607 @RulaKhaled @andreiborza @s1gr1d
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.