Workers AI integration drops output of non-streaming chat responses in the OpenAI format (`choices`)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
- Ambito
- observability
Direzione di ricerca
Inizia leggendo packages/server-utils/src/ai/workers-ai/utils.ts e la relativa funzione addResponseAttributes, poi confronta la gestione dello streaming esistente di Workers AI in ai/workers-ai/streaming.ts con quella di OpenAI in ai/openai/utils.ts. Aggiorna il percorso senza streaming per acquisire i messaggi di output, il testo della risposta e i motivi di fine da choices; verifica che la risposta nel nuovo formato registri questi attributi preservando il formato di risposta precedente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 8.8k
- Fork
- 1.9k
- Merge medio
- 1g 20h
- PR unite (30g)
- 682
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di getsentry/sentry-javascript
-
Bug Cloudflare Workers
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
getsentry/sentry-javascript#26091 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Vercel AI: `gen_ai.system_instructions` is missing when the system prompt is a message objectForse già presa @biggdawg320 l’ha presa 1 giorno fa. ApertaBug Package: node Spans vercel ai
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
getsentry/sentry-javascript#26079 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
fsIntegration crashes in native ESM when patching the read-only fs namespaceForse già presa @chargome l’ha presa 1 giorno fa. ApertaBug Node.js Waiting for: Product Owner
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
getsentry/sentry-javascript#25950 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
normalize() throws when a getter throws a Symbol or a null-prototype objectForse già presa @rjmcgee53192 l’ha presa 5 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
getsentry/sentry-javascript#25920 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Only create Nuxt database and storage spans when there is a parent spanForse già presa @nicohrubec l’ha presa 7 giorni fa. ApertaImprovement Nuxt
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
getsentry/sentry-javascript#25805 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di getsentry/sentry-javascript
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 2 giorni
-
reproduced
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
anomalyco/opencode#62052 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
strapi/design-system#2084 ·
I maintainer di solito rispondono entro 3 giorni
-
Report: &TV InternationalApertacheck:passed streams:remove
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 67/100
I maintainer di solito rispondono entro 1 giorno
-
OAuth documentation for GET /api/v2/users/me/ appears inconsistent with required global read scopeAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno