From 51fe224ee33e52f5086f72bae9a64011f6e8274f Mon Sep 17 00:00:00 2001 From: Stef Lewandowski Date: Thu, 29 Aug 2024 16:18:47 +0100 Subject: [PATCH] Move instrumentation into src directory. Add webpack config in Next config to ignore the dependency warning --- apps/nextjs/instrumentation.ts | 5 ----- apps/nextjs/next.config.js | 17 ++++++++++++++++- apps/nextjs/src/instrumentation.ts | 12 ++++++++---- apps/nextjs/{ => src}/instrumentation/tracer.ts | 0 4 files changed, 24 insertions(+), 10 deletions(-) delete mode 100644 apps/nextjs/instrumentation.ts rename apps/nextjs/{ => src}/instrumentation/tracer.ts (100%) diff --git a/apps/nextjs/instrumentation.ts b/apps/nextjs/instrumentation.ts deleted file mode 100644 index ec316bbdb..000000000 --- a/apps/nextjs/instrumentation.ts +++ /dev/null @@ -1,5 +0,0 @@ -export async function register() { - if (process.env.NEXT_RUNTIME === "nodejs") { - await import("./instrumentation/tracer"); - } -} diff --git a/apps/nextjs/next.config.js b/apps/nextjs/next.config.js index 16317f2c4..d966e5b36 100644 --- a/apps/nextjs/next.config.js +++ b/apps/nextjs/next.config.js @@ -101,7 +101,7 @@ const getConfig = async (phase) => { BRANCH: process.env.BRANCH, DEPLOY_CONTEXT: process.env.CONTEXT, }, - webpack: (config, { dev }) => { + webpack: (config, { dev, isServer }) => { if (!dev && isProductionBuild && isNextjsProductionBuildPhase) { config.devtool = "source-map"; config.plugins.push( @@ -114,6 +114,21 @@ const getConfig = async (phase) => { ); } + // dd-trace outputs the following warning in the browser console: + // Critical dependency: the request of a dependency is an expression + // This is due to the use of `require` in the dd-trace codebase. + // This can be safely ignored. + // Start of dd-trace fix + if (!isServer) { + config.resolve.fallback = { + ...config.resolve.fallback, + "dd-trace": false, + }; + } + config.module = config.module || {}; + config.module.exprContextCritical = false; + // End of dd-trace fix + return config; }, }; diff --git a/apps/nextjs/src/instrumentation.ts b/apps/nextjs/src/instrumentation.ts index 6a02852d9..32a937a7a 100644 --- a/apps/nextjs/src/instrumentation.ts +++ b/apps/nextjs/src/instrumentation.ts @@ -1,9 +1,13 @@ export async function register() { - if (process.env.NEXT_RUNTIME === 'nodejs') { - await import('../sentry.server.config'); + if (process.env.NEXT_RUNTIME === "nodejs") { + await import("../sentry.server.config"); } - if (process.env.NEXT_RUNTIME === 'edge') { - await import('../sentry.edge.config'); + if (process.env.NEXT_RUNTIME === "edge") { + await import("../sentry.edge.config"); + } + + if (process.env.NEXT_RUNTIME === "nodejs") { + await import("./instrumentation/tracer"); } } diff --git a/apps/nextjs/instrumentation/tracer.ts b/apps/nextjs/src/instrumentation/tracer.ts similarity index 100% rename from apps/nextjs/instrumentation/tracer.ts rename to apps/nextjs/src/instrumentation/tracer.ts