11/* eslint-disable complexity */
22/* eslint-disable max-lines */
33import { getSentryRelease } from '@sentry/node' ;
4- import { arrayify , dropUndefinedKeys , escapeStringForRegex , logger } from '@sentry/utils' ;
4+ import { arrayify , dropUndefinedKeys , escapeStringForRegex , logger , stringMatchesSomePattern } from '@sentry/utils' ;
55import { default as SentryWebpackPlugin } from '@sentry/webpack-plugin' ;
66import * as chalk from 'chalk' ;
77import * as fs from 'fs' ;
@@ -316,7 +316,7 @@ async function addSentryToEntryProperty(
316316
317317 // inject into all entry points which might contain user's code
318318 for ( const entryPointName in newEntryProperty ) {
319- if ( shouldAddSentryToEntryPoint ( entryPointName , runtime ) ) {
319+ if ( shouldAddSentryToEntryPoint ( entryPointName , runtime , userSentryOptions . excludeServerRoutes ?? [ ] ) ) {
320320 addFilesToExistingEntryPoint ( newEntryProperty , entryPointName , filesToInject ) ;
321321 } else {
322322 if (
@@ -448,9 +448,20 @@ function checkWebpackPluginOverrides(
448448 * @param excludeServerRoutes A list of excluded serverside entrypoints provided by the user
449449 * @returns `true` if sentry code should be injected, and `false` otherwise
450450 */
451- function shouldAddSentryToEntryPoint ( entryPointName : string , runtime : 'node' | 'browser' | 'edge' ) : boolean {
451+ function shouldAddSentryToEntryPoint (
452+ entryPointName : string ,
453+ runtime : 'node' | 'browser' | 'edge' ,
454+ excludeServerRoutes : Array < string | RegExp > ,
455+ ) : boolean {
452456 // On the server side, by default we inject the `Sentry.init()` code into every page (with a few exceptions).
453457 if ( runtime === 'node' ) {
458+ // User-specified pages to skip. (Note: For ease of use, `excludeServerRoutes` is specified in terms of routes,
459+ // which don't have the `pages` prefix.)
460+ const entryPointRoute = entryPointName . replace ( / ^ p a g e s / , '' ) ;
461+ if ( stringMatchesSomePattern ( entryPointRoute , excludeServerRoutes , true ) ) {
462+ return false ;
463+ }
464+
454465 // This expression will implicitly include `pages/_app` which is called for all serverside routes and pages
455466 // regardless whether or not the user has a`_app` file.
456467 return entryPointName . startsWith ( 'pages/' ) ;
@@ -460,6 +471,13 @@ function shouldAddSentryToEntryPoint(entryPointName: string, runtime: 'node' | '
460471 entryPointName === 'main-app' // entrypoint for `/app` pages
461472 ) ;
462473 } else {
474+ // User-specified pages to skip. (Note: For ease of use, `excludeServerRoutes` is specified in terms of routes,
475+ // which don't have the `pages` prefix.)
476+ const entryPointRoute = entryPointName . replace ( / ^ p a g e s / , '' ) ;
477+ if ( stringMatchesSomePattern ( entryPointRoute , excludeServerRoutes , true ) ) {
478+ return false ;
479+ }
480+
463481 return true ;
464482 }
465483}
0 commit comments