`instrumentLangGraph` does not instrument `stream()`, only `invoke()`
Is there an existing issue for this?
- [x] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- [x] I have reviewed the documentation https://docs.sentry.io/
- [x] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/browser
SDK Version
^10.40.0
Framework Version
No response
Link to Sentry event
https://pri-dogfooding-ai.sentry.io/insights/ai-agents/?project=4510951776059472&statsPeriod=30d&query=trace:[990f076070fd4e64b8d9032e10f0f27c,34466beafe8a4f39a4ba82da51559827]
Reproduction Example/SDK Setup
No response
Steps to Reproduce
const graph = new StateGraph(MyAnnotation)
.addNode("step1", stepFn)
.addEdge(START, "step1")
.addEdge("step1", END);
Sentry.instrumentLangGraph(graph, { recordInputs: true, recordOutputs: true });
const compiled = graph.compile({ name: "my_agent" });
// Using invoke() — works, produces invoke_agent span
const result = await compiled.invoke({ input: "test" });
// Using stream() — no invoke_agent span created
const stream = await compiled.stream({ input: "test" });
for await (const chunk of stream) { /* ... */ }
Expected Result
Both invoke() and stream() should produce a parent span wrapping the graph execution.
Actual Result
| Method | create_agent span |
Agent execution span |
|---|---|---|
invoke() |
Yes (0.5ms) | Yes — gen_ai.invoke_agent (wraps full execution) |
stream() |
Yes (0.5ms) | None |
With stream(), only the create_agent span (from compile()) appears. The actual graph execution has no parent span. If createLangChainCallbackHandler is also used, its child spans become orphaned root transactions instead of nesting under a parent.
Note: The SDK currently defines only gen_ai.invoke_agent as the agent-level operation (via GEN_AI_INVOKE_AGENT_OPERATION_ATTRIBUTE). There is no stream_agent equivalent. Whether stream() should reuse invoke_agent or get its own operation name is a design decision.
Additional Context
instrumentStateGraphCompile only patches invoke():
const originalInvoke = compiledGraph.invoke;
if (originalInvoke && typeof originalInvoke === 'function') {
compiledGraph.invoke = instrumentCompiledGraphInvoke(...);
}
// stream() is never patched
Priority
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.
I’d like to work on this. Since v11 moved AI integrations to server runtimes and renamed instrumentLangGraph to instrumentStateGraph, I plan to add CompiledGraph.stream() instrumentation for the supported server runtimes, including the Node Orchestrion path, and add Node/Cloudflare regression coverage. Does that match the intended current scope?
Hey, thanks for writing in. You can work on this, but we'll need to get some fundamental changes in for the AI integrations over the coming weeks for the next major, so we should likely wait for these (should also be much easier then as we are simplifying some of the implementation).
@nicohrubec Thanks for the heads-up! I’ll hold off for now. Once the AI integration changes land and this issue is ready to pick up, could you ping me here? I’d be happy to take it then.
The v11 AI integration migration and the channel-based LangGraph work appear to have landed. I confirmed that current develop still wraps only CompiledGraph.invoke(), and I couldn't find an overlapping PR for stream() instrumentation.
I'm going to pick this up now, keeping the change scoped to full-stream lifecycle instrumentation in the shared server-utils and diagnostics-channel paths, with focused Node and Cloudflare regression coverage. Please let me know if you'd prefer a different scope.
Hey, sure we'll get it reviewed. Be aware that improvements to our AI integrations are not a high priority to as atm as we are busy with other projects, so can't make any promises on timelines.
A PR closing this issue has just been released 🚀
This issue was referenced by PR #25749, which was included in the 11.12.0 release.