Skip to content

instrumentLangGraph does not instrument stream(), only invoke()Β #19626

@priscilawebdev

Description

@priscilawebdev

Is there an existing issue for this?

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions