Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(replay): Fix onError callback #14002

Merged
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
2 changes: 2 additions & 0 deletions packages/replay-internal/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export class Replay implements Integration {

beforeAddRecordingEvent,
beforeErrorSampling,
onError,
}: ReplayConfiguration = {}) {
this.name = Replay.id;

Expand Down Expand Up @@ -183,6 +184,7 @@ export class Replay implements Integration {
networkResponseHeaders: _getMergedNetworkHeaders(networkResponseHeaders),
beforeAddRecordingEvent,
beforeErrorSampling,
onError,

_experiments,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('Integration | sendReplayEvent', () => {
let mockTransportSend: MockTransportSend;
let mockSendReplayRequest: MockInstance<any>;
let domHandler: DomHandler;
const onError: () => void = vi.fn();
const { record: mockRecord } = mockRrweb();

beforeAll(async () => {
Expand All @@ -44,6 +45,7 @@ describe('Integration | sendReplayEvent', () => {
_experiments: {
captureExceptions: true,
},
onError,
},
}));

Expand All @@ -54,6 +56,7 @@ describe('Integration | sendReplayEvent', () => {
});

beforeEach(() => {
vi.clearAllMocks();
vi.setSystemTime(new Date(BASE_TIMESTAMP));
mockRecord.takeFullSnapshot.mockClear();
mockTransportSend.mockClear();
Expand Down Expand Up @@ -357,8 +360,9 @@ describe('Integration | sendReplayEvent', () => {
expect(replay).not.toHaveLastSentReplay();
});

it('fails to upload data and hits retry max and stops', async () => {
it('fails to upload data, hits retry max, stops, and calls `onError` with the error', async () => {
const TEST_EVENT = getTestEventIncremental({ timestamp: BASE_TIMESTAMP });
const ERROR = new Error('Something bad happened');

const spyHandleException = vi.spyOn(SentryCore, 'captureException');

Expand All @@ -369,7 +373,7 @@ describe('Integration | sendReplayEvent', () => {

// fail all requests
mockSendReplayRequest.mockImplementation(async () => {
throw new Error('Something bad happened');
throw ERROR;
});
mockRecord._emitter(TEST_EVENT);

Expand Down Expand Up @@ -406,6 +410,8 @@ describe('Integration | sendReplayEvent', () => {
// Replay has stopped, no session should exist
expect(replay.session).toBe(undefined);
expect(replay.isEnabled()).toBe(false);
expect(onError).toHaveBeenCalledTimes(5);
Copy link
Contributor

Choose a reason for hiding this comment

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

why is it 5?

Copy link
Member Author

Choose a reason for hiding this comment

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

It gets called each time replay fails to send until it hits max

expect(onError).toHaveBeenCalledWith(ERROR);

// Events are ignored now, because we stopped
mockRecord._emitter(TEST_EVENT);
Expand Down
Loading