Anthropic gen_ai span never ends when a streaming call is consumed via .asResponse()
@RulaKhaled 已经在做这个了。
开始于 2026年9月9日。
评估
这个 Issue 还没有评估数据。
描述
Problem
anthropicAIIntegration starts a gen_ai.chat span for messages.create({ stream: true }) but never ends it when the caller takes the raw Response via .asResponse() (or .withResponse()) instead of iterating the SDK's Stream. The span is silently dropped — no error, no partial data.
Cause
packages/server-utils/src/integrations/anthropic.ts:147 — wrapStreamResult checks isAsyncIterable(result). With .asResponse() the result is a raw Response, so the check fails and it returns false, meaning "end via beforeSpanEnd". beforeSpanEnd never fires, so nothing ends the span.
Repro
Two identical streaming calls, one per consumption style:
const client = new Anthropic({ apiKey: 'sk-fake', baseURL: 'http://127.0.0.1:3999' });
// A: raw Response
const res = await client.messages.create({ ...params, stream: true }).asResponse();
for await (const _ of res.body) {}
// B: SDK async iterable
const stream = await client.messages.create({ ...params, stream: true });
for await (const _ of stream) {}
Span lifecycle:
[spanStart] chat claude-haiku-4-5 <- A
[spanStart] chat claude-haiku-4-5 <- B
[spanEnd] chat claude-haiku-4-5 <- only one ends
Impact
Any consumer using .asResponse()/.withResponse() on a streaming call loses the span. Found via @flue/runtime, whose @earendil-works/pi-ai layer calls client.messages.create({ ...params, stream: true }, opts).asResponse() — a Flue app currently reports only a raw http.client span for every LLM call. Not Flue-specific.
Verified on @sentry/node@11.0.0-beta.2, @anthropic-ai/sdk@0.91.1, Node 24.11.1.
- 主要语言
- TypeScript
- 星标
- 8.7k
- 派生
- 1.9k
- 平均合并
- 1 天 18 小时
- 30 天内合并 PR
- 562
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
getsentry/sentry-javascript 的其他 Issue
-
Browser Waiting for: Product Owner
难度 2/5 1-3 小时 新手友好度 85/100
getsentry/sentry-javascript#24577 · 1 条评论 ·
-
Task
难度 2/5 1-3 小时 新手友好度 78/100
getsentry/sentry-javascript#24558 · 1 条评论 ·
-
Task
难度 1/5 1 小时以内 新手友好度 90/100
getsentry/sentry-javascript#24557 · 1 条评论 ·
-
Task
难度 2/5 1-3 小时 新手友好度 84/100
getsentry/sentry-javascript#24556 · 1 条评论 ·
-
Task
难度 1/5 1-3 小时 新手友好度 90/100
getsentry/sentry-javascript#24555 · 1 条评论 ·
查看 getsentry/sentry-javascript 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 75/100
-
bug v2
难度 2/5 1-3 小时 新手友好度 75/100
modelcontextprotocol/inspector#2458 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 75/100
railmapgen/rmp-gallery#4068 ·
-
Mend: dependency security vulnerability status: needs triage 🕵️♀️
难度 2/5 1-3 小时 新手友好度 70/100
carbon-design-system/ibm-products#9907 ·