fix(ui): skip Sentry initialization when DSN is not configured (#9368)

This commit is contained in:
Alan Buscaglia
2025-12-01 18:05:45 +01:00
committed by GitHub
parent 56ea498cca
commit dda0a2567d
4 changed files with 231 additions and 206 deletions

View File

@@ -11,6 +11,10 @@
import { browserTracingIntegration } from "@sentry/browser";
import * as Sentry from "@sentry/nextjs";
const SENTRY_DSN = process.env.NEXT_PUBLIC_SENTRY_DSN;
// Only initialize Sentry if DSN is configured
if (SENTRY_DSN) {
const isDevelopment = process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "local";
/**
@@ -23,7 +27,7 @@ const isDevelopment = process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "local";
*/
Sentry.init({
// 📍 DSN - Data Source Name (identifies your Sentry project)
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
dsn: SENTRY_DSN,
// 🌍 Environment - Separate dev errors from production
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT || "local",
@@ -113,3 +117,4 @@ if (isDevelopment) {
id: "dev-user",
});
}
}

View File

@@ -16,7 +16,14 @@
import * as Sentry from "@sentry/nextjs";
const SENTRY_DSN = process.env.SENTRY_DSN;
export async function register() {
// Skip Sentry initialization if DSN is not configured
if (!SENTRY_DSN) {
return;
}
// The Sentry SDK automatically loads the appropriate config based on runtime
if (process.env.NEXT_RUNTIME === "nodejs") {
await import("./sentry/sentry.server.config");
@@ -27,4 +34,7 @@ export async function register() {
}
}
export const onRequestError = Sentry.captureRequestError;
// Only capture request errors if Sentry is configured
export const onRequestError = SENTRY_DSN
? Sentry.captureRequestError
: undefined;

View File

@@ -1,5 +1,9 @@
import * as Sentry from "@sentry/nextjs";
const SENTRY_DSN = process.env.SENTRY_DSN;
// Only initialize Sentry if DSN is configured
if (SENTRY_DSN) {
const isProduction = process.env.SENTRY_ENVIRONMENT === "pro";
/**
@@ -13,7 +17,7 @@ const isProduction = process.env.SENTRY_ENVIRONMENT === "pro";
*/
Sentry.init({
// 📍 DSN - Data Source Name (identifies your Sentry project)
dsn: process.env.SENTRY_DSN,
dsn: SENTRY_DSN,
// 🌍 Environment configuration
environment: process.env.SENTRY_ENVIRONMENT || "local",
@@ -62,3 +66,4 @@ Sentry.init({
return event;
},
});
}

View File

@@ -1,5 +1,9 @@
import * as Sentry from "@sentry/nextjs";
const SENTRY_DSN = process.env.SENTRY_DSN;
// Only initialize Sentry if DSN is configured
if (SENTRY_DSN) {
const isProduction = process.env.SENTRY_ENVIRONMENT === "pro";
/**
@@ -12,7 +16,7 @@ const isProduction = process.env.SENTRY_ENVIRONMENT === "pro";
*/
Sentry.init({
// 📍 DSN - Data Source Name (identifies your Sentry project)
dsn: process.env.SENTRY_DSN,
dsn: SENTRY_DSN,
// 🌍 Environment configuration
environment: process.env.SENTRY_ENVIRONMENT || "local",
@@ -78,3 +82,4 @@ Sentry.init({
return event;
},
});
}