Background
As of @sentry/core 10.70.0 (getsentry/sentry-javascript#22819), error event sampleRate sampling was moved from before _prepareEvent to after it. This means beforeSend now runs before the sampling decision.
The mobile replay integration wraps beforeSend to call NATIVE.captureReplay for error events (mobilereplay.ts:375). With the new ordering, replay segments can be captured for events that are subsequently dropped by sampleRate sampling.
Previous behavior (< 10.70.0)
sampleRate check → event dropped before beforeSend → no replay captured
Current behavior (>= 10.70.0)
_prepareEvent → beforeSend → mobile replay captures native segment → sampleRate check → event dropped
- The replay segment is captured and linked via
replay_id, but the error event it's linked to is never sent
Impact
Apps with sampleRate below 1.0 will capture native replay segments for error events that are then dropped by sampling, resulting in orphaned replays and wasted native work.
Suggested investigation
- Confirm whether orphaned replay segments cause any server-side issues (e.g. unlinked replays in the UI)
- Consider checking
sampleRate in processEvent before calling NATIVE.captureReplay
- Alternatively, coordinate with the JS SDK team on whether a hook or event metadata could signal the sampling decision earlier
References
Background
As of
@sentry/core10.70.0 (getsentry/sentry-javascript#22819), error eventsampleRatesampling was moved from before_prepareEventto after it. This meansbeforeSendnow runs before the sampling decision.The mobile replay integration wraps
beforeSendto callNATIVE.captureReplayfor error events (mobilereplay.ts:375). With the new ordering, replay segments can be captured for events that are subsequently dropped bysampleRatesampling.Previous behavior (< 10.70.0)
sampleRatecheck → event dropped beforebeforeSend→ no replay capturedCurrent behavior (>= 10.70.0)
_prepareEvent→beforeSend→ mobile replay captures native segment →sampleRatecheck → event droppedreplay_id, but the error event it's linked to is never sentImpact
Apps with
sampleRatebelow1.0will capture native replay segments for error events that are then dropped by sampling, resulting in orphaned replays and wasted native work.Suggested investigation
sampleRateinprocessEventbefore callingNATIVE.captureReplayReferences
beforeSendwrapper:packages/core/src/js/replay/mobilereplay.ts#L492-L508