@@ -15,6 +15,15 @@ const config: NextConfig = {
1515 // Transpile @primer /react so Next's webpack can process its CSS and other assets
1616 // This ensures CSS in node_modules/@primer /react is handled by the app's loaders.
1717 transpilePackages : [ '@primer/react' ] ,
18+ // Keep OTel packages out of the Next.js server bundle.
19+ // They must be loaded via native require() for auto-instrumentation to work.
20+ serverExternalPackages : [
21+ '@opentelemetry/api' ,
22+ '@opentelemetry/auto-instrumentations-node' ,
23+ '@opentelemetry/core' ,
24+ '@opentelemetry/exporter-trace-otlp-proto' ,
25+ '@opentelemetry/sdk-node' ,
26+ ] ,
1827 // speed up production `next build` by ignoring typechecking during that step of build.
1928 // type-checking still occurs in the Dockerfile build
2029 typescript : {
@@ -48,8 +57,15 @@ const config: NextConfig = {
4857 } )
4958 } ,
5059
51- webpack : ( webpackConfig ) => {
60+ webpack : ( webpackConfig , { isServer } ) => {
5261 webpackConfig . resolve . fallback = { fs : false , async_hooks : false }
62+ // OTel is server-only. Alias to empty stub in browser bundles.
63+ if ( ! isServer ) {
64+ webpackConfig . resolve . alias = {
65+ ...webpackConfig . resolve . alias ,
66+ '@/observability/lib/tracing' : path . resolve ( './src/observability/lib/tracing.browser.ts' ) ,
67+ }
68+ }
5369 return webpackConfig
5470 } ,
5571
@@ -71,6 +87,9 @@ const config: NextConfig = {
7187 '@/observability/logger/lib/logger-context' : {
7288 browser : './empty.ts' ,
7389 } ,
90+ '@/observability/lib/tracing' : {
91+ browser : './src/observability/lib/tracing.browser.ts' ,
92+ } ,
7493 } ,
7594 } ,
7695
0 commit comments