Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

### Fixes

- Session replay will no longer start recording when an event was ignored or dropped. ([#5885](https://github.com/getsentry/sentry-react-native/pull/5885))
- Fix SIGABRT crash on launch when `mobileReplayIntegration` is not configured and iOS deployment target >= 16.0 ([#5858](https://github.com/getsentry/sentry-react-native/pull/5858))
- Reduce `reactNavigationIntegration` performance overhead ([#5840](https://github.com/getsentry/sentry-react-native/pull/5840), [#5842](https://github.com/getsentry/sentry-react-native/pull/5842), [#5849](https://github.com/getsentry/sentry-react-native/pull/5849))
- Fix duplicated breadcrumbs on Android ([#5841](https://github.com/getsentry/sentry-react-native/pull/5841))
Expand Down
20 changes: 17 additions & 3 deletions packages/core/src/js/replay/mobilereplay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Client, DynamicSamplingContext, Event, EventHint, Integration, Metric } from '@sentry/core';
import type { Client, DynamicSamplingContext, ErrorEvent, Event, EventHint, Integration, Metric } from '@sentry/core';
import { debug } from '@sentry/core';
import { isHardCrash } from '../misc';
import { hasHooks } from '../utils/clientutils';
Expand Down Expand Up @@ -213,7 +213,7 @@ export const mobileReplayIntegration = (initOptions: MobileReplayOptions = defau
return nativeReplayId;
}

async function processEvent(event: Event, hint: EventHint): Promise<Event> {
async function processEvent(event: ErrorEvent, hint: EventHint): Promise<ErrorEvent> {
const hasException = event.exception?.values && event.exception.values.length > 0;
if (!hasException) {
// Event is not an error, will not capture replay
Expand Down Expand Up @@ -303,6 +303,21 @@ export const mobileReplayIntegration = (initOptions: MobileReplayOptions = defau
});

client.on('beforeAddBreadcrumb', enrichXhrBreadcrumbsForMobileReplay);

// Wrap beforeSend to run processEvent after user's beforeSend
const clientOptions = client.getOptions();
const originalBeforeSend = clientOptions.beforeSend;
clientOptions.beforeSend = async (event: ErrorEvent, hint: EventHint): Promise<ErrorEvent | null> => {
var result = event;
if (originalBeforeSend) {
result = await originalBeforeSend(event, hint);
if (result === null) {
// Event was dropped by user's beforeSend, don't capture replay
return null;
}
}
return processEvent(result, hint);
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replay bridge errors can drop events

High Severity

beforeSend awaits processEvent without guarding failures. If replay bridge calls fail, the wrapped beforeSend rejects and the SDK drops the original event instead of sending it without replay data.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

}

function getReplayId(): string | null {
Expand All @@ -314,7 +329,6 @@ export const mobileReplayIntegration = (initOptions: MobileReplayOptions = defau
return {
name: MOBILE_REPLAY_INTEGRATION_NAME,
setup,
processEvent,
options: options,
getReplayId: getReplayId,
};
Expand Down
Loading
Loading