-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- 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
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 patchedPriority
React with π to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.