From 0d7f560c432b305d73084ea0343023baaac94bd6 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Tue, 1 Oct 2024 17:52:13 +0100 Subject: [PATCH] chore: improve instrumentation deps (#16899) * Remove Sentry from direct import in instrumentation file * chore: Exclude Sentry configs when not needed --- apps/web/instrumentation.ts | 16 +++++----------- apps/web/sentry.edge.config.ts | 5 +++++ apps/web/sentry.server.config.ts | 5 +++++ 3 files changed, 15 insertions(+), 11 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..b0bba123cc719d 100644 --- a/apps/web/instrumentation.ts +++ b/apps/web/instrumentation.ts @@ -1,15 +1,9 @@ -import * as Sentry from "@sentry/nextjs"; - -export function register() { - if (process.env.NEXT_RUNTIME === "nodejs") { - Sentry.init({ - dsn: process.env.NEXT_PUBLIC_SENTRY_DSN, - }); +export async function register() { + if (process.env.NEXT_PUBLIC_SENTRY_DSN && process.env.NEXT_RUNTIME === "nodejs") { + await import("./sentry.server.config"); } - if (process.env.NEXT_RUNTIME === "edge") { - Sentry.init({ - dsn: process.env.NEXT_PUBLIC_SENTRY_DSN, - }); + if (process.env.NEXT_PUBLIC_SENTRY_DSN && process.env.NEXT_RUNTIME === "edge") { + 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, +});