Skip to content

Commit

Permalink
feat(replay): Capture client report when retry fails
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Jan 13, 2023
1 parent 5e39384 commit bae6b5e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/replay/src/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,9 @@ export class ReplayContainer implements ReplayContainerInterface {
return;
}

const client = getCurrentHub().getClient();
client?.recordDroppedEvent('retry_failed', 'replay_event');

// This means we retried 3 times, and all of them failed
// In this case, we want to completely stop the replay - otherwise, we may get inconsistent segments
this.stop();
Expand Down
5 changes: 5 additions & 0 deletions packages/replay/test/integration/sendReplayEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ describe('Integration | sendReplayEvent', () => {
const TEST_EVENT = { data: {}, timestamp: BASE_TIMESTAMP, type: 3 };

const spyHandleException = jest.spyOn(SentryCore, 'captureException');
const spyRecordDroppedEvent = jest.spyOn(SentryCore.getCurrentHub().getClient()!, 'recordDroppedEvent');

// Suppress console.errors
const mockConsole = jest.spyOn(console, 'error').mockImplementation(jest.fn());
Expand Down Expand Up @@ -432,6 +433,10 @@ describe('Integration | sendReplayEvent', () => {
// Replay should be completely stopped now
expect(replay.isEnabled()).toBe(false);

// Failed retry is recorded
expect(spyRecordDroppedEvent).toHaveBeenCalledTimes(1);
expect(spyRecordDroppedEvent).toHaveBeenLastCalledWith('retry_failed', 'replay_event');

// Events are ignored now, because we stopped
mockRecord._emitter(TEST_EVENT);
await advanceTimers(DEFAULT_FLUSH_MIN_DELAY);
Expand Down
3 changes: 2 additions & 1 deletion packages/types/src/clientreport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export type EventDropReason =
| 'network_error'
| 'queue_overflow'
| 'ratelimit_backoff'
| 'sample_rate';
| 'sample_rate'
| 'retry_failed';

export type Outcome = {
reason: EventDropReason;
Expand Down

0 comments on commit bae6b5e

Please sign in to comment.