Skip to content

Commit 56c4346

Browse files
committed
feat(react-router): Create a transaction filter for react router
1 parent e0c0d9d commit 56c4346

File tree

1 file changed

+29
-1
lines changed
  • packages/react-router/src/server

1 file changed

+29
-1
lines changed

packages/react-router/src/server/sdk.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { applySdkMetadata, logger, setTag } from '@sentry/core';
1+
import { type EventProcessor, applySdkMetadata, getGlobalScope, logger, setTag } from '@sentry/core';
22
import type { NodeClient, NodeOptions } from '@sentry/node';
33
import { init as initNodeSdk } from '@sentry/node';
44
import { DEBUG_BUILD } from '../common/debug-build';
@@ -20,5 +20,33 @@ export function init(options: NodeOptions): NodeClient | undefined {
2020
setTag('runtime', 'node');
2121

2222
DEBUG_BUILD && logger.log('SDK successfully initialized');
23+
24+
getGlobalScope().addEventProcessor(lowQualityTransactionsFilter(options));
25+
2326
return client;
2427
}
28+
29+
/**
30+
* Filters out noisy transactions such as requests to node_modules
31+
*
32+
* @param options The NodeOptions passed to the SDK
33+
* @returns An EventProcessor that filters low-quality transactions
34+
*/
35+
export function lowQualityTransactionsFilter(options: NodeOptions): EventProcessor {
36+
return Object.assign(
37+
(event => {
38+
if (event.type !== 'transaction' || !event.transaction) {
39+
return event;
40+
}
41+
42+
if (event.transaction.match(/\/node_modules\//)) {
43+
options.debug &&
44+
logger.log('[ReactRouter] Filtered node_modules transaction:', event.transaction);
45+
return null;
46+
}
47+
48+
return event;
49+
}) satisfies EventProcessor,
50+
{ id: 'ReactRouterLowQualityTransactionsFilter' },
51+
);
52+
}

0 commit comments

Comments
 (0)