getsentry / getsentry/sentry-javascript

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

Offen
#19,626 6 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
Browser Feature
Vorherrschende Sprache
TypeScript
Sterne
8.7k
Forks
1.8k
Ø Merge
1 T. 17 Std.
Gemergte PRs (30 T.)
515

Beschreibung

### 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

```js
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()`:

```js
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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.