From f1e8e8f30a963f07c6702d2ed8cf4852ff98cfe5 Mon Sep 17 00:00:00 2001 From: Tofik Hasanov Date: Sun, 14 Jun 2026 21:59:31 -0400 Subject: [PATCH] fix(sentry): only report errors from the production environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sentry was initialized unconditionally in app and portal across the server, edge, and client runtimes. The DSN has a hardcoded fallback and there was no environment gating, so every Vercel deployment — production AND every preview/branch deploy — reported into the same Sentry project, creating noise. Gate ingestion on the Vercel environment via the `enabled` option: - server/edge configs: VERCEL_ENV === 'production' - client configs: NEXT_PUBLIC_VERCEL_ENV === 'production' (inlined at build time) `enabled: false` makes the SDK a silent no-op (it never throws); a missing var resolves to false, so the worst case is Sentry being off in a non-prod env — never a runtime error or a broken build. Co-Authored-By: Claude Opus 4.8 (1M context) --- apps/app/sentry.edge.config.ts | 5 +++++ apps/app/sentry.server.config.ts | 5 +++++ apps/app/src/instrumentation-client.ts | 5 +++++ apps/portal/sentry.edge.config.ts | 5 +++++ apps/portal/sentry.server.config.ts | 5 +++++ apps/portal/src/instrumentation-client.ts | 5 +++++ 6 files changed, 30 insertions(+) diff --git a/apps/app/sentry.edge.config.ts b/apps/app/sentry.edge.config.ts index e996f794ca..991de81ebd 100644 --- a/apps/app/sentry.edge.config.ts +++ b/apps/app/sentry.edge.config.ts @@ -10,6 +10,11 @@ Sentry.init({ process.env.SENTRY_DSN ?? 'https://331f1c3d4b08e9352dd1a2621e1ae845@o4509214247813120.ingest.us.sentry.io/4511304630927360', + // Only report from production. On Vercel, VERCEL_ENV is 'production' | 'preview' + // | 'development'; on any non-production deployment (or if the var is missing) + // Sentry stays disabled — a no-op, never an error — to avoid noise and quota burn. + enabled: process.env.VERCEL_ENV === 'production', + tracesSampleRate: process.env.NODE_ENV === 'development' ? 1.0 : 0.1, enableLogs: true, diff --git a/apps/app/sentry.server.config.ts b/apps/app/sentry.server.config.ts index 6d9894dbca..f2d422f573 100644 --- a/apps/app/sentry.server.config.ts +++ b/apps/app/sentry.server.config.ts @@ -9,6 +9,11 @@ Sentry.init({ process.env.SENTRY_DSN ?? 'https://331f1c3d4b08e9352dd1a2621e1ae845@o4509214247813120.ingest.us.sentry.io/4511304630927360', + // Only report from production. On Vercel, VERCEL_ENV is 'production' | 'preview' + // | 'development'; on any non-production deployment (or if the var is missing) + // Sentry stays disabled — a no-op, never an error — to avoid noise and quota burn. + enabled: process.env.VERCEL_ENV === 'production', + tracesSampleRate: process.env.NODE_ENV === 'development' ? 1.0 : 0.1, // Off in production: local variables in stack frames can expose request-scoped diff --git a/apps/app/src/instrumentation-client.ts b/apps/app/src/instrumentation-client.ts index cd27359c8f..9f60393d4b 100644 --- a/apps/app/src/instrumentation-client.ts +++ b/apps/app/src/instrumentation-client.ts @@ -14,6 +14,11 @@ Sentry.init({ process.env.NEXT_PUBLIC_SENTRY_DSN ?? 'https://331f1c3d4b08e9352dd1a2621e1ae845@o4509214247813120.ingest.us.sentry.io/4511304630927360', + // Only report from production. NEXT_PUBLIC_VERCEL_ENV is inlined at build time + // per Vercel deployment; preview/dev builds (or a missing var) keep Sentry + // disabled — a no-op, never an error — to avoid noise and quota burn. + enabled: process.env.NEXT_PUBLIC_VERCEL_ENV === 'production', + integrations: [ // Add `data-sentry-mask` (or `.sentry-mask`) to any element rendering // customer-confidential data; `data-sentry-block` to drop whole sections. diff --git a/apps/portal/sentry.edge.config.ts b/apps/portal/sentry.edge.config.ts index e996f794ca..991de81ebd 100644 --- a/apps/portal/sentry.edge.config.ts +++ b/apps/portal/sentry.edge.config.ts @@ -10,6 +10,11 @@ Sentry.init({ process.env.SENTRY_DSN ?? 'https://331f1c3d4b08e9352dd1a2621e1ae845@o4509214247813120.ingest.us.sentry.io/4511304630927360', + // Only report from production. On Vercel, VERCEL_ENV is 'production' | 'preview' + // | 'development'; on any non-production deployment (or if the var is missing) + // Sentry stays disabled — a no-op, never an error — to avoid noise and quota burn. + enabled: process.env.VERCEL_ENV === 'production', + tracesSampleRate: process.env.NODE_ENV === 'development' ? 1.0 : 0.1, enableLogs: true, diff --git a/apps/portal/sentry.server.config.ts b/apps/portal/sentry.server.config.ts index 6d9894dbca..f2d422f573 100644 --- a/apps/portal/sentry.server.config.ts +++ b/apps/portal/sentry.server.config.ts @@ -9,6 +9,11 @@ Sentry.init({ process.env.SENTRY_DSN ?? 'https://331f1c3d4b08e9352dd1a2621e1ae845@o4509214247813120.ingest.us.sentry.io/4511304630927360', + // Only report from production. On Vercel, VERCEL_ENV is 'production' | 'preview' + // | 'development'; on any non-production deployment (or if the var is missing) + // Sentry stays disabled — a no-op, never an error — to avoid noise and quota burn. + enabled: process.env.VERCEL_ENV === 'production', + tracesSampleRate: process.env.NODE_ENV === 'development' ? 1.0 : 0.1, // Off in production: local variables in stack frames can expose request-scoped diff --git a/apps/portal/src/instrumentation-client.ts b/apps/portal/src/instrumentation-client.ts index c265121a9b..06a44c55fd 100644 --- a/apps/portal/src/instrumentation-client.ts +++ b/apps/portal/src/instrumentation-client.ts @@ -9,6 +9,11 @@ Sentry.init({ process.env.NEXT_PUBLIC_SENTRY_DSN ?? 'https://331f1c3d4b08e9352dd1a2621e1ae845@o4509214247813120.ingest.us.sentry.io/4511304630927360', + // Only report from production. NEXT_PUBLIC_VERCEL_ENV is inlined at build time + // per Vercel deployment; preview/dev builds (or a missing var) keep Sentry + // disabled — a no-op, never an error — to avoid noise and quota burn. + enabled: process.env.NEXT_PUBLIC_VERCEL_ENV === 'production', + integrations: [ // Add `data-sentry-mask` (or `.sentry-mask`) to any element rendering // customer-confidential data; `data-sentry-block` to drop whole sections.