Skip to content

Commit

Permalink
feat(replay): Stop recording when retry fails
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Jan 16, 2023
1 parent 57b3ccb commit aba648a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/replay/src/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -824,10 +824,16 @@ export class ReplayContainer implements ReplayContainerInterface {
timestamp: new Date().getTime(),
});
} catch (err) {
this._handleException(err);

if (err instanceof RateLimitError) {
this._handleRateLimit(err.rateLimits);
return;
}
this._handleException(err);

// 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 All @@ -837,8 +843,7 @@ export class ReplayContainer implements ReplayContainerInterface {
*/
private _flush: () => Promise<void> = async () => {
if (!this._isEnabled) {
// This is just a precaution, there should be no listeners that would
// cause a flush.
// This can happen if e.g. the replay was stopped because of exceeding the retry limit
return;
}

Expand Down
12 changes: 12 additions & 0 deletions packages/replay/test/integration/sendReplayEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,5 +428,17 @@ describe('Integration | sendReplayEvent', () => {

// segmentId increases despite error
expect(replay.session?.segmentId).toBe(1);

// Replay should be completely stopped now
expect(replay.isEnabled()).toBe(false);

// Events are ignored now, because we stopped
mockRecord._emitter(TEST_EVENT);
await advanceTimers(DEFAULT_FLUSH_MIN_DELAY);
expect(mockSendReplayRequest).toHaveBeenCalledTimes(4);
});

// NOTE: If you add a test after the last one, make sure to adjust the test setup
// As this ends with a `stopped()` replay, which may prevent future tests from working
// Sadly, fixing this turned out to be much more annoying than expected, so leaving this warning here for now
});

0 comments on commit aba648a

Please sign in to comment.