8000 feat(replay): Do not capture errors originating from rrweb (#6521) · danieliu/sentry-javascript@967dfb1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 967dfb1

Browse files
authored
feat(replay): Do not capture errors originating from rrweb (getsentry#6521)
Unless using `captureExceptions` experiment, we want to ignore these errors.
1 parent 23a58b9 commit 967dfb1

File tree

3 files changed

+278
-100
lines changed

3 files changed

+278
-100
lines changed

packages/replay/src/coreHandlers/handleGlobalEvent.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { addBreadcrumb } from '@sentry/core';
22
import { Event } from '@sentry/types';
3+
import { logger } from '@sentry/utils';
34

45
import { REPLAY_EVENT_NAME, UNABLE_TO_SEND_REPLAY } from '../constants';
56
import type { ReplayContainer } from '../types';
7+
import { isRrwebError< 8000 /span> } from '../util/isRrwebError';
68

79
/**
810
* Returns a listener to be added to `addGlobalEventProcessor(listener)`.
911
*/
10-
export function handleGlobalEventListener(replay: ReplayContainer): (event: Event) => Event {
12+
export function handleGlobalEventListener(replay: ReplayContainer): (event: Event) => Event | null {
1113
return (event: Event) => {
1214
// Do not apply replayId to the root event
1315
if (
@@ -20,6 +22,13 @@ export function handleGlobalEventListener(replay: ReplayContainer): (event: Even
2022
return event;
2123
}
2224

25+
// Unless `captureExceptions` is enabled, we want to ignore errors coming from rrweb
26+
// As there can be a bunch of stuff going wrong in internals there, that we don't want to bubble up to users
27+
if (isRrwebError(event) && !replay.getOptions()._experiments?.captureExceptions) {
28+
__DEBUG_BUILD__ && logger.log('[Replay] Ignoring error from rrweb internals', event);
29+
return null;
30+
}
31+
2332
// Only tag transactions with replayId if not waiting for an error
2433
// @ts-ignore private
2534
if (event.type !== 'transaction' || replay.recordingMode === 'session') {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Event } from '@sentry/types';
2+
3+
export function isRrwebError(event: Event): boolean {
4+
if (event.type || !event.exception?.values?.length) {
5+
return false;
6+
}
7+
8+
// Check if any exception originates from rrweb
9+
return event.exception.values.some(exception => {
10+
if (!exception.stacktrace?.frames?.length) {
11+
return false;
12+
}
13+
14+
return exception.stacktrace.frames.some(frame => frame.filename?.includes('/rrweb/src/'));
15+
});
16+
}

0 commit comments

Comments
 (0)
0