Skip to content

Commit 348c8cb

Browse files
committed
feat(nextjs): Filtering unwanted segments in span streaming
1 parent 313cf82 commit 348c8cb

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

packages/nextjs/src/client/index.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,17 @@ export function init(options: BrowserOptions): Client | undefined {
7474
applyTunnelRouteOption(opts);
7575
applySdkMetadata(opts, 'nextjs', ['nextjs', 'react']);
7676

77-
const client = reactInit(opts);
78-
79-
const filterTransactions: EventProcessor = event =>
80-
event.type === 'transaction' && event.transaction === '/404' ? null : event;
81-
filterTransactions.id = 'NextClient404Filter';
82-
addEventProcessor(filterTransactions);
77+
opts.ignoreSpans = [
78+
...(opts.ignoreSpans || []),
79+
// we filter out segment spans for /404 pages
80+
/^\/404$/,
81+
// segment spans where we didn't get a reasonable transaction name
82+
// in this case, constructing a dynamic RegExp is fine because the variable is a constant
83+
// we need to ensure to exact-match, so a string match isn't safe (same for /404 above)
84+
new RegExp(`^${INCOMPLETE_APP_ROUTER_INSTRUMENTATION_TRANSACTION_NAME}$`),
85+
];
8386

84-
const filterIncompleteNavigationTransactions: EventProcessor = event =>
85-
event.type === 'transaction' && event.transaction === INCOMPLETE_APP_ROUTER_INSTRUMENTATION_TRANSACTION_NAME
86-
? null
87-
: event;
88-
filterIncompleteNavigationTransactions.id = 'IncompleteTransactionFilter';
89-
addEventProcessor(filterIncompleteNavigationTransactions);
87+
const client = reactInit(opts);
9088

9189
const filterNextRedirectError: EventProcessor = (event, hint) =>
9290
isRedirectNavigationError(hint?.originalException) || event.exception?.values?.[0]?.value === 'NEXT_REDIRECT'

0 commit comments

Comments
 (0)