Repository navigation
fix(ai): preserve telemetry stream replacements during credential redaction - #25135
Merged
Merged
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
gr2m
approved these changes
Nov 16, 2026
1 task done
Contributor
|
🚀 Published in:
|
RulaKhaled
added a commit
to getsentry/sentry-javascript
that referenced
this pull request
Nov 18, 2026
## What Adds a node integration scenario that runs `streamText` with tools through `@ai-sdk/openai` (Responses API, fake SSE `fetch`, no network) with tracing sampled and unsampled. The caller must get the streamed text, and the model and tool spans must be recorded. ## Why `ai` 7.0.168–7.0.173 broke this call with `ReadableStream is locked` whenever Sentry was loaded (#26403). Our existing scenarios use `MockLanguageModelV3`, which sends no request body, so `ai` never makes the redacted result copy that triggers the bug. `@ai-sdk/openai` attaches a telemetry redactor to the body when tools are sent, so it does. The suite requires `ai: '^7.0.174'`, the first release with the upstream fix (vercel/ai#25135). Refs #26403 <!-- junior-request-attribution:start --> via **Rola Abuhasna**. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AD0C848BQ509%3A1794901557.524269 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AD0C848BQ509%3A1794901557.524269) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AD0C848BQ509%3A1794901557.524269/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Rola Abuhasna <[email protected]>
melgarafael
pushed a commit
to melgarafael/DeskcommCRM
that referenced
this pull request
Nov 18, 2026
…I SDK (#4798) Com o provedor `openai-assinatura`, toda chamada "Responder o cliente" falhava em ~1 s com `Invalid state: The ReadableStream is locked`, e a aba Teste do agente dava `preview_failed`. Chamada curta do mesmo provedor passava; Gemini e OpenAI por chave não eram afetados. Causa, medida no código e nas dependências instaladas: - o ramo da assinatura é o único que monta `streamText` com tools (lib/agent-engine/edge/llm/run-model-call.ts:1131); os outros provedores vão por `generateText` (linha 1182); - com a integração `VercelAI` do Sentry instalada, o SDK assina o canal `ai:telemetry` e, no `asyncEnd`, troca `result.stream` por um stream espiado (`deferStreamedModelCallEnd` → `tapModelCallStream`, @sentry/server-utils/integrations/vercel-ai/vercel-ai-dc-subscriber.js:339). O `pipeThrough` trava o `ReadableStream` original; a partir do `ai` 7.0.168 o SDK publica uma CÓPIA (`redactTelemetryCredentials`) que compartilha o mesmo stream, então o laço de ferramentas volta ao original já travado (getsentry/sentry-javascript#26403, vercel/ai#24970). Sem tools não há segunda volta — por isso só a assinatura caía; - e isso atingia toda instalação porque `resolveSentryDsn` (lib/sentry/dsn.ts:19) mandava o vazio para o DSN da comunidade, então o `Sentry.init` rodava por padrão no app (sentry.server.config.ts:12), no edge (sentry.edge.config.ts:10), no worker (workers/agent-worker/main.ts:48) e no navegador. Conserto: - DSN vazio (ou ausente) = telemetria DESLIGADA: sai o fallback para o DSN da comunidade. O aceite virou token explícito (`SENTRY_DSN=comunidade`), que o install.sh grava no lugar do vazio — consentimento registrado, sem a chave do ingest no `.env` do cliente; - sem DSN, nenhum `Sentry.init` roda (nem cliente é criado, nem integração é instalada); - com DSN, `integrations: integracoesDoServidor` tira a integração `VercelAI` dos três inits de servidor. Tradeoff declarado em `lib/sentry/dsn.ts`: quem aponta para o próprio Sentry perde spans de IA, mantém a captura de erro (e a alternativa — não iniciar Sentry no worker — apagaria o erro de todos os provedores, porque o processo é o mesmo). Não muda versão do `ai` nem do SDK do Sentry: a correção do vercel/ai#25135 só chega no 7.0.174. Testes: tests/unit/sentry-e-assinatura-do-chatgpt.test.ts (quatro casos, com controle negativo do dublê), contrato do `SENTRY_DSN` vazio atualizado em tests/unit/sentry-comunidade-so-erro.test.ts, e o cenário de aceite do install.sh em hostgator-setup-kit/test-validators.sh.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Credential redaction created result copies that shared the original stream. When Sentry or another telemetry integration wrapped that stream, core retained the locked original and failed with
ReadableStream is locked.Fixes #24970
Summary
Forward stream replacements from redacted copies to the original result while preserving credential redaction. Add regression coverage for multiple subscribers and nested integrations, plus a patch changeset.
Validation: all 96 telemetry tests pass in both Node and Edge; full workspace type checking, lint, and formatting pass.
End-to-End Verification
Verified by running the Azure Responses reproduction against locally built packages before and after the fix.
Reproduction, commands, and results
Requires Node.js 22.13+ and installed workspace dependencies (
pnpm install --frozen-lockfile). Uses fake SSE responses through the actual Azure provider; no API credentials or network access are needed to run the reproduction.Save the script below as
/tmp/ai-sdk-24970.mjs, then run these commands from each checkout. The workspace links inexamples/ai-functionsresolve the local package builds:Before: Tools plus a wrapping subscriber produced empty text and
Invalid state: The ReadableStream is locked. The other three combinations returned"Hello world".After: All four combinations returned
"Hello world"without errors.This verifies the provider flow with simulated Azure responses, rather than a live Azure service or installed Sentry/Datadog integration.