@sentry/replay 0.5.10 → 0.5.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -46,6 +46,18 @@ Sentry.init({
46
46
  });
47
47
  ```
48
48
 
49
+ ### Stopping Replays
50
+
51
+ To stop replays you can call the `destroy()` method on the integration instance. It's possible to resume recording by calling `setup()`.
52
+
53
+ ```javascript
54
+
55
+ const replay = new SentryReplay(); // This will begin recording replays
56
+
57
+ replay.destroy(); // Stop recording
58
+
59
+ replay.setup(); // Start recording again
60
+ ```
49
61
 
50
62
  ## Configuration
51
63
 
@@ -0,0 +1,15 @@
1
+ import { InitialState } from '@/types';
2
+ export interface CaptureReplayEventParams {
3
+ initialState: InitialState;
4
+ includeReplayStartTimestamp: boolean;
5
+ errorIds: string[];
6
+ replayId: string;
7
+ segmentId: number;
8
+ /**
9
+ * Timestamp of the event in milliseconds
10
+ */
11
+ timestamp: number;
12
+ traceIds: string[];
13
+ urls: string[];
14
+ }
15
+ export declare function captureReplayEvent({ initialState, includeReplayStartTimestamp, errorIds, replayId: replay_id, segmentId: segment_id, timestamp, traceIds, urls, }: CaptureReplayEventParams): void;
@@ -1,6 +1,5 @@
1
1
  import { Breadcrumb, Event, Integration } from '@sentry/types';
2
- import { CaptureReplayParams } from './api/captureReplay';
3
- import { CaptureReplayUpdateParams } from './api/captureReplayUpdate';
2
+ import { CaptureReplayEventParams } from './api/captureReplayEvent';
4
3
  import { Session } from './session/Session';
5
4
  import { ReplayPerformanceEntry } from './createPerformanceEntry';
6
5
  import { IEventBuffer } from './eventBuffer';
@@ -18,11 +17,7 @@ export declare class SentryReplay implements Integration {
18
17
  * @inheritDoc
19
18
  */
20
19
  name: string;
21
- eventBuffer: IEventBuffer;
22
- /**
23
- * Buffer of breadcrumbs to be uploaded
24
- */
25
- breadcrumbs: Breadcrumb[];
20
+ eventBuffer: IEventBuffer | null;
26
21
  /**
27
22
  * List of PerformanceEntry from PerformanceObserver
28
23
  */
@@ -46,12 +41,23 @@ export declare class SentryReplay implements Integration {
46
41
  private retryCount;
47
42
  private retryInterval;
48
43
  /**
49
- * Flag to make sure we only create a replay event when
50
- * necessary (i.e. we only want to have a single replay
51
- * event per session and it should only be created
52
- * immediately before sending recording)
44
+ * Flag when a new session has been created. Captured replay events behave
45
+ * slightly differently in this case: `replay_start_timestamp` is included.
46
+ */
47
+ private newSessionCreated;
48
+ /**
49
+ * Is the integration currently active?
50
+ */
51
+ private isEnabled;
52
+ /**
53
+ * Have we attached listeners to the core SDK?
54
+ * Note we have to track this as there is no way to remove instrumentation handlers.
55
+ */
56
+ private hasInitializedCoreListeners;
57
+ /**
58
+ * Function to stop recording
53
59
  */
54
- private needsCaptureReplay;
60
+ private stopRecording;
55
61
  /**
56
62
  * Captured state when integration is first initialized
57
63
  */
@@ -208,7 +214,7 @@ export declare class SentryReplay implements Integration {
208
214
  */
209
215
  popEventContext({ timestamp, }?: {
210
216
  timestamp?: number;
211
- }): CaptureReplayParams & CaptureReplayUpdateParams;
217
+ }): CaptureReplayEventParams;
212
218
  /**
213
219
  * Flushes replay event buffer to Sentry.
214
220
  *
@@ -219,11 +225,11 @@ export declare class SentryReplay implements Integration {
219
225
  /**
220
226
  * Send replay attachment using `fetch()`
221
227
  */
222
- sendReplayRequest({ endpoint, events }: ReplayRequest): Promise<void>;
228
+ sendReplayRequest({ endpoint, events, replayId: event_id, segmentId: segment_id, }: ReplayRequest): Promise<void>;
223
229
  resetRetries(): void;
224
230
  /**
225
231
  * Finalize and send the current replay event to Sentry
226
232
  */
227
- sendReplay(eventId: string, events: RecordedEvents): Promise<boolean | undefined>;
233
+ sendReplay(replayId: string, events: RecordedEvents, segmentId: number): Promise<true | undefined>;
228
234
  }
229
235
  export {};
@@ -6,6 +6,8 @@ export declare type RecordedEvents = Uint8Array | string;
6
6
  export interface ReplayRequest {
7
7
  endpoint: string;
8
8
  events: RecordedEvents;
9
+ replayId: string;
10
+ segmentId: number;
9
11
  }
10
12
  export declare type InstrumentationTypeBreadcrumb = 'dom' | 'scope';
11
13
  export declare type InstrumentationTypeSpan = 'fetch' | 'xhr' | 'history';
@@ -4,8 +4,8 @@ declare const logger: {
4
4
  log: (...args: any[]) => any;
5
5
  disable(): void;
6
6
  enable(): void;
7
- info: (...args: unknown[]) => void;
8
7
  debug: (...args: unknown[]) => void;
8
+ info: (...args: unknown[]) => void;
9
9
  assert: (...args: unknown[]) => void;
10
10
  trace: (...args: unknown[]) => void;
11
11
  };
package/dist/index.es.js CHANGED
@@ -95,32 +95,13 @@ var SESSION_IDLE_DURATION = 900000; // 15 minutes
95
95
  // Grace period to keep a session when a user changes tabs or hides window
96
96
  var VISIBILITY_CHANGE_TIMEOUT = SESSION_IDLE_DURATION;
97
97
 
98
- function captureReplay(_a) {
99
- var session = _a.session, initialState = _a.initialState, errorIds = _a.errorIds, traceIds = _a.traceIds, urls = _a.urls;
100
- captureEvent({
98
+ function captureReplayEvent(_a) {
99
+ var initialState = _a.initialState, includeReplayStartTimestamp = _a.includeReplayStartTimestamp, errorIds = _a.errorIds, replay_id = _a.replayId, segment_id = _a.segmentId, timestamp = _a.timestamp, traceIds = _a.traceIds, urls = _a.urls;
100
+ captureEvent(__assign(__assign(__assign({
101
101
  // @ts-expect-error replay_event is a new event type
102
- type: REPLAY_EVENT_NAME,
103
- replay_start_timestamp: initialState.timestamp / 1000,
104
- error_ids: errorIds,
105
- trace_ids: traceIds,
106
- urls: urls,
107
- replay_id: session.id,
108
- segment_id: session.segmentId, // TODO: Should this increment?
109
- }, { event_id: session.id });
110
- }
111
-
112
- function captureReplayUpdate(_a) {
113
- var session = _a.session, timestamp = _a.timestamp, errorIds = _a.errorIds, traceIds = _a.traceIds, urls = _a.urls;
114
- captureEvent({
115
- // @ts-expect-error replay_event is a new event type
116
- type: REPLAY_EVENT_NAME,
117
- timestamp: timestamp / 1000,
118
- error_ids: errorIds,
119
- trace_ids: traceIds,
120
- urls: urls,
121
- replay_id: session.id,
122
- segment_id: ++session.segmentId,
123
- });
102
+ type: REPLAY_EVENT_NAME }, (includeReplayStartTimestamp
103
+ ? { replay_start_timestamp: initialState.timestamp / 1000 }
104
+ : {})), (timestamp ? { timestamp: timestamp / 1000 } : {})), { error_ids: errorIds, trace_ids: traceIds, urls: urls, replay_id: replay_id, segment_id: segment_id }), { event_id: replay_id });
124
105
  }
125
106
 
126
107
  function createBreadcrumb(breadcrumb) {
@@ -467,7 +448,8 @@ function fetchSession() {
467
448
  */
468
449
  function getSession(_a) {
469
450
  var expiry = _a.expiry, currentSession = _a.currentSession, stickySession = _a.stickySession, samplingRate = _a.samplingRate;
470
- var session = stickySession ? fetchSession() : currentSession;
451
+ // If session exists and is passed, use it instead of always hitting session storage
452
+ var session = currentSession || (stickySession && fetchSession());
471
453
  if (session) {
472
454
  // If there is a session, check if it is valid (e.g. "last activity" time should be within the "session idle time")
473
455
  // TODO: We should probably set a max age on this as well
@@ -797,7 +779,7 @@ var EventBufferCompressionWorker = /** @class */ (function () {
797
779
  }());
798
780
 
799
781
  var BASE_RETRY_INTERVAL = 5000;
800
- var MAX_RETRY_COUNT = 5;
782
+ var MAX_RETRY_COUNT = 3;
801
783
  var UNABLE_TO_SEND_REPLAY = 'Unable to send replay';
802
784
  var SentryReplay = /** @class */ (function () {
803
785
  function SentryReplay(_a) {
@@ -808,10 +790,6 @@ var SentryReplay = /** @class */ (function () {
808
790
  * @inheritDoc
809
791
  */
810
792
  this.name = SentryReplay.id;
811
- /**
812
- * Buffer of breadcrumbs to be uploaded
813
- */
814
- this.breadcrumbs = [];
815
793
  /**
816
794
  * List of PerformanceEntry from PerformanceObserver
817
795
  */
@@ -826,12 +804,23 @@ var SentryReplay = /** @class */ (function () {
826
804
  this.retryCount = 0;
827
805
  this.retryInterval = BASE_RETRY_INTERVAL;
828
806
  /**
829
- * Flag to make sure we only create a replay event when
830
- * necessary (i.e. we only want to have a single replay
831
- * event per session and it should only be created
832
- * immediately before sending recording)
807
+ * Flag when a new session has been created. Captured replay events behave
808
+ * slightly differently in this case: `replay_start_timestamp` is included.
809
+ */
810
+ this.newSessionCreated = false;
811
+ /**
812
+ * Is the integration currently active?
833
813
  */
834
- this.needsCaptureReplay = false;
814
+ this.isEnabled = false;
815
+ /**
816
+ * Have we attached listeners to the core SDK?
817
+ * Note we have to track this as there is no way to remove instrumentation handlers.
818
+ */
819
+ this.hasInitializedCoreListeners = false;
820
+ /**
821
+ * Function to stop recording
822
+ */
823
+ this.stopRecording = null;
835
824
  this.context = {
836
825
  errorIds: new Set(),
837
826
  traceIds: new Set(),
@@ -950,6 +939,9 @@ var SentryReplay = /** @class */ (function () {
950
939
  *
951
940
  */
952
941
  this.handleCoreSpanListener = function (type) { return function (handlerData) {
942
+ if (!_this.isEnabled) {
943
+ return;
944
+ }
953
945
  var handler = getSpanHandler(type);
954
946
  var result = handler(handlerData);
955
947
  if (result === null) {
@@ -973,6 +965,9 @@ var SentryReplay = /** @class */ (function () {
973
965
  * These events will create breadcrumb-like objects in the recording.
974
966
  */
975
967
  this.handleCoreBreadcrumbListener = function (type) { return function (handlerData) {
968
+ if (!_this.isEnabled) {
969
+ return;
970
+ }
976
971
  var handler = getBreadcrumbHandler(type);
977
972
  var result = handler(handlerData);
978
973
  if (result === null) {
@@ -1001,6 +996,7 @@ var SentryReplay = /** @class */ (function () {
1001
996
  // For whatever reason the observer was returning duplicate navigation
1002
997
  // entries (the other entry types were not duplicated).
1003
998
  var newEntries = new Set(list.getEntries());
999
+ console.log(list.getEntries());
1004
1000
  _this.performanceEvents = __spreadArray(__spreadArray([], _this.performanceEvents, true), Array.from(newEntries), true);
1005
1001
  };
1006
1002
  this.recordingOptions = __assign({ maskAllInputs: maskAllInputs, blockClass: blockClass, ignoreClass: ignoreClass, maskTextClass: maskTextClass }, recordingOptions);
@@ -1055,7 +1051,8 @@ var SentryReplay = /** @class */ (function () {
1055
1051
  // Tag all (non replay) events that get sent to Sentry with the current
1056
1052
  // replay ID so that we can reference them later in the UI
1057
1053
  addGlobalEventProcessor(this.handleGlobalEvent);
1058
- record(__assign(__assign({}, this.recordingOptions), { emit: this.handleRecordingEmit }));
1054
+ this.stopRecording = record(__assign(__assign({}, this.recordingOptions), { emit: this.handleRecordingEmit }));
1055
+ this.isEnabled = true;
1059
1056
  };
1060
1057
  /**
1061
1058
  * We want to batch uploads of replay events. Save events only if
@@ -1110,8 +1107,13 @@ var SentryReplay = /** @class */ (function () {
1110
1107
  * Currently, this needs to be manually called (e.g. for tests). Sentry SDK does not support a teardown
1111
1108
  */
1112
1109
  SentryReplay.prototype.destroy = function () {
1110
+ var _a, _b;
1113
1111
  logger.log('Destroying instance');
1112
+ this.isEnabled = false;
1114
1113
  this.removeListeners();
1114
+ (_a = this.stopRecording) === null || _a === void 0 ? void 0 : _a.call(this);
1115
+ (_b = this.eventBuffer) === null || _b === void 0 ? void 0 : _b.destroy();
1116
+ this.eventBuffer = null;
1115
1117
  };
1116
1118
  SentryReplay.prototype.clearSession = function () {
1117
1119
  deleteSession();
@@ -1133,7 +1135,7 @@ var SentryReplay = /** @class */ (function () {
1133
1135
  // If session was newly created (i.e. was not loaded from storage), then
1134
1136
  // enable flag to create the root replay
1135
1137
  if (type === 'new') {
1136
- this.needsCaptureReplay = true;
1138
+ this.newSessionCreated = true;
1137
1139
  this.setInitialState();
1138
1140
  }
1139
1141
  if (session.id !== ((_b = this.session) === null || _b === void 0 ? void 0 : _b.id)) {
@@ -1149,6 +1151,7 @@ var SentryReplay = /** @class */ (function () {
1149
1151
  SentryReplay.prototype.setInitialState = function () {
1150
1152
  var urlPath = "".concat(window.location.pathname).concat(window.location.hash).concat(window.location.search);
1151
1153
  var url = "".concat(window.location.origin).concat(urlPath);
1154
+ this.performanceEvents = [];
1152
1155
  // Reset context as well
1153
1156
  this.popEventContext();
1154
1157
  this.initialState = {
@@ -1165,13 +1168,17 @@ var SentryReplay = /** @class */ (function () {
1165
1168
  document.addEventListener('visibilitychange', this.handleVisibilityChange);
1166
1169
  window.addEventListener('blur', this.handleWindowBlur);
1167
1170
  window.addEventListener('focus', this.handleWindowFocus);
1168
- // Listeners from core SDK //
1169
- var scope = getCurrentHub().getScope();
1170
- scope === null || scope === void 0 ? void 0 : scope.addScopeListener(this.handleCoreBreadcrumbListener('scope'));
1171
- addInstrumentationHandler('dom', this.handleCoreBreadcrumbListener('dom'));
1172
- addInstrumentationHandler('fetch', this.handleCoreSpanListener('fetch'));
1173
- addInstrumentationHandler('xhr', this.handleCoreSpanListener('xhr'));
1174
- addInstrumentationHandler('history', this.handleCoreSpanListener('history'));
1171
+ // There is no way to remove these listeners, so ensure they are only added once
1172
+ if (!this.hasInitializedCoreListeners) {
1173
+ // Listeners from core SDK //
1174
+ var scope = getCurrentHub().getScope();
1175
+ scope === null || scope === void 0 ? void 0 : scope.addScopeListener(this.handleCoreBreadcrumbListener('scope'));
1176
+ addInstrumentationHandler('dom', this.handleCoreBreadcrumbListener('dom'));
1177
+ addInstrumentationHandler('fetch', this.handleCoreSpanListener('fetch'));
1178
+ addInstrumentationHandler('xhr', this.handleCoreSpanListener('xhr'));
1179
+ addInstrumentationHandler('history', this.handleCoreSpanListener('history'));
1180
+ this.hasInitializedCoreListeners = true;
1181
+ }
1175
1182
  // PerformanceObserver //
1176
1183
  if (!('PerformanceObserver' in window)) {
1177
1184
  return;
@@ -1268,7 +1275,14 @@ var SentryReplay = /** @class */ (function () {
1268
1275
  * Add an event to the event buffer
1269
1276
  */
1270
1277
  SentryReplay.prototype.addEvent = function (event, isCheckout) {
1271
- var timestampInMs = event.timestamp * 1000;
1278
+ if (!this.eventBuffer) {
1279
+ // This implies that `isEnabled` is false
1280
+ return;
1281
+ }
1282
+ // TODO: sadness -- we will want to normalize timestamps to be in ms -
1283
+ // requires coordination with frontend
1284
+ var isMs = event.timestamp > 9999999999;
1285
+ var timestampInMs = isMs ? event.timestamp : event.timestamp * 1000;
1272
1286
  if (!this.context.earliestEvent ||
1273
1287
  timestampInMs < this.context.earliestEvent) {
1274
1288
  this.context.earliestEvent = timestampInMs;
@@ -1393,7 +1407,6 @@ var SentryReplay = /** @class */ (function () {
1393
1407
  initialState.timestamp = this.context.earliestEvent;
1394
1408
  }
1395
1409
  var context = {
1396
- session: this.session,
1397
1410
  initialState: initialState,
1398
1411
  timestamp: timestamp,
1399
1412
  errorIds: Array.from(this.context.errorIds).filter(Boolean),
@@ -1414,12 +1427,17 @@ var SentryReplay = /** @class */ (function () {
1414
1427
  * due to the buffered performance observer events.
1415
1428
  */
1416
1429
  SentryReplay.prototype.flushUpdate = function () {
1417
- var _a;
1430
+ var _a, _b;
1418
1431
  return __awaiter(this, void 0, void 0, function () {
1419
- var timestamp, recordingData, err_1;
1420
- return __generator(this, function (_b) {
1421
- switch (_b.label) {
1432
+ var timestamp, replayId, newSessionCreated, segmentId, recordingData, err_1;
1433
+ return __generator(this, function (_c) {
1434
+ switch (_c.label) {
1422
1435
  case 0:
1436
+ if (!this.isEnabled) {
1437
+ // This is just a precaution, there should be no listeners that would
1438
+ // cause a flush.
1439
+ return [2 /*return*/];
1440
+ }
1423
1441
  if (!this.checkAndHandleExpiredSession()) {
1424
1442
  logger.error(new Error('Attempting to finish replay event after session expired.'));
1425
1443
  return [2 /*return*/];
@@ -1432,44 +1450,42 @@ var SentryReplay = /** @class */ (function () {
1432
1450
  clearTimeout(this.timeout);
1433
1451
  return [4 /*yield*/, this.addPerformanceEntries()];
1434
1452
  case 1:
1435
- _b.sent();
1436
- if (!this.eventBuffer.length) {
1453
+ _c.sent();
1454
+ if (!((_b = this.eventBuffer) === null || _b === void 0 ? void 0 : _b.length)) {
1437
1455
  return [2 /*return*/];
1438
1456
  }
1439
1457
  // Only attach memory event if eventBuffer is not empty
1440
1458
  return [4 /*yield*/, this.addMemoryEntry()];
1441
1459
  case 2:
1442
1460
  // Only attach memory event if eventBuffer is not empty
1443
- _b.sent();
1461
+ _c.sent();
1444
1462
  timestamp = new Date().getTime();
1445
- // Only want to create replay event if session is new
1446
- if (this.needsCaptureReplay) {
1447
- // This event needs to exist before calling `sendReplay`
1448
- captureReplay(this.popEventContext({ timestamp: timestamp }));
1449
- this.needsCaptureReplay = false;
1450
- }
1463
+ replayId = this.session.id;
1464
+ newSessionCreated = this.newSessionCreated;
1465
+ segmentId = this.session.segmentId++;
1451
1466
  // Reset this to null regardless of `sendReplay` result so that future
1452
1467
  // events will get flushed properly
1453
1468
  this.initialEventTimestampSinceFlush = null;
1454
- _b.label = 3;
1469
+ _c.label = 3;
1455
1470
  case 3:
1456
- _b.trys.push([3, 6, , 7]);
1471
+ _c.trys.push([3, 6, , 7]);
1457
1472
  return [4 /*yield*/, this.eventBuffer.finish()];
1458
1473
  case 4:
1459
- recordingData = _b.sent();
1460
- return [4 /*yield*/, this.sendReplay(this.session.id, recordingData)];
1474
+ recordingData = _c.sent();
1475
+ return [4 /*yield*/, this.sendReplay(replayId, recordingData, segmentId)];
1461
1476
  case 5:
1462
- _b.sent();
1477
+ _c.sent();
1463
1478
  // The below will only happen after successfully sending replay //
1464
1479
  // TBD: Alternatively we could update this after every rrweb event
1465
1480
  // `timestamp` should reflect when the event happens. e.g. the timestamp
1466
1481
  // of the event is passed as an argument in the case where a timeout
1467
1482
  // occurs.
1468
1483
  this.updateLastActivity(timestamp);
1469
- captureReplayUpdate(this.popEventContext({ timestamp: timestamp }));
1484
+ captureReplayEvent(__assign(__assign({}, this.popEventContext({ timestamp: timestamp })), { replayId: replayId, segmentId: segmentId, includeReplayStartTimestamp: newSessionCreated }));
1485
+ this.newSessionCreated = false;
1470
1486
  return [3 /*break*/, 7];
1471
1487
  case 6:
1472
- err_1 = _b.sent();
1488
+ err_1 = _c.sent();
1473
1489
  captureException(err_1);
1474
1490
  console.error(err_1);
1475
1491
  return [3 /*break*/, 7];
@@ -1482,22 +1498,21 @@ var SentryReplay = /** @class */ (function () {
1482
1498
  * Send replay attachment using `fetch()`
1483
1499
  */
1484
1500
  SentryReplay.prototype.sendReplayRequest = function (_a) {
1485
- var _b, _c;
1486
- var endpoint = _a.endpoint, events = _a.events;
1501
+ var endpoint = _a.endpoint, events = _a.events, event_id = _a.replayId, segment_id = _a.segmentId;
1487
1502
  return __awaiter(this, void 0, void 0, function () {
1488
- var payloadWithSequence, envelope, response, _d, _e;
1489
- var _f;
1490
- return __generator(this, function (_g) {
1491
- switch (_g.label) {
1503
+ var payloadWithSequence, envelope, response, _b, _c;
1504
+ var _d;
1505
+ return __generator(this, function (_e) {
1506
+ switch (_e.label) {
1492
1507
  case 0:
1493
1508
  payloadWithSequence = createPayload({
1494
1509
  events: events,
1495
1510
  headers: {
1496
- segment_id: (_b = this.session) === null || _b === void 0 ? void 0 : _b.segmentId,
1511
+ segment_id: segment_id,
1497
1512
  },
1498
1513
  });
1499
1514
  envelope = createEnvelope({
1500
- event_id: (_c = this.session) === null || _c === void 0 ? void 0 : _c.id,
1515
+ event_id: event_id,
1501
1516
  sent_at: new Date().toISOString(),
1502
1517
  sdk: { name: 'sentry.javascript.integration.replay', version: '1.0.0' },
1503
1518
  }, [
@@ -1518,17 +1533,17 @@ var SentryReplay = /** @class */ (function () {
1518
1533
  body: serializeEnvelope(envelope),
1519
1534
  })];
1520
1535
  case 1:
1521
- response = _g.sent();
1536
+ response = _e.sent();
1522
1537
  if (!(response.status !== 200)) return [3 /*break*/, 3];
1523
- _d = setContext;
1524
- _e = ['Send Replay Response'];
1525
- _f = {
1538
+ _b = setContext;
1539
+ _c = ['Send Replay Response'];
1540
+ _d = {
1526
1541
  status: response.status
1527
1542
  };
1528
1543
  return [4 /*yield*/, response.text()];
1529
1544
  case 2:
1530
- _d.apply(void 0, _e.concat([(_f.body = _g.sent(),
1531
- _f)]));
1545
+ _b.apply(void 0, _c.concat([(_d.body = _e.sent(),
1546
+ _d)]));
1532
1547
  throw new Error(UNABLE_TO_SEND_REPLAY);
1533
1548
  case 3: return [2 /*return*/];
1534
1549
  }
@@ -1542,7 +1557,7 @@ var SentryReplay = /** @class */ (function () {
1542
1557
  /**
1543
1558
  * Finalize and send the current replay event to Sentry
1544
1559
  */
1545
- SentryReplay.prototype.sendReplay = function (eventId, events) {
1560
+ SentryReplay.prototype.sendReplay = function (replayId, events, segmentId) {
1546
1561
  return __awaiter(this, void 0, void 0, function () {
1547
1562
  var client, endpoint, ex_1;
1548
1563
  var _this = this;
@@ -1561,6 +1576,8 @@ var SentryReplay = /** @class */ (function () {
1561
1576
  return [4 /*yield*/, this.sendReplayRequest({
1562
1577
  endpoint: endpoint,
1563
1578
  events: events,
1579
+ replayId: replayId,
1580
+ segmentId: segmentId,
1564
1581
  })];
1565
1582
  case 2:
1566
1583
  _b.sent();
@@ -1579,29 +1596,30 @@ var SentryReplay = /** @class */ (function () {
1579
1596
  // failed, we'll can retry with the same events payload
1580
1597
  if (this.retryCount >= MAX_RETRY_COUNT) {
1581
1598
  this.resetRetries();
1582
- return [2 /*return*/, false];
1599
+ throw new Error(UNABLE_TO_SEND_REPLAY);
1583
1600
  }
1584
1601
  this.retryCount = this.retryCount + 1;
1585
- // will retry in intervals of 5, 10, 15, 20, 25 seconds
1602
+ // will retry in intervals of 5, 10, 30
1586
1603
  this.retryInterval = this.retryCount * this.retryInterval;
1587
1604
  _b.label = 4;
1588
1605
  case 4:
1589
1606
  _b.trys.push([4, 6, , 7]);
1590
1607
  return [4 /*yield*/, new Promise(function (resolve, reject) {
1591
1608
  setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
1592
- var result;
1593
- return __generator(this, function (_a) {
1594
- switch (_a.label) {
1595
- case 0: return [4 /*yield*/, this.sendReplay(eventId, events)];
1609
+ return __generator(this, function (_b) {
1610
+ switch (_b.label) {
1611
+ case 0:
1612
+ _b.trys.push([0, 2, , 3]);
1613
+ return [4 /*yield*/, this.sendReplay(replayId, events, segmentId)];
1596
1614
  case 1:
1597
- result = _a.sent();
1598
- if (result) {
1599
- resolve(true);
1600
- }
1601
- else {
1602
- reject(new Error('Could not send replay'));
1603
- }
1604
- return [2 /*return*/];
1615
+ _b.sent();
1616
+ resolve(true);
1617
+ return [3 /*break*/, 3];
1618
+ case 2:
1619
+ _b.sent();
1620
+ reject(new Error(UNABLE_TO_SEND_REPLAY));
1621
+ return [3 /*break*/, 3];
1622
+ case 3: return [2 /*return*/];
1605
1623
  }
1606
1624
  });
1607
1625
  }); }, _this.retryInterval);
@@ -1611,7 +1629,7 @@ var SentryReplay = /** @class */ (function () {
1611
1629
  return [2 /*return*/, true];
1612
1630
  case 6:
1613
1631
  _b.sent();
1614
- return [2 /*return*/, false];
1632
+ throw new Error(UNABLE_TO_SEND_REPLAY);
1615
1633
  case 7: return [3 /*break*/, 8];
1616
1634
  case 8: return [2 /*return*/];
1617
1635
  }