Skip to content

Commit 3890823

Browse files
committed
ref: remove the middleware, config must be statically analyzable
1 parent 1a231a4 commit 3890823

File tree

4 files changed

+7
-325
lines changed

4 files changed

+7
-325
lines changed

packages/nextjs/src/common/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ export { wrapPageComponentWithSentry } from './pages-router-instrumentation/wrap
1212
export { wrapGenerationFunctionWithSentry } from './wrapGenerationFunctionWithSentry';
1313
export { withServerActionInstrumentation } from './withServerActionInstrumentation';
1414
export { captureRequestError } from './captureRequestError';
15-
export { withSentryMiddlewareConfig, withSentryProxyConfig } from './withSentryMiddlewareConfig';

packages/nextjs/src/common/withSentryMiddlewareConfig.ts

Lines changed: 0 additions & 78 deletions
This file was deleted.

packages/nextjs/src/config/withSentryConfig.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export function withSentryConfig<C>(nextConfig?: C, sentryBuildOptions: SentryBu
9393

9494
/**
9595
* Checks if the user has a middleware/proxy file with a matcher that might exclude the tunnel route.
96-
* Warns the user if they have a matcher but are not using withSentryMiddlewareConfig or withSentryProxyConfig.
96+
* Warns the user if their matcher might interfere with the tunnel route.
9797
*/
9898
function checkMiddlewareMatcherForTunnelRoute(tunnelPath: string): void {
9999
if (showedMiddlewareMatcherWarning) {
@@ -108,29 +108,20 @@ function checkMiddlewareMatcherForTunnelRoute(tunnelPath: string): void {
108108
return;
109109
}
110110

111-
// Check if they're already using Sentry middleware/proxy config helpers
112-
if (
113-
middlewareFile.contents.includes('withSentryMiddlewareConfig') ||
114-
middlewareFile.contents.includes('withSentryProxyConfig')
115-
) {
116-
return;
117-
}
118-
119111
// Look for config.matcher export
120112
const isProxy = middlewareFile.path.includes('proxy');
121113
const hasConfigMatcher = /export\s+const\s+config\s*=\s*{[^}]*matcher\s*:/s.test(middlewareFile.contents);
122114

123115
if (hasConfigMatcher) {
124-
const helperName = isProxy ? 'withSentryProxyConfig' : 'withSentryMiddlewareConfig';
125116
// eslint-disable-next-line no-console
126117
console.warn(
127118
`[@sentry/nextjs] WARNING: You have a ${isProxy ? 'proxy' : 'middleware'} file (${path.basename(middlewareFile.path)}) with a \`config.matcher\`. ` +
128-
`If your matcher does not include the Sentry tunnel route (${tunnelPath}), tunnel requests may be blocked. ` +
129-
`To ensure your matcher doesn't interfere with Sentry event delivery, wrap your config with \`${helperName}\`:\n\n` +
130-
` import { ${helperName} } from '@sentry/nextjs';\n` +
131-
` export const config = ${helperName}({\n` +
132-
" matcher: ['/your/routes'],\n" +
133-
' });\n',
119+
`If your matcher runs on the Sentry tunnel route (${tunnelPath}), it may interfere with event delivery. ` +
120+
'Please ensure your matcher excludes the tunnel route. For example:\n\n' +
121+
' export const config = {\n' +
122+
' // Use a negative lookahead to exclude the Sentry tunnel route\n' +
123+
` matcher: '/((?!${tunnelPath.replace(/^\//, '')}|_next/static|_next/image|favicon.ico).*)',\n` +
124+
' };\n',
134125
);
135126
showedMiddlewareMatcherWarning = true;
136127
}

packages/nextjs/test/common/withSentryMiddlewareConfig.test.ts

Lines changed: 0 additions & 230 deletions
This file was deleted.

0 commit comments

Comments
 (0)