Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/nestjs
SDK Version
latest 10+
Framework Version
No response
Link to Sentry event
No response
Reproduction Example/SDK Setup
No response
Steps to Reproduce
Importing instrument.ts breaks OpenAI streaming capabilities (only last full response is coming through).
I am using OpenAI with Langchain wrapper if it matters.
I've lost few hours until I discovered that this is Sentry causing my streaming not to work.
import*asSentryfrom'@sentry/nestjs';import{isSentryTracingEnabled}from'./common/utils/sentry-tracing';// DSN is safe to hardcode - it only allows sending data TO Sentry// Can be overridden via SENTRY_DSN env var for per-environment routingconstDEFAULT_DSN=
'xxx;
constdsn=process.env.SENTRY_DSN??DEFAULT_DSN;// Use SENTRY_ENVIRONMENT if set, otherwise infer from NODE_ENVconstenvironment=process.env.SENTRY_ENVIRONMENT??(process.env.NODE_ENV==='production' ? 'production' : 'local');constrelease=process.env.RELEASE_TAG??'local';consttracingEnabled=isSentryTracingEnabled();constnormalizedEnvironment=environment.toLowerCase();constisLocalEnvironment=normalizedEnvironment==='local';constisProductionEnvironment=normalizedEnvironment==='production';typeLogLevel='info'|'warn'|'error'|'fatal';constlogLevels: LogLevel[]=isProductionEnvironment
? ['warn','error','fatal']
: ['info','warn','error','fatal'];// Only initialize Sentry if DSN is provided and not in local developmentif(dsn){// && environment !== 'local') {Sentry.init({
dsn,
environment,
release,sendDefaultPii: true,tracesSampleRate:
tracingEnabled&&environment==='production'
? 1.0
: tracingEnabled
? 1.0
: 0,// Enable logs to be sent to SentryenableLogs: !isLocalEnvironment,integrations: (integrations)=>{constfiltered=integrations.filter((integration)=>{constname=integration?.name??'';constnormalized=name.toLowerCase();// Filter out Redis (noisy) and OpenAI (breaks streaming)return!(normalized.includes('redis')||normalized.includes('ioredis')||normalized.includes('openai'));});return[// Automatically capture Pino logsSentry.pinoIntegration({log: {levels: logLevels,},error: {levels: ['error','fatal'],},}),
...filtered,];},// Scrub sensitive data from events before sending to SentrybeforeSend(event){// Remove sensitive headers (Pino redaction doesn't cover Sentry's request context)if(event.request?.headers){constsensitiveHeaders=['authorization','cookie','x-api-key','x-auth-token','x-access-token',];for(constheaderofsensitiveHeaders){if(event.request.headers[header]){event.request.headers[header]='[REDACTED]';}}}// Remove sensitive user data if presentif(event.user){// Keep user.id but remove other PIIconstuserId=event.user.id;event.user=userId ? {id: userId} : undefined;}// Remove sensitive tags/contextif(event.tags){deleteevent.tags.password;deleteevent.tags.token;deleteevent.tags.secret;}// Scrub sensitive data from extra contextif(event.contexts){constsensitiveKeys=['password','token','secret','apiKey','auth'];for(constkeyofsensitiveKeys){if(keyinevent.contexts){deleteevent.contexts[keyaskeyoftypeofevent.contexts];}}}returnevent;},// Filter logs: keep info+ and drop trace/debug noisebeforeSendLog(log){if(isLocalEnvironment){returnnull;}if(log.level==='trace'||log.level==='debug'){returnnull;}if(isProductionEnvironment&&log.level==='info'){returnnull;}returnlog;},});}Expected Result
OpenAI / Langchain streaming to work.
Actual Result
Streaming is broken.
No matter if I added filtering of integrations, process.env.OTEL_NODE_DISABLED_INSTRUMENTATIONS = 'openai'; as per JS-770 and many more - only completely removing instrument.ts import allows streaming to work.
Additional Context
I can live without openai instrumentation working until this is fixed, but please give me/us some workaround.
Priority
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/nestjs
SDK Version
latest 10+
Framework Version
No response
Link to Sentry event
No response
Reproduction Example/SDK Setup
No response
Steps to Reproduce
Importing instrument.ts breaks OpenAI streaming capabilities (only last full response is coming through).
I am using OpenAI with Langchain wrapper if it matters.
I've lost few hours until I discovered that this is Sentry causing my streaming not to work.
Expected Result
OpenAI / Langchain streaming to work.
Actual Result
Streaming is broken.
No matter if I added filtering of integrations,
process.env.OTEL_NODE_DISABLED_INSTRUMENTATIONS = 'openai';as per JS-770 and many more - only completely removing instrument.ts import allows streaming to work.Additional Context
I can live without openai instrumentation working until this is fixed, but please give me/us some workaround.
Priority
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding
+1orme too, to help us triage it.