getsentry / getsentry/sentry-javascript

`instrumentLangGraph` input/output recording only works with `MessagesAnnotation`

未关闭
#19,628 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
Browser Bug
主要语言
TypeScript
星标
8.7k
派生
1.8k
平均合并
1 天 17 小时
30 天内合并 PR
515

描述

### 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&trace=5eb7a6719e6a45dd8b4accab1881c7bd&span=a2fd3ab2120a6698&trace-timestamp=1772622965

### Reproduction Example/SDK Setup

_No response_

### Steps to Reproduce

```js
const CustomState = Annotation.Root({
idea: Annotation(),
expanded: Annotation(),
validated: Annotation(),
});

const graph = new StateGraph(CustomState)
.addNode("expand", expandNode)
.addEdge(START, "expand")
.addEdge("expand", END);

Sentry.instrumentLangGraph(graph, { recordInputs: true, recordOutputs: true });
const compiled = graph.compile({ name: "my_agent" });
const result = await compiled.invoke({ idea: "test idea" });
```

### Expected Result

The `invoke_agent` span should contain the graph's input (`{ idea: "test idea" }`) and output state as span attributes.

### Actual Result

The `invoke_agent` span has no input or output data. No error or warning is logged.

### Additional Context

`instrumentCompiledGraphInvoke` hardcodes extraction for `MessagesAnnotation`:

```js
const inputMessages = args.length > 0 ? ((args[0])?.messages ?? []) : [];
```

It looks for `args[0].messages`, which only exists when using `MessagesAnnotation`. Custom state keys (like `idea`, `expanded`, etc.) are ignored. The OTEL `gen_ai.input.messages` / `gen_ai.output.messages` attributes are message-array-oriented by design, but there is no fallback to record arbitrary state.

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

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。