Workers AI integration drops output of non-streaming chat responses in the OpenAI format (`choices`)
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 78/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- typescript
- Bereich
- observability
Rechercherichtung
Lies zuerst packages/server-utils/src/ai/workers-ai/utils.ts und die Funktion addResponseAttributes und vergleiche anschließend die bestehende Workers-AI-Streamverarbeitung in ai/workers-ai/streaming.ts mit der OpenAI-Verarbeitung in ai/openai/utils.ts. Aktualisiere den Nicht-Streaming-Pfad so, dass Ausgabenachrichten, Antworttext und Beendigungsgründe aus choices erfasst werden; bestätige, dass die Antwort im neuen Format diese Attribute aufzeichnet und das ältere Antwortformat beibehält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 8.8k
- Forks
- 1.9k
- Ø Merge
- 1 T. 20 Std.
- Gemergte PRs (30 T.)
- 682
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus getsentry/sentry-javascript
-
Bug Cloudflare Workers
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
getsentry/sentry-javascript#26091 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Vercel AI: `gen_ai.system_instructions` is missing when the system prompt is a message objectEvtl. vergeben @biggdawg320 hat das vor 1 Tag übernommen. OffenBug Package: node Spans vercel ai
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 73/100
getsentry/sentry-javascript#26079 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
fsIntegration crashes in native ESM when patching the read-only fs namespaceEvtl. vergeben @chargome hat das vor 1 Tag übernommen. OffenBug Node.js Waiting for: Product Owner
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
getsentry/sentry-javascript#25950 · 2 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
normalize() throws when a getter throws a Symbol or a null-prototype objectEvtl. vergeben @rjmcgee53192 hat das vor 5 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
getsentry/sentry-javascript#25920 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Only create Nuxt database and storage spans when there is a parent spanEvtl. vergeben @nicohrubec hat das vor 7 Tagen übernommen. OffenImprovement Nuxt
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
getsentry/sentry-javascript#25805 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in getsentry/sentry-javascript
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
vercel-labs/durable-harness#53 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
area/docs area/ui enhancement
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
melgarafael/DeskcommCRM#4098 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug ready-for-agent
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
kerti/balances-v2#801 ·
Maintainer antworten meist innerhalb von 1 Tag
-
lesson-submission pending-review
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 84/100
Ikalus1988/MisakaNet#4510 ·
Maintainer antworten meist innerhalb von 1 Tag