Skip to content

Commit

Permalink
feat(replay): Send client_report when replay sending fails
Browse files Browse the repository at this point in the history
This leverages the new client_report categories.
  • Loading branch information
mydea committed Feb 8, 2023
1 parent b539b36 commit 374be44
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
12 changes: 10 additions & 2 deletions packages/replay/src/replay.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable max-lines */ // TODO: We might want to split this file up
import { EventType, record } from '@sentry-internal/rrweb';
import { captureException } from '@sentry/core';
import { captureException, getCurrentHub } from '@sentry/core';
import type { Breadcrumb, ReplayRecordingMode } from '@sentry/types';
import { logger } from '@sentry/utils';

Expand Down Expand Up @@ -807,9 +807,17 @@ export class ReplayContainer implements ReplayContainerInterface {
} catch (err) {
this._handleException(err);

// This means we retried 3 times, and all of them failed
// This means we retried 3 times and all of them failed,
// or we ran into a problem we don't want to retry, like rate limiting.
// In this case, we want to completely stop the replay - otherwise, we may get inconsistent segments
this.stop();

const hub = getCurrentHub();
const client = hub.getClient();

if (client) {
client.recordDroppedEvent('send_error', 'replay');
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions packages/replay/src/util/addEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { logger } from '@sentry/utils';

import { SESSION_IDLE_DURATION } from '../constants';
import type { AddEventResult, RecordingEvent, ReplayContainer } from '../types';
import { getCurrentHub } from '@sentry/core';

/**
* Add an event to the event buffer
Expand Down Expand Up @@ -46,5 +47,12 @@ export async function addEvent(
} catch (error) {
__DEBUG_BUILD__ && logger.error(error);
replay.stop();

const hub = getCurrentHub();
const client = hub.getClient();

if (client) {
client.recordDroppedEvent('internal_sdk_error', 'replay');
}
}
}
4 changes: 3 additions & 1 deletion packages/types/src/clientreport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export type EventDropReason =
| 'network_error'
| 'queue_overflow'
| 'ratelimit_backoff'
| 'sample_rate';
| 'sample_rate'
| 'send_error'
| 'internal_sdk_error';

export type Outcome = {
reason: EventDropReason;
Expand Down

0 comments on commit 374be44

Please sign in to comment.