Skip to content

Commit 1f398ae

Browse files
author
Luca Forstner
committed
Add escape hatch
1 parent c588f78 commit 1f398ae

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

packages/nextjs/src/config/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,14 @@ export type UserSentryOptions = {
106106
*/
107107
autoInstrumentMiddleware?: boolean;
108108

109+
/**
110+
* Automatically instrument components in the `app` directory with error monitoring. Defaults to `true`.
111+
*/
112+
autoInstrumentAppDirectory?: boolean;
113+
109114
/**
110115
* Exclude certain serverside API routes or pages from being instrumented with Sentry. This option takes an array of
111-
* strings or regular expressions.
116+
* strings or regular expressions. This options also affects pages in the `app` directory.
112117
*
113118
* NOTE: Pages should be specified as routes (`/animals` or `/api/animals/[animalType]/habitat`), not filepaths
114119
* (`pages/animals/index.js` or `.\src\pages\api\animals\[animalType]\habitat.tsx`), and strings must be be a full,

packages/nextjs/src/config/webpack.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,19 @@ export function constructWebpackConfigFunction(
113113
excludeServerRoutes: userSentryOptions.excludeServerRoutes,
114114
};
115115

116-
if (isServer && userSentryOptions.autoInstrumentServerFunctions !== false) {
117-
const normalizeLoaderResourcePath = (resourcePath: string): string => {
118-
// `resourcePath` may be an absolute path or a path relative to the context of the webpack config
119-
let absoluteResourcePath: string;
120-
if (path.isAbsolute(resourcePath)) {
121-
absoluteResourcePath = resourcePath;
122-
} else {
123-
absoluteResourcePath = path.join(projectDir, resourcePath);
124-
}
116+
const normalizeLoaderResourcePath = (resourcePath: string): string => {
117+
// `resourcePath` may be an absolute path or a path relative to the context of the webpack config
118+
let absoluteResourcePath: string;
119+
if (path.isAbsolute(resourcePath)) {
120+
absoluteResourcePath = resourcePath;
121+
} else {
122+
absoluteResourcePath = path.join(projectDir, resourcePath);
123+
}
125124

126-
return path.normalize(absoluteResourcePath);
127-
};
125+
return path.normalize(absoluteResourcePath);
126+
};
128127

128+
if (isServer && userSentryOptions.autoInstrumentServerFunctions !== false) {
129129
// It is very important that we insert our loaders at the beginning of the array because we expect any sort of transformations/transpilations (e.g. TS -> JS) to already have happened.
130130

131131
// Wrap pages
@@ -187,7 +187,9 @@ export function constructWebpackConfigFunction(
187187
},
188188
],
189189
});
190+
}
190191

192+
if (userSentryOptions.autoInstrumentAppDirectory) {
191193
// Wrap page server components
192194
newConfig.module.rules.unshift({
193195
test: resourcePath => {

0 commit comments

Comments
 (0)