@sentry/replay 0.5.12 → 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.
@@ -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';
@@ -42,12 +41,10 @@ export declare class SentryReplay implements Integration {
42
41
  private retryCount;
43
42
  private retryInterval;
44
43
  /**
45
- * Flag to make sure we only create a replay event when
46
- * necessary (i.e. we only want to have a single replay
47
- * event per session and it should only be created
48
- * 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.
49
46
  */
50
- private needsCaptureReplay;
47
+ private newSessionCreated;
51
48
  /**
52
49
  * Is the integration currently active?
53
50
  */
@@ -217,7 +214,7 @@ export declare class SentryReplay implements Integration {
217
214
  */
218
215
  popEventContext({ timestamp, }?: {
219
216
  timestamp?: number;
220
- }): CaptureReplayParams & CaptureReplayUpdateParams;
217
+ }): CaptureReplayEventParams;
221
218
  /**
222
219
  * Flushes replay event buffer to Sentry.
223
220
  *
@@ -228,11 +225,11 @@ export declare class SentryReplay implements Integration {
228
225
  /**
229
226
  * Send replay attachment using `fetch()`
230
227
  */
231
- sendReplayRequest({ endpoint, events }: ReplayRequest): Promise<void>;
228
+ sendReplayRequest({ endpoint, events, replayId: event_id, segmentId: segment_id, }: ReplayRequest): Promise<void>;
232
229
  resetRetries(): void;
233
230
  /**
234
231
  * Finalize and send the current replay event to Sentry
235
232
  */
236
- sendReplay(eventId: string, events: RecordedEvents): Promise<boolean | undefined>;
233
+ sendReplay(replayId: string, events: RecordedEvents, segmentId: number): Promise<true | undefined>;
237
234
  }
