diff --git a/packages/nextjs/test/integration/next.config.js b/packages/nextjs/test/integration/next.config.js index 8992ed63d0e5..3f209311c332 100644 --- a/packages/nextjs/test/integration/next.config.js +++ b/packages/nextjs/test/integration/next.config.js @@ -9,6 +9,7 @@ const moduleExports = { // Suppress the warning message from `handleSourcemapHidingOptionWarning` in `src/config/webpack.ts` // TODO (v8): This can come out in v8, because this option will get a default value hideSourceMaps: false, + excludeServerRoutes: ['/api/excludedEndpoints/excludedWithString', /\/api\/excludedEndpoints\/excludedWithRegExp/], }, }; const SentryWebpackPluginOptions = { diff --git a/packages/nextjs/test/integration/next10.config.template b/packages/nextjs/test/integration/next10.config.template index 31c332cd25cd..6e55fa099a22 100644 --- a/packages/nextjs/test/integration/next10.config.template +++ b/packages/nextjs/test/integration/next10.config.template @@ -10,6 +10,10 @@ const moduleExports = { // Suppress the warning message from `handleSourcemapHidingOptionWarning` in `src/config/webpack.ts` // TODO (v8): This can come out in v8, because this option will get a default value hideSourceMaps: false, + excludeServerRoutes: [ + '/api/excludedEndpoints/excludedWithString', + /\/api\/excludedEndpoints\/excludedWithRegExp/, + ], }, }; diff --git a/packages/nextjs/test/integration/next11.config.template b/packages/nextjs/test/integration/next11.config.template index 6a7e849067b1..28aaba18639a 100644 --- a/packages/nextjs/test/integration/next11.config.template +++ b/packages/nextjs/test/integration/next11.config.template @@ -11,6 +11,10 @@ const moduleExports = { // Suppress the warning message from `handleSourcemapHidingOptionWarning` in `src/config/webpack.ts` // TODO (v8): This can come out in v8, because this option will get a default value hideSourceMaps: false, + excludeServerRoutes: [ + '/api/excludedEndpoints/excludedWithString', + /\/api\/excludedEndpoints\/excludedWithRegExp/, + ], }, }; diff --git a/packages/nextjs/test/integration/pages/api/excludedEndpoints/excludedWithRegExp.tsx b/packages/nextjs/test/integration/pages/api/excludedEndpoints/excludedWithRegExp.tsx new file mode 100644 index 000000000000..49099819c843 --- /dev/null +++ b/packages/nextjs/test/integration/pages/api/excludedEndpoints/excludedWithRegExp.tsx @@ -0,0 +1,6 @@ +// This file will test the `excludeServerRoutes` option when a route is provided as a RegExp. +const handler = async (): Promise => { + throw new Error('API Error'); +}; + +export default handler; diff --git a/packages/nextjs/test/integration/pages/api/excludedEndpoints/excludedWithString.tsx b/packages/nextjs/test/integration/pages/api/excludedEndpoints/excludedWithString.tsx new file mode 100644 index 000000000000..9e6bde70c490 --- /dev/null +++ b/packages/nextjs/test/integration/pages/api/excludedEndpoints/excludedWithString.tsx @@ -0,0 +1,6 @@ +// This file will test the `excludeServerRoutes` option when a route is provided as a string. +const handler = async (): Promise => { + throw new Error('API Error'); +}; + +export default handler; diff --git a/packages/nextjs/test/integration/test/server/excludedApiEndpoints.js b/packages/nextjs/test/integration/test/server/excludedApiEndpoints.js new file mode 100644 index 000000000000..db49bbbc57cf --- /dev/null +++ b/packages/nextjs/test/integration/test/server/excludedApiEndpoints.js @@ -0,0 +1,67 @@ +const assert = require('assert'); + +const { sleep } = require('../utils/common'); +const { getAsync, interceptEventRequest, interceptTracingRequest } = require('../utils/server'); + +module.exports = async ({ url: urlBase, argv }) => { + const regExpUrl = `${urlBase}/api/excludedEndpoints/excludedWithRegExp`; + const stringUrl = `${urlBase}/api/excludedEndpoints/excludedWithString`; + + const capturedRegExpErrorRequest = interceptEventRequest( + { + exception: { + values: [ + { + type: 'Error', + value: 'API Error', + }, + ], + }, + tags: { + runtime: 'node', + }, + request: { + url: regExpUrl, + method: 'GET', + }, + transaction: 'GET /api/excludedEndpoints/excludedWithRegExp', + }, + argv, + 'excluded API endpoint via RegExp', + ); + + const capturedStringErrorRequest = interceptEventRequest( + { + exception: { + values: [ + { + type: 'Error', + value: 'API Error', + }, + ], + }, + tags: { + runtime: 'node', + }, + request: { + url: regExpUrl, + method: 'GET', + }, + transaction: 'GET /api/excludedEndpoints/excludedWithString', + }, + argv, + 'excluded API endpoint via String', + ); + + await Promise.all([getAsync(regExpUrl), getAsync(stringUrl)]); + await sleep(250); + + assert.ok( + !capturedRegExpErrorRequest.isDone(), + 'Did intercept error request even though route should be excluded (RegExp)', + ); + assert.ok( + !capturedStringErrorRequest.isDone(), + 'Did intercept error request even though route should be excluded (String)', + ); +};