Workers AI integration drops output of non-streaming chat responses in the OpenAI format (`choices`)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript
调研方向
首先阅读 packages/server-utils/src/ai/workers-ai/utils.ts 及其 addResponseAttributes 函数,然后比较 ai/workers-ai/streaming.ts 中现有的 Workers AI 流处理与 ai/openai/utils.ts 中的 OpenAI 处理。更新非流式路径,从 choices 中捕获输出消息、响应文本和结束原因;确认新格式的响应会记录这些属性,同时保留旧的响应格式。
由索引模型根据 Issue 内容生成。
描述
Is there an existing issue for this?
- I have checked for existing issues
How do you use Sentry?
Sentry SaaS (sentry.io)
Which SDK are you using?
@sentry/cloudflare
SDK Version
11.10.0 (@sentry/server-utils 11.10.0). The same code is on develop.
Framework Version
Cloudflare Workers, Workers AI binding
Steps to Reproduce
-
Instrument the Workers AI binding (the default
@sentry/cloudflaresetup). -
Call a model that answers in the OpenAI chat-completion format, without
stream: true. For example,@cf/google/gemma-4-26b-a4b-it:const result = await env.AI.run("@cf/google/gemma-4-26b-a4b-it", { messages: [{ role: "user", content: "Say hi" }], max_tokens: 50, }); -
Open the
gen_ai.chatspan in Sentry.
Expected Result
The span has gen_ai.output.messages, gen_ai.response.text and gen_ai.response.finish_reasons, the same as for a stream: true call to the same model.
Actual Result
The span has the token usage, but no output and no finish reason.
I sent the same prompt to @cf/google/gemma-4-26b-a4b-it twice through the Workers AI REST API, once without and once with stream: true. Then I passed the real responses through instrumentWorkersAiClient (11.10.0). The gen_ai.* span attributes were:
--- no stream
gen_ai.operation.name = "chat"
gen_ai.usage.input_tokens = 19
gen_ai.usage.output_tokens = 4
gen_ai.usage.total_tokens = 23
--- stream: true
gen_ai.operation.name = "chat"
gen_ai.output.messages = "[{\"role\":\"assistant\",\"parts\":[{\"type\":\"text\",\"content\":\"Hello there!\"}]}]"
gen_ai.response.finish_reasons = "[\"stop\"]"
gen_ai.response.streaming = true
gen_ai.response.text = "Hello there!"
gen_ai.usage.input_tokens = 19
gen_ai.usage.output_tokens = 4
gen_ai.usage.total_tokens = 23
The non-streaming response was:
{"id":"...","object":"chat.completion","created":0,"model":"@cf/google/gemma-4-26b-a4b-it","choices":[{"index":0,"message":{"role":"assistant","content":"Hello there!"},"finish_reason":"stop","logprobs":null}],"usage":{"prompt_tokens":19,"completion_tokens":4,"total_tokens":23}}
Cause
Workers AI returns two response formats:
- older models:
{ response: string, tool_calls?, usage } - newer models, such as gemma-4: the OpenAI chat-completion format with
choices[].message
The streaming path supports both. instrumentWorkersAiStream in ai/workers-ai/streaming.ts reads parsed.response and also parsed.choices[].delta.content, delta.tool_calls and finish_reason.
The non-streaming path supports only the old format. addResponseAttributes in ai/workers-ai/utils.ts reads only response.response and response.tool_calls:
A possible fix: when response.choices is an array, read choices[].message.content, choices[].message.tool_calls and choices[].finish_reason, the same way as the OpenAI integration (ai/openai/utils.ts) does.
Additional Context
Workaround: we wrap the call in our own gen_ai.chat span that sets gen_ai.output.messages from choices, and we call env.AI.run inside Sentry.suppressTracing() so that the SDK span does not duplicate it.
- 主要语言
- TypeScript
- 星标
- 8.8k
- 派生
- 1.9k
- 平均合并
- 1 天 20 小时
- 30 天内合并 PR
- 682
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
getsentry/sentry-javascript 的其他 Issue
-
Bug Cloudflare Workers
难度 2/5 1-3 小时 新手友好度 78/100
getsentry/sentry-javascript#26091 · 1 条评论 ·
维护者通常 1 天内回复
-
Vercel AI: `gen_ai.system_instructions` is missing when the system prompt is a message object可能已有人在做 @biggdawg320 今天认领。 未关闭Bug Package: node Spans vercel ai
难度 2/5 1-3 小时 新手友好度 73/100
getsentry/sentry-javascript#26079 · 1 条评论 ·
维护者通常 1 天内回复
-
fsIntegration crashes in native ESM when patching the read-only fs namespace可能已有人在做 @chargome 于 1 天前认领。 未关闭Bug Node.js Waiting for: Product Owner
难度 2/5 1-3 小时 新手友好度 68/100
getsentry/sentry-javascript#25950 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
normalize() throws when a getter throws a Symbol or a null-prototype object可能已有人在做 @rjmcgee53192 于 5 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
getsentry/sentry-javascript#25920 · 2 条评论 ·
维护者通常 1 天内回复
-
Only create Nuxt database and storage spans when there is a parent span可能已有人在做 @nicohrubec 于 6 天前认领。 未关闭Improvement Nuxt
难度 2/5 1-3 小时 新手友好度 83/100
getsentry/sentry-javascript#25805 · 2 条评论 ·
维护者通常 1 天内回复
查看 getsentry/sentry-javascript 的全部 Issue
相似的 Issue
-
[fullsend] E2E: scorecard — filecheck GitLab entity metrics unavailable due to initialDelay timing未关闭e2e-failure ready-to-code
难度 2/5 1-3 小时 新手友好度 75/100
redhat-developer/rhdh-plugin-export-overlays#4698 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
devswha/herdr-web-ui#2884 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
b:minor bug
难度 2/5 1-3 小时 新手友好度 78/100
software-mansion/argent#1771 ·
维护者通常 1 天内回复
-
Resources: New palettes of Xiamen可能已有人在做 @rmt-svc 今天认领。 未关闭resources
难度 1/5 1-3 小时 新手友好度 74/100
railmapgen/rmg-palette#2491 ·
维护者通常 4 天内回复