From 492d8a51da56b37cfbfe2f74cc7ead5339964dd7 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Tue, 1 Oct 2024 17:08:13 +0100 Subject: [PATCH 1/2] Remove Sentry from direct import in instrumentation file --- apps/web/instrumentation.ts | 12 +++--------- apps/web/sentry.edge.config.ts | 5 +++++ apps/web/sentry.server.config.ts | 5 +++++ 3 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 apps/web/sentry.edge.config.ts create mode 100644 apps/web/sentry.server.config.ts diff --git a/apps/web/instrumentation.ts b/apps/web/instrumentation.ts index 79040c9dbb19cb..f8a929ba429a4d 100644 --- a/apps/web/instrumentation.ts +++ b/apps/web/instrumentation.ts @@ -1,15 +1,9 @@ -import * as Sentry from "@sentry/nextjs"; - -export function register() { +export async function register() { if (process.env.NEXT_RUNTIME === "nodejs") { - Sentry.init({ - dsn: process.env.NEXT_PUBLIC_SENTRY_DSN, - }); + await import("./sentry.server.config"); } if (process.env.NEXT_RUNTIME === "edge") { - Sentry.init({ - dsn: process.env.NEXT_PUBLIC_SENTRY_DSN, - }); + await import("./sentry.edge.config"); } } diff --git a/apps/web/sentry.edge.config.ts b/apps/web/sentry.edge.config.ts new file mode 100644 index 00000000000000..842f09fccc2c06 --- /dev/null +++ b/apps/web/sentry.edge.config.ts @@ -0,0 +1,5 @@ +import * as Sentry from "@sentry/nextjs"; + +Sentry.init({ + dsn: process.env.NEXT_PUBLIC_SENTRY_DSN, +}); diff --git a/apps/web/sentry.server.config.ts b/apps/web/sentry.server.config.ts new file mode 100644 index 00000000000000..842f09fccc2c06 --- /dev/null +++ b/apps/web/sentry.server.config.ts @@ -0,0 +1,5 @@ +import * as Sentry from "@sentry/nextjs"; + +Sentry.init({ + dsn: process.env.NEXT_PUBLIC_SENTRY_DSN, +}); From 0ca2d0b6fd5f17ee20bcc2c788a99cb88c24a034 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Tue, 1 Oct 2024 17:12:43 +0100 Subject: [PATCH 2/2] chore: Exclude Sentry configs when not needed --- apps/web/instrumentation.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/web/instrumentation.ts b/apps/web/instrumentation.ts index f8a929ba429a4d..b0bba123cc719d 100644 --- a/apps/web/instrumentation.ts +++ b/apps/web/instrumentation.ts @@ -1,9 +1,9 @@ export async function register() { - if (process.env.NEXT_RUNTIME === "nodejs") { + if (process.env.NEXT_PUBLIC_SENTRY_DSN && process.env.NEXT_RUNTIME === "nodejs") { await import("./sentry.server.config"); } - if (process.env.NEXT_RUNTIME === "edge") { + if (process.env.NEXT_PUBLIC_SENTRY_DSN && process.env.NEXT_RUNTIME === "edge") { await import("./sentry.edge.config"); } }