fix(server-utils): Instrument LangGraph stream executions - #23615
Open
psh4607 wants to merge 5 commits into
Open
fix(server-utils): Instrument LangGraph stream executions#23615psh4607 wants to merge 5 commits into
psh4607 wants to merge 5 commits into
Conversation
psh4607
force-pushed
the
fix/JS-1858/langgraph-stream-instrumentation
branch
from
August 26, 2026 04:17
35cd712 to
e500300
Compare
Handle ReadableStream consumption and record accumulated stream responses.
psh4607
force-pushed
the
fix/JS-1858/langgraph-stream-instrumentation
branch
from
August 26, 2026 04:20
f632689 to
bbd119d
Compare
psh4607
marked this pull request as ready for review
August 26, 2026 04:27
psh4607
requested review from
JPeer264 and
isaacs
and removed request for
a team
August 26, 2026 04:27
Record source chunks and complete spans across pipeTo and pipeThrough consumption. Co-Authored-By: OpenAI Codex <codex@openai.com>
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.
Reviewed by Cursor Bugbot for commit 794a336. Configure here.
Throw for locked pipeThrough inputs and forward asynchronous pipeline failures through the returned readable. Co-Authored-By: OpenAI Codex <codex@openai.com>
Preserve the native TypeError for locked pipeThrough inputs without reporting an internal stream failure or ending the active span. Co-Authored-By: OpenAI Codex <codex@openai.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

LangGraph
CompiledGraph.stream()now creates the samegen_ai.invoke_agentparent span asinvoke()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 whenstream()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()tostream()call per compiled graph so existing invoke instrumentation does not emit duplicate agent spans.JS-1858
Fixes #19626