Skip to content

Commit 7e3b73a

Browse files
committed
add filter for 404 transactions
1 parent c29785b commit 7e3b73a

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

packages/nextjs/src/index.client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export function init(options: NextjsOptions): void {
3030
});
3131
configureScope(scope => {
3232
scope.setTag('runtime', 'browser');
33+
scope.addEventProcessor(event => (event.type === 'transaction' && event.transaction === '/404' ? null : event));
3334
});
3435
}
3536

packages/nextjs/src/index.server.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Carrier, getHubFromCarrier, getMainCarrier } from '@sentry/hub';
22
import { RewriteFrames } from '@sentry/integrations';
33
import { configureScope, getCurrentHub, init as nodeInit, Integrations } from '@sentry/node';
4+
import { Event } from '@sentry/types';
45
import { escapeStringForRegex, logger } from '@sentry/utils';
56
import * as domainModule from 'domain';
67
import * as path from 'path';
@@ -56,6 +57,8 @@ export function init(options: NextjsOptions): void {
5657
if (process.env.VERCEL) {
5758
scope.setTag('vercel', true);
5859
}
60+
61+
scope.addEventProcessor(filterTransactions);
5962
});
6063

6164
if (activeDomain) {
@@ -65,6 +68,8 @@ export function init(options: NextjsOptions): void {
6568
// apply the changes made by `nodeInit` to the domain's hub also
6669
domainHub.bindClient(globalHub.getClient());
6770
domainHub.getScope()?.update(globalHub.getScope());
71+
// `scope.update()` doesn’t copy over event processors, so we have to add it manually
72+
domainHub.getScope()?.addEventProcessor(filterTransactions);
6873

6974
// restore the domain hub as the current one
7075
domain.active = activeDomain;
@@ -107,6 +112,10 @@ function addServerIntegrations(options: NextjsOptions): void {
107112
}
108113
}
109114

115+
function filterTransactions(event: Event): Event | null {
116+
return event.type === 'transaction' && event.transaction === '/404' ? null : event;
117+
}
118+
110119
export { withSentryConfig } from './config';
111120
export { withSentry } from './utils/withSentry';
112121

0 commit comments

Comments
 (0)