diff --git a/packages/nextjs/src/config/types.ts b/packages/nextjs/src/config/types.ts index 2a5ee51d9d57..ee7643ef491e 100644 --- a/packages/nextjs/src/config/types.ts +++ b/packages/nextjs/src/config/types.ts @@ -49,6 +49,10 @@ export type UserSentryOptions = { // uploaded. At the same time, we don't want to widen the scope if we don't have to, because we're guaranteed to end // up uploading too many files, which is why this defaults to `false`. widenClientFileUpload?: boolean; + + // Automatically wrap `getServerSideProps`, `getStaticProps`, and `getStaticPaths` in order to instrument them for + // tracing. + autoWrapDataFetchers?: boolean; }; export type NextConfigFunction = (phase: string, defaults: { defaultConfig: NextConfigObject }) => NextConfigObject; diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 9bd5dd3ae602..f1eabb351094 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -74,17 +74,20 @@ export function constructWebpackConfigFunction( }, ], }, - { - test: pageRegex, - use: [ - { - loader: path.resolve(__dirname, 'loaders/dataFetchersLoader.js'), - options: { projectDir }, - }, - ], - }, ], }; + + if (userSentryOptions.autoWrapDataFetchers) { + newConfig.module.rules.push({ + test: pageRegex, + use: [ + { + loader: path.resolve(__dirname, 'loaders/dataFetchersLoader.js'), + options: { projectDir }, + }, + ], + }); + } } // The SDK uses syntax (ES6 and ES6+ features like object spread) which isn't supported by older browsers. For users