Skip to content

feat(react-router): Create low quality transactions filter for react router #16219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Next Next commit
feat(react-router): Create a transaction filter for react router
  • Loading branch information
RulaKhaled committed May 7, 2025
commit 56c4346668c474338321eb9d7c47a724f1d85f7d
30 changes: 29 additions & 1 deletion packages/react-router/src/server/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { applySdkMetadata, logger, setTag } from '@sentry/core';
import { type EventProcessor, applySdkMetadata, getGlobalScope, logger, setTag } from '@sentry/core';
import type { NodeClient, NodeOptions } from '@sentry/node';
import { init as initNodeSdk } from '@sentry/node';
import { DEBUG_BUILD } from '../common/debug-build';
Expand All @@ -20,5 +20,33 @@ export function init(options: NodeOptions): NodeClient | undefined {
setTag('runtime', 'node');

DEBUG_BUILD && logger.log('SDK successfully initialized');

getGlobalScope().addEventProcessor(lowQualityTransactionsFilter(options));

return client;
}

/**
* Filters out noisy transactions such as requests to node_modules
*
* @param options The NodeOptions passed to the SDK
* @returns An EventProcessor that filters low-quality transactions
*/
export function lowQualityTransactionsFilter(options: NodeOptions): EventProcessor {
return Object.assign(
(event => {
if (event.type !== 'transaction' || !event.transaction) {
return event;
}

if (event.transaction.match(/\/node_modules\//)) {
options.debug &&
logger.log('[ReactRouter] Filtered node_modules transaction:', event.transaction);
return null;
}

return event;
}) satisfies EventProcessor,
{ id: 'ReactRouterLowQualityTransactionsFilter' },
);
}