Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Fix duplicate error reporting on iOS with New Architecture ([#5532](https://github.com/getsentry/sentry-react-native/pull/5532))
- Fix for missing `replay_id` from metrics ([#5483](https://github.com/getsentry/sentry-react-native/pull/5483))
- Skip span ID check when standalone mode is enabled ([#5493](https://github.com/getsentry/sentry-react-native/pull/5493))
- Fix traces not always being attached to replays with errors ([#5538](https://github.com/getsentry/sentry-react-native/pull/5538))

### Dependencies

Expand Down
12 changes: 12 additions & 0 deletions packages/core/src/js/replay/mobilereplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ export const mobileReplayIntegration = (initOptions: MobileReplayOptions = defau
debug.log(
`[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} Captured recording replay ${replayId} for event ${event.event_id}.`,
);
// Add replay_id to error event contexts to link replays to events/traces
event.contexts = event.contexts || {};
event.contexts.replay = {
...event.contexts.replay,
replay_id: replayId,
};
} else {
// Check if there's an ongoing recording and update cache if found
const recordingReplayId = NATIVE.getCurrentReplayId();
Expand All @@ -224,6 +230,12 @@ export const mobileReplayIntegration = (initOptions: MobileReplayOptions = defau
debug.log(
`[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} assign already recording replay ${recordingReplayId} for event ${event.event_id}.`,
);
// Add replay_id to error event contexts to link replays to events/traces
event.contexts = event.contexts || {};
event.contexts.replay = {
...event.contexts.replay,
replay_id: recordingReplayId,
};
} else {
updateCachedReplayId(null);
debug.log(`[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} not sampled for event ${event.event_id}.`);
Expand Down
19 changes: 19 additions & 0 deletions packages/core/test/replay/mobilereplay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,25 @@ describe('Mobile Replay Integration', () => {

expect(mockCaptureReplay).toHaveBeenCalled();
});

it('should add replay context to error events when replay is captured', async () => {
const integration = mobileReplayIntegration();
const replayId = 'test-replay-id';
mockCaptureReplay.mockResolvedValue(replayId);

const event: Event = {
event_id: 'test-event-id',
exception: {
values: [{ type: 'Error', value: 'Test error' }],
},
};
const hint: EventHint = {};

if (integration.processEvent) {
const processedEvent = await integration.processEvent(event, hint);
expect(processedEvent.contexts?.replay?.replay_id).toBe(replayId);
}
});
});

describe('platform checks', () => {
Expand Down
Loading