Skip to content

feat(replay): Do not capture errors originating from rrweb #6521

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 1 commit into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/replay/src/coreHandlers/handleGlobalEvent.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { addBreadcrumb } from '@sentry/core';
import { Event } from '@sentry/types';
import { logger } from '@sentry/utils';

import { REPLAY_EVENT_NAME, UNABLE_TO_SEND_REPLAY } from '../constants';
import type { ReplayContainer } from '../types';
import { isRrwebError } from '../util/isRrwebError';

/**
* Returns a listener to be added to `addGlobalEventProcessor(listener)`.
*/
export function handleGlobalEventListener(replay: ReplayContainer): (event: Event) => Event {
export function handleGlobalEventListener(replay: ReplayContainer): (event: Event) => Event | null {
return (event: Event) => {
// Do not apply replayId to the root event
if (
Expand All @@ -20,6 +22,13 @@ export function handleGlobalEventListener(replay: ReplayContainer): (event: Even
return event;
}

// Unless `captureExceptions` is enabled, we want to ignore errors coming from rrweb
// As there can be a bunch of stuff going wrong in internals there, that we don't want to bubble up to users
if (isRrwebError(event) && !replay.getOptions()._experiments?.captureExceptions) {
__DEBUG_BUILD__ && logger.log('[Replay] Ignoring error from rrweb internals', event);
return null;
}

// Only tag transactions with replayId if not waiting for an error
// @ts-ignore private
if (event.type !== 'transaction' || replay.recordingMode === 'session') {
Expand Down
16 changes: 16 additions & 0 deletions packages/replay/src/util/isRrwebError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Event } from '@sentry/types';

export function isRrwebError(event: Event): boolean {
if (event.type || !event.exception?.values?.length) {
return false;
}

// Check if any exception originates from rrweb
return event.exception.values.some(exception => {
if (!exception.stacktrace?.frames?.length) {
return false;
}

return exception.stacktrace.frames.some(frame => frame.filename?.includes('/rrweb/src/'));
});
}
Loading