Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading