Skip to content

Commit 017e8f9

Browse files
authored
fix(nextjs): Widen removal of 404 transactions (#13628)
On app router, transactions like `GET /404` get created that we don't like.
1 parent 4c6dd80 commit 017e8f9

File tree

2 files changed

+31
-2
lines changed
  • dev-packages/e2e-tests/test-applications/nextjs-13/tests/server
  • packages/nextjs/src/server

2 files changed

+31
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { test } from '@playwright/test';
2+
import { waitForTransaction } from '@sentry-internal/test-utils';
3+
4+
test('should create a transaction for a CJS pages router API endpoint', async ({ page }) => {
5+
let received404Transaction = false;
6+
waitForTransaction('nextjs-13', async transactionEvent => {
7+
return transactionEvent.transaction === 'GET /404' || transactionEvent.transaction === 'GET /_not-found';
8+
}).then(() => {
9+
received404Transaction = true;
10+
});
11+
12+
await page.goto('/page-that-doesnt-exist');
13+
14+
await new Promise<void>((resolve, reject) => {
15+
setTimeout(() => {
16+
if (received404Transaction) {
17+
reject(new Error('received 404 transaction'));
18+
} else {
19+
resolve();
20+
}
21+
}, 5_000);
22+
});
23+
});

packages/nextjs/src/server/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,14 @@ export function init(options: NodeOptions): NodeClient | undefined {
219219
return null;
220220
}
221221

222-
// Filter out /404 transactions for pages-router which seem to be created excessively
223-
if (event.transaction === '/404') {
222+
// Filter out /404 transactions which seem to be created excessively
223+
if (
224+
// Pages router
225+
event.transaction === '/404' ||
226+
// App router (could be "GET /404", "POST /404", ...)
227+
event.transaction?.match(/^(GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH) \/404$/) ||
228+
event.transaction === 'GET /_not-found'
229+
) {
224230
return null;
225231
}
226232

0 commit comments

Comments
 (0)