238
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';
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) {
@@ -798,7 +779,7 @@ var EventBufferCompressionWorker = /** @class */ (function () {
798
779
  }());
799
780
 
800
781
  var BASE_RETRY_INTERVAL = 5000;
801
- var MAX_RETRY_COUNT = 5;
782
+ var MAX_RETRY_COUNT = 3;
802
783
  var UNABLE_TO_SEND_REPLAY = 'Unable to send replay';
803
784
  var SentryReplay = /** @class */ (function () {
804
785
  function SentryReplay(_a) {
@@ -823,12 +804,10 @@ var SentryReplay = /** @class */ (function () {
823
804
  this.retryCount = 0;
824
805
  this.retryInterval = BASE_RETRY_INTERVAL;
825
806
  /**
826
- * Flag to make sure we only create a replay event when
827
- * necessary (i.e. we only want to have a single replay
828
- * event per session and it should only be created
829
- * 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.
830
809
  */
831
- this.needsCaptureReplay = false;
810
+ this.newSessionCreated = false;
832
811
  /**
833
812
  * Is the integration currently active?
834
813
  */
@@ -1017,6 +996,7 @@ var SentryReplay = /** @class */ (function () {
1017
996
  // For whatever reason the observer was returning duplicate navigation
1018
997
  // entries (the other entry types were not duplicated).
1019
998
  var newEntries = new Set(list.getEntries());
999
+ console.log(list.getEntries());
1020
1000
  _this.performanceEvents = __spreadArray(__spreadArray([], _this.performanceEvents, true), Array.from(newEntries), true);
1021
1001
  };
1022
1002
  this.recordingOptions = __assign({ maskAllInputs: maskAllInputs, blockClass: blockClass, ignoreClass: ignoreClass, maskTextClass: maskTextClass }, recordingOptions);
@@ -1155,7 +1135,7 @@ var SentryReplay = /** @class */ (function () {
1155
1135
  // If session was newly created (i.e. was not loaded from storage), then
1156
1136
  // enable flag to create the root replay
1157
1137
  if (type === 'new') {
1158
- this.needsCaptureReplay = true;
1138
+ this.newSessionCreated = true;
1159
1139
  this.setInitialState();
1160
1140
  }
1161
1141
  if (session.id !== ((_b = this.session) === null || _b === void 0 ? void 0 : _b.id)) {
@@ -1427,7 +1407,6 @@ var SentryReplay = /** @class */ (function () {
1427
1407
  initialState.timestamp = this.context.earliestEvent;
1428
1408
  }
1429
1409
  var context = {
1430
- session: this.session,
1431
1410
  initialState: initialState,
1432
1411
  timestamp: timestamp,
1433
1412
  errorIds: Array.from(this.context.errorIds).filter(Boolean),
@@ -1450,7 +1429,7 @@ var SentryReplay = /** @class */ (function () {
1450
1429
  SentryReplay.prototype.flushUpdate = function () {
1451
1430
  var _a, _b;
1452
1431
  return __awaiter(this, void 0, void 0, function () {
1453
- var timestamp, recordingData, err_1;
1432
+ var timestamp, replayId, newSessionCreated, segmentId, recordingData, err_1;
1454
1433
  return __generator(this, function (_c) {
1455
1434
  switch (_c.label) {
1456
1435
  case 0:
@@ -1481,12 +1460,9 @@ var SentryReplay = /** @class */ (function () {
1481
1460
  // Only attach memory event if eventBuffer is not empty
1482
1461
  _c.sent();
1483
1462
  timestamp = new Date().getTime();
1484
- // Only want to create replay event if session is new
1485
- if (this.needsCaptureReplay) {
1486
- // This event needs to exist before calling `sendReplay`
1487
- captureReplay(this.popEventContext({ timestamp: timestamp }));
1488
- this.needsCaptureReplay = false;
1489
- }
1463
+ replayId = this.session.id;
1464
+ newSessionCreated = this.newSessionCreated;
1465
+ segmentId = this.session.segmentId++;
1490
1466
  // Reset this to null regardless of `sendReplay` result so that future
1491
1467
  // events will get flushed properly
1492
1468
  this.initialEventTimestampSinceFlush = null;
@@ -1496,7 +1472,7 @@ var SentryReplay = /** @class */ (function () {
1496
1472
  return [4 /*yield*/, this.eventBuffer.finish()];
1497
1473
  case 4:
1498
1474
  recordingData = _c.sent();
1499
- return [4 /*yield*/, this.sendReplay(this.session.id, recordingData)];
1475
+ return [4 /*yield*/, this.sendReplay(replayId, recordingData, segmentId)];
1500
1476
  case 5:
1501
1477
  _c.sent();
1502
1478
  // The below will only happen after successfully sending replay //
@@ -1505,7 +1481,8 @@ var SentryReplay = /** @class */ (function () {
1505
1481
  // of the event is passed as an argument in the case where a timeout
1506
1482
  // occurs.
1507
1483
  this.updateLastActivity(timestamp);
1508
- captureReplayUpdate(this.popEventContext({ timestamp: timestamp }));
1484
+ captureReplayEvent(__assign(__assign({}, this.popEventContext({ timestamp: timestamp })), { replayId: replayId, segmentId: segmentId, includeReplayStartTimestamp: newSessionCreated }));
1485
+ this.newSessionCreated = false;
1509
1486
  return [3 /*break*/, 7];
1510
1487
  case 6:
1511
1488
  err_1 = _c.sent();
@@ -1521,22 +1498,21 @@ var SentryReplay = /** @class */ (function () {
1521
1498
  * Send replay attachment using `fetch()`
1522
1499
  */
1523
1500
  SentryReplay.prototype.sendReplayRequest = function (_a) {
1524
- var _b, _c;
1525
- var endpoint = _a.endpoint, events = _a.events;
1501
+ var endpoint = _a.endpoint, events = _a.events, event_id = _a.replayId, segment_id = _a.segmentId;
1526
1502
  return __awaiter(this, void 0, void 0, function () {
1527
- var payloadWithSequence, envelope, response, _d, _e;
1528
- var _f;
1529
- return __generator(this, function (_g) {
1530
- switch (_g.label) {
1503
+ var payloadWithSequence, envelope, response, _b, _c;
1504
+ var _d;
1505
+ return __generator(this, function (_e) {
1506
+ switch (_e.label) {
1531
1507
  case 0:
1532
1508
  payloadWithSequence = createPayload({
1533
1509
  events: events,
1534
1510
  headers: {
1535
- segment_id: (_b = this.session) === null || _b === void 0 ? void 0 : _b.segmentId,
1511
+ segment_id: segment_id,
1536
1512
  },
1537
1513
  });
1538
1514
  envelope = createEnvelope({
1539
- event_id: (_c = this.session) === null || _c === void 0 ? void 0 : _c.id,
1515
+ event_id: event_id,
1540
1516
  sent_at: new Date().toISOString(),
1541
1517
  sdk: { name: 'sentry.javascript.integration.replay', version: '1.0.0' },
1542
1518
  }, [
@@ -1557,17 +1533,17 @@ var SentryReplay = /** @class */ (function () {
1557
1533
  body: serializeEnvelope(envelope),
1558
1534
  })];
1559
1535
  case 1:
1560
- response = _g.sent();
1536
+ response = _e.sent();
1561
1537
  if (!(response.status !== 200)) return [3 /*break*/, 3];
1562
- _d = setContext;
1563
- _e = ['Send Replay Response'];
1564
- _f = {
1538
+ _b = setContext;
1539
+ _c = ['Send Replay Response'];
1540
+ _d = {
1565
1541
  status: response.status
1566
1542
  };
1567
1543
  return [4 /*yield*/, response.text()];
1568
1544
  case 2:
1569
- _d.apply(void 0, _e.concat([(_f.body = _g.sent(),
1570
- _f)]));
1545
+ _b.apply(void 0, _c.concat([(_d.body = _e.sent(),
1546
+ _d)]));
1571
1547
  throw new Error(UNABLE_TO_SEND_REPLAY);
1572
1548
  case 3: return [2 /*return*/];
1573
1549
  }
@@ -1581,7 +1557,7 @@ var SentryReplay = /** @class */ (function () {
1581
1557
  /**
1582
1558
  * Finalize and send the current replay event to Sentry
1583
1559
  */
1584
- SentryReplay.prototype.sendReplay = function (eventId, events) {
1560
+ SentryReplay.prototype.sendReplay = function (replayId, events, segmentId) {
1585
1561
  return __awaiter(this, void 0, void 0, function () {
1586
1562
  var client, endpoint, ex_1;
1587
1563
  var _this = this;
@@ -1600,6 +1576,8 @@ var SentryReplay = /** @class */ (function () {
1600
1576
  return [4 /*yield*/, this.sendReplayRequest({
1601
1577
  endpoint: endpoint,
1602
1578
  events: events,
1579
+ replayId: replayId,
1580
+ segmentId: segmentId,
1603
1581
  })];
1604
1582
  case 2:
1605
1583
  _b.sent();
@@ -1618,29 +1596,30 @@ var SentryReplay = /** @class */ (function () {
1618
1596
  // failed, we'll can retry with the same events payload
1619
1597
  if (this.retryCount >= MAX_RETRY_COUNT) {
1620
1598
  this.resetRetries();
1621
- return [2 /*return*/, false];
1599
+ throw new Error(UNABLE_TO_SEND_REPLAY);
1622
1600
  }
1623
1601
  this.retryCount = this.retryCount + 1;
1624
- // will retry in intervals of 5, 10, 15, 20, 25 seconds
1602
+ // will retry in intervals of 5, 10, 30
1625
1603
  this.retryInterval = this.retryCount * this.retryInterval;
1626
1604
  _b.label = 4;
1627
1605
  case 4:
1628
1606
  _b.trys.push([4, 6, , 7]);
1629
1607
  return [4 /*yield*/, new Promise(function (resolve, reject) {
1630
1608
  setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
1631
- var result;
1632
- return __generator(this, function (_a) {
1633
- switch (_a.label) {
1634
- 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)];
1635
1614
  case 1:
1636
- result = _a.sent();
1637
- if (result) {
1638
- resolve(true);
1639
- }
1640
- else {
1641
- reject(new Error('Could not send replay'));
1642
- }
1643
- 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*/];
1644
1623
  }
1645
1624
  });
1646
1625
  }); }, _this.retryInterval);
@@ -1650,7 +1629,7 @@ var SentryReplay = /** @class */ (function () {
1650
1629
  return [2 /*return*/, true];
1651
1630
  case 6:
1652
1631
  _b.sent();
1653
- return [2 /*return*/, false];
1632
+ throw new Error(UNABLE_TO_SEND_REPLAY);
1654
1633
  case 7: return [3 /*break*/, 8];
1655
1634
  case 8: return [2 /*return*/];
1656
1635
  }
package/dist/index.js CHANGED
@@ -99,32 +99,13 @@ var SESSION_IDLE_DURATION = 900000; // 15 minutes
99
99
  // Grace period to keep a session when a user changes tabs or hides window
100
100
  var VISIBILITY_CHANGE_TIMEOUT = SESSION_IDLE_DURATION;
101
101
 
102
- function captureReplay(_a) {
103
- var session = _a.session, initialState = _a.initialState, errorIds = _a.errorIds, traceIds = _a.traceIds, urls = _a.urls;
104
- core.captureEvent({
102
+ function captureReplayEvent(_a) {
103
+ 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;
104
+ core.captureEvent(__assign(__assign(__assign({
105
105
  // @ts-expect-error replay_event is a new event type
106
- type: REPLAY_EVENT_NAME,
107
- replay_start_timestamp: initialState.timestamp / 1000,
108
- error_ids: errorIds,
109
- trace_ids: traceIds,
110
- urls: urls,
111
- replay_id: session.id,
112
- segment_id: session.segmentId, // TODO: Should this increment?
113
- }, { event_id: session.id });
114
- }
115
-
116
- function captureReplayUpdate(_a) {
117
- var session = _a.session, timestamp = _a.timestamp, errorIds = _a.errorIds, traceIds = _a.traceIds, urls = _a.urls;
118
- core.captureEvent({
119
- // @ts-expect-error replay_event is a new event type
120
- type: REPLAY_EVENT_NAME,
121
- timestamp: timestamp / 1000,
122
- error_ids: errorIds,
123
- trace_ids: traceIds,
124
- urls: urls,
125
- replay_id: session.id,
126
- segment_id: ++session.segmentId,
127
- });
106
+ type: REPLAY_EVENT_NAME }, (includeReplayStartTimestamp
107
+ ? { replay_start_timestamp: initialState.timestamp / 1000 }
108
+ : {})), (timestamp ? { timestamp: timestamp / 1000 } : {})), { error_ids: errorIds, trace_ids: traceIds, urls: urls, replay_id: replay_id, segment_id: segment_id }), { event_id: replay_id });
128
109
  }
129
110
 
130
111
  function createBreadcrumb(breadcrumb) {
@@ -802,7 +783,7 @@ var EventBufferCompressionWorker = /** @class */ (function () {
802
783
  }());
803
784
 
804
785
  var BASE_RETRY_INTERVAL = 5000;
805
- var MAX_RETRY_COUNT = 5;
786
+ var MAX_RETRY_COUNT = 3;
806
787
  var UNABLE_TO_SEND_REPLAY = 'Unable to send replay';
807
788
  var SentryReplay = /** @class */ (function () {
808
789
  function SentryReplay(_a) {
@@ -827,12 +808,10 @@ var SentryReplay = /** @class */ (function () {
827
808
  this.retryCount = 0;
828
809
  this.retryInterval = BASE_RETRY_INTERVAL;
829
810
  /**
830
- * Flag to make sure we only create a replay event when
831
- * necessary (i.e. we only want to have a single replay
832
- * event per session and it should only be created
833
- * immediately before sending recording)
811
+ * Flag when a new session has been created. Captured replay events behave
812
+ * slightly differently in this case: `replay_start_timestamp` is included.
834
813
  */
835
- this.needsCaptureReplay = false;
814
+ this.newSessionCreated = false;
836
815
  /**
837
816
  * Is the integration currently active?
838
817
  */
@@ -1021,6 +1000,7 @@ var SentryReplay = /** @class */ (function () {
1021
1000
  // For whatever reason the observer was returning duplicate navigation
1022
1001
  // entries (the other entry types were not duplicated).
1023
1002
  var newEntries = new Set(list.getEntries());
1003
+ console.log(list.getEntries());
1024
1004
  _this.performanceEvents = __spreadArray(__spreadArray([], _this.performanceEvents, true), Array.from(newEntries), true);
1025
1005
  };
1026
1006
  this.recordingOptions = __assign({ maskAllInputs: maskAllInputs, blockClass: blockClass, ignoreClass: ignoreClass, maskTextClass: maskTextClass }, recordingOptions);
@@ -1159,7 +1139,7 @@ var SentryReplay = /** @class */ (function () {
1159
1139
  // If session was newly created (i.e. was not loaded from storage), then
1160
1140
  // enable flag to create the root replay
1161
1141
  if (type === 'new') {
1162
- this.needsCaptureReplay = true;
1142
+ this.newSessionCreated = true;
1163
1143
  this.setInitialState();
1164
1144
  }
1165
1145
  if (session.id !== ((_b = this.session) === null || _b === void 0 ? void 0 : _b.id)) {
@@ -1431,7 +1411,6 @@ var SentryReplay = /** @class */ (function () {
1431
1411
  initialState.timestamp = this.context.earliestEvent;
1432
1412
  }
1433
1413
  var context = {
1434
- session: this.session,
1435
1414
  initialState: initialState,
1436
1415
  timestamp: timestamp,
1437
1416
  errorIds: Array.from(this.context.errorIds).filter(Boolean),
@@ -1454,7 +1433,7 @@ var SentryReplay = /** @class */ (function () {
1454
1433
  SentryReplay.prototype.flushUpdate = function () {
1455
1434
  var _a, _b;
1456
1435
  return __awaiter(this, void 0, void 0, function () {
1457
- var timestamp, recordingData, err_1;
1436
+ var timestamp, replayId, newSessionCreated, segmentId, recordingData, err_1;
1458
1437
  return __generator(this, function (_c) {
1459
1438
  switch (_c.label) {
1460
1439
  case 0:
@@ -1485,12 +1464,9 @@ var SentryReplay = /** @class */ (function () {
1485
1464
  // Only attach memory event if eventBuffer is not empty
1486
1465
  _c.sent();
1487
1466
  timestamp = new Date().getTime();
1488
- // Only want to create replay event if session is new
1489
- if (this.needsCaptureReplay) {
1490
- // This event needs to exist before calling `sendReplay`
1491
- captureReplay(this.popEventContext({ timestamp: timestamp }));
1492
- this.needsCaptureReplay = false;
1493
- }
1467
+ replayId = this.session.id;
1468
+ newSessionCreated = this.newSessionCreated;
1469
+ segmentId = this.session.segmentId++;
1494
1470
  // Reset this to null regardless of `sendReplay` result so that future
1495
1471
  // events will get flushed properly
1496
1472
  this.initialEventTimestampSinceFlush = null;
@@ -1500,7 +1476,7 @@ var SentryReplay = /** @class */ (function () {
1500
1476
  return [4 /*yield*/, this.eventBuffer.finish()];
1501
1477
  case 4:
1502
1478
  recordingData = _c.sent();
1503
- return [4 /*yield*/, this.sendReplay(this.session.id, recordingData)];
1479
+ return [4 /*yield*/, this.sendReplay(replayId, recordingData, segmentId)];
1504
1480
  case 5:
1505
1481
  _c.sent();
1506
1482
  // The below will only happen after successfully sending replay //
@@ -1509,7 +1485,8 @@ var SentryReplay = /** @class */ (function () {
1509
1485
  // of the event is passed as an argument in the case where a timeout
1510
1486
  // occurs.
1511
1487
  this.updateLastActivity(timestamp);
1512
- captureReplayUpdate(this.popEventContext({ timestamp: timestamp }));
1488
+ captureReplayEvent(__assign(__assign({}, this.popEventContext({ timestamp: timestamp })), { replayId: replayId, segmentId: segmentId, includeReplayStartTimestamp: newSessionCreated }));
1489
+ this.newSessionCreated = false;
1513
1490
  return [3 /*break*/, 7];
1514
1491
  case 6:
1515
1492
  err_1 = _c.sent();
@@ -1525,22 +1502,21 @@ var SentryReplay = /** @class */ (function () {
1525
1502
  * Send replay attachment using `fetch()`
1526
1503
  */
1527
1504
  SentryReplay.prototype.sendReplayRequest = function (_a) {
1528
- var _b, _c;
1529
- var endpoint = _a.endpoint, events = _a.events;
1505
+ var endpoint = _a.endpoint, events = _a.events, event_id = _a.replayId, segment_id = _a.segmentId;
1530
1506
  return __awaiter(this, void 0, void 0, function () {
1531
- var payloadWithSequence, envelope, response, _d, _e;
1532
- var _f;
1533
- return __generator(this, function (_g) {
1534
- switch (_g.label) {
1507
+ var payloadWithSequence, envelope, response, _b, _c;
1508
+ var _d;
1509
+ return __generator(this, function (_e) {
1510
+ switch (_e.label) {
1535
1511
  case 0:
1536
1512
  payloadWithSequence = createPayload({
1537
1513
  events: events,
1538
1514
  headers: {
1539
- segment_id: (_b = this.session) === null || _b === void 0 ? void 0 : _b.segmentId,
1515
+ segment_id: segment_id,
1540
1516
  },
1541
1517
  });
1542
1518
  envelope = utils.createEnvelope({
1543
- event_id: (_c = this.session) === null || _c === void 0 ? void 0 : _c.id,
1519
+ event_id: event_id,
1544
1520
  sent_at: new Date().toISOString(),
1545
1521
  sdk: { name: 'sentry.javascript.integration.replay', version: '1.0.0' },
1546
1522
  }, [
@@ -1561,17 +1537,17 @@ var SentryReplay = /** @class */ (function () {
1561
1537
  body: utils.serializeEnvelope(envelope),
1562
1538
  })];
1563
1539
  case 1:
1564
- response = _g.sent();
1540
+ response = _e.sent();
1565
1541
  if (!(response.status !== 200)) return [3 /*break*/, 3];
1566
- _d = core.setContext;
1567
- _e = ['Send Replay Response'];
1568
- _f = {
1542
+ _b = core.setContext;
1543
+ _c = ['Send Replay Response'];
1544
+ _d = {
1569
1545
  status: response.status
1570
1546
  };
1571
1547
  return [4 /*yield*/, response.text()];
1572
1548
  case 2:
1573
- _d.apply(void 0, _e.concat([(_f.body = _g.sent(),
1574
- _f)]));
1549
+ _b.apply(void 0, _c.concat([(_d.body = _e.sent(),
1550
+ _d)]));
1575
1551
  throw new Error(UNABLE_TO_SEND_REPLAY);
1576
1552
  case 3: return [2 /*return*/];
1577
1553
  }
@@ -1585,7 +1561,7 @@ var SentryReplay = /** @class */ (function () {
1585
1561
  /**
1586
1562
  * Finalize and send the current replay event to Sentry
1587
1563
  */
1588
- SentryReplay.prototype.sendReplay = function (eventId, events) {
1564
+ SentryReplay.prototype.sendReplay = function (replayId, events, segmentId) {
1589
1565
  return __awaiter(this, void 0, void 0, function () {
1590
1566
  var client, endpoint, ex_1;
1591
1567
  var _this = this;
@@ -1604,6 +1580,8 @@ var SentryReplay = /** @class */ (function () {
1604
1580
  return [4 /*yield*/, this.sendReplayRequest({
1605
1581
  endpoint: endpoint,
1606
1582
  events: events,
1583
+ replayId: replayId,
1584
+ segmentId: segmentId,
1607
1585
  })];
1608
1586
  case 2:
1609
1587
  _b.sent();
@@ -1622,29 +1600,30 @@ var SentryReplay = /** @class */ (function () {
1622
1600
  // failed, we'll can retry with the same events payload
1623
1601
  if (this.retryCount >= MAX_RETRY_COUNT) {
1624
1602
  this.resetRetries();
1625
- return [2 /*return*/, false];
1603
+ throw new Error(UNABLE_TO_SEND_REPLAY);
1626
1604
  }
1627
1605
  this.retryCount = this.retryCount + 1;
1628
- // will retry in intervals of 5, 10, 15, 20, 25 seconds
1606
+ // will retry in intervals of 5, 10, 30
1629
1607
  this.retryInterval = this.retryCount * this.retryInterval;
1630
1608
  _b.label = 4;
1631
1609
  case 4:
1632
1610
  _b.trys.push([4, 6, , 7]);
1633
1611
  return [4 /*yield*/, new Promise(function (resolve, reject) {
1634
1612
  setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
1635
- var result;
1636
- return __generator(this, function (_a) {
1637
- switch (_a.label) {
1638
- case 0: return [4 /*yield*/, this.sendReplay(eventId, events)];
1613
+ return __generator(this, function (_b) {
1614
+ switch (_b.label) {
1615
+ case 0:
1616
+ _b.trys.push([0, 2, , 3]);
1617
+ return [4 /*yield*/, this.sendReplay(replayId, events, segmentId)];
1639
1618
  case 1:
1640
- result = _a.sent();
1641
- if (result) {
1642
- resolve(true);
1643
- }
1644
- else {
1645
- reject(new Error('Could not send replay'));
1646
- }
1647
- return [2 /*return*/];
1619
+ _b.sent();
1620
+ resolve(true);
1621
+ return [3 /*break*/, 3];
1622
+ case 2:
1623
+ _b.sent();
1624
+ reject(new Error(UNABLE_TO_SEND_REPLAY));
1625
+ return [3 /*break*/, 3];
1626
+ case 3: return [2 /*return*/];
1648
1627
  }
1649
1628
  });
1650
1629
  }); }, _this.retryInterval);
@@ -1654,7 +1633,7 @@ var SentryReplay = /** @class */ (function () {
1654
1633
  return [2 /*return*/, true];
1655
1634
  case 6:
1656
1635
  _b.sent();
1657
- return [2 /*return*/, false];
1636
+ throw new Error(UNABLE_TO_SEND_REPLAY);
1658
1637
  case 7: return [3 /*break*/, 8];
1659
1638
  case 8: return [2 /*return*/];
1660
1639
  }