getsentry / getsentry/sentry-javascript

Reducing memory foot print for vercel AI messages

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

描述

### Problem Statement

When `sendDefaultPii: true`, [requestMessagesFromPrompt](https://github.com/getsentry/sentry-javascript/blob/72346740a44620368fe07478362cd272d14abe3d/packages/core/src/tracing/vercel-ai/utils.ts#L258) parses and re-serializes `ai.prompt.messages` on every AI span, even when no transformation is needed.

For a 4mb prompt, this briefly doubles memory usage and has inside the function another memory footprint (which is unavoidable I guess):
1. Original JSON string on the span attribute
2. Parsed array from `JSON.parse`
3. Re-serialized string from `getJsonString`/`getTruncatedJsonString`

The parse + reserialize is only necessary when:
- System instructions need to be extracted (messages contain role: "system")
- Truncation is enabled

In the common case (no system messages, no truncation), we could skip parsing entirely and reuse the original string.

### Solution Brainstorm

Not sure if there is a good solution for it or if it is worth fixing as 4mb is unusually big, but if there is a high traffic this could spike real fast.

### Additional Context

_No response_

### 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 摘要。