Skip to content

Commit

Permalink
fix(nextjs): Widen removal of 404 transactions (#13628)
Browse files Browse the repository at this point in the history
On app router, transactions like `GET /404` get created that we don't
like.
  • Loading branch information
lforst authored Sep 10, 2024
1 parent 4c6dd80 commit 017e8f9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';

test('should create a transaction for a CJS pages router API endpoint', async ({ page }) => {
let received404Transaction = false;
waitForTransaction('nextjs-13', async transactionEvent => {
return transactionEvent.transaction === 'GET /404' || transactionEvent.transaction === 'GET /_not-found';
}).then(() => {
received404Transaction = true;
});

await page.goto('/page-that-doesnt-exist');

await new Promise<void>((resolve, reject) => {
setTimeout(() => {
if (received404Transaction) {
reject(new Error('received 404 transaction'));
} else {
resolve();
}
}, 5_000);
});
});
10 changes: 8 additions & 2 deletions packages/nextjs/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,14 @@ export function init(options: NodeOptions): NodeClient | undefined {
return null;
}

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

Expand Down

0 comments on commit 017e8f9

Please sign in to comment.