Skip to content

feat(replay): Attach an error cause to send exceptions #7350

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

Merged
merged 2 commits into from
Mar 9, 2023
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
12 changes: 11 additions & 1 deletion packages/replay/src/util/sendReplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ export async function sendReplay(
// If an error happened here, it's likely that uploading the attachment
// failed, we'll can retry with the same events payload
if (retryConfig.count >= RETRY_MAX_COUNT) {
throw new Error(`${UNABLE_TO_SEND_REPLAY} - max retries exceeded`);
const error = new Error(`${UNABLE_TO_SEND_REPLAY} - max retries exceeded`);

try {
// In case browsers don't allow this property to be writable
// @ts-ignore This needs lib es2022 and newer
error.cause = err;
} catch {
// nothing to do
}

throw error;
}

// will retry in intervals of 5, 10, 30
Expand Down
13 changes: 11 additions & 2 deletions packages/replay/src/util/sendReplayRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,17 @@ export async function sendReplayRequest({

try {
response = await transport.send(envelope);
} catch {
throw new Error(UNABLE_TO_SEND_REPLAY);
} catch (err) {
const error = new Error(UNABLE_TO_SEND_REPLAY);

try {
// In case browsers don't allow this property to be writable
// @ts-ignore This needs lib es2022 and newer
error.cause = err;
} catch {
// nothing to do
}
throw error;
}

// TODO (v8): we can remove this guard once transport.send's type signature doesn't include void anymore
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 @@ -371,6 +371,11 @@ describe('Integration | sendReplayEvent', () => {
expect(spyHandleException).toHaveBeenCalledTimes(5);
expect(spyHandleException).toHaveBeenLastCalledWith(new Error('Unable to send Replay - max retries exceeded'));

const spyHandleExceptionCall = spyHandleException.mock.calls;
expect(spyHandleExceptionCall[spyHandleExceptionCall.length - 1][0].cause.message).toEqual(
'Something bad happened',
);

// No activity has occurred, session's last activity should remain the same
expect(replay.session?.lastActivity).toBe(BASE_TIMESTAMP);

Expand Down