@sentry/replay 0.5.12 → 0.5.15
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/dist/config/types/src/index.d.ts +7 -10
- package/dist/config/types/src/session/constants.d.ts +2 -2
- package/dist/config/types/src/types.d.ts +2 -0
- package/dist/index.es.js +66 -78
- package/dist/index.js +66 -78
- package/dist/index.js.map +1 -1
- package/dist/types/src/api/captureReplayEvent.d.ts +15 -0
- package/dist/types/src/index.d.ts +7 -10
- package/dist/types/src/session/constants.d.ts +2 -2
- package/dist/types/src/types.d.ts +2 -0
- package/package.json +1 -1
- package/dist/types/src/api/captureReplay.d.ts +0 -10
- package/dist/types/src/api/captureReplayUpdate.d.ts +0 -12
package/dist/index.js
CHANGED
|
@@ -95,36 +95,17 @@ function __spreadArray(to, from, pack) {
|
|
|
95
95
|
var REPLAY_SESSION_KEY = 'sentryReplaySession';
|
|
96
96
|
var REPLAY_EVENT_NAME = 'replay_event';
|
|
97
97
|
// The idle limit for a session
|
|
98
|
-
var SESSION_IDLE_DURATION =
|
|
98
|
+
var SESSION_IDLE_DURATION = 300000; // 5 minutes in ms
|
|
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
|
|
103
|
-
var
|
|
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) {
|
|
@@ -544,7 +525,11 @@ function createPaintEntry(entry) {
|
|
|
544
525
|
}
|
|
545
526
|
function createNavigationEntry(entry) {
|
|
546
527
|
// TODO: There looks to be some more interesting bits in here (domComplete, domContentLoaded)
|
|
547
|
-
var entryType = entry.entryType, name = entry.name, domComplete = entry.domComplete, startTime = entry.startTime, transferSize = entry.transferSize, type = entry.type;
|
|
528
|
+
var entryType = entry.entryType, name = entry.name, duration = entry.duration, domComplete = entry.domComplete, startTime = entry.startTime, transferSize = entry.transferSize, type = entry.type;
|
|
529
|
+
// Ignore entries with no duration, they do not seem to be useful and cause dupes
|
|
530
|
+
if (duration === 0) {
|
|
531
|
+
return null;
|
|
532
|
+
}
|
|
548
533
|
return {
|
|
549
534
|
type: "".concat(entryType, ".").concat(type),
|
|
550
535
|
start: getAbsoluteTime(startTime),
|
|
@@ -552,11 +537,12 @@ function createNavigationEntry(entry) {
|
|
|
552
537
|
name: name,
|
|
553
538
|
data: {
|
|
554
539
|
size: transferSize,
|
|
540
|
+
duration: duration,
|
|
555
541
|
},
|
|
556
542
|
};
|
|
557
543
|
}
|
|
558
544
|
function createResourceEntry(entry) {
|
|
559
|
-
var entryType = entry.entryType, initiatorType = entry.initiatorType, name = entry.name, responseEnd = entry.responseEnd, startTime = entry.startTime, transferSize = entry.transferSize;
|
|
545
|
+
var entryType = entry.entryType, initiatorType = entry.initiatorType, name = entry.name, responseEnd = entry.responseEnd, startTime = entry.startTime, encodedBodySize = entry.encodedBodySize, transferSize = entry.transferSize;
|
|
560
546
|
// Do not capture fetches to Sentry ingestion endpoint
|
|
561
547
|
if (isIngestHost(name)) {
|
|
562
548
|
return null;
|
|
@@ -572,6 +558,7 @@ function createResourceEntry(entry) {
|
|
|
572
558
|
name: name,
|
|
573
559
|
data: {
|
|
574
560
|
size: transferSize,
|
|
561
|
+
encodedBodySize: encodedBodySize,
|
|
575
562
|
},
|
|
576
563
|
};
|
|
577
564
|
}
|
|
@@ -584,6 +571,7 @@ function createLargestContentfulPaint(entry) {
|
|
|
584
571
|
start: start,
|
|
585
572
|
end: start + duration,
|
|
586
573
|
data: {
|
|
574
|
+
duration: duration,
|
|
587
575
|
size: size,
|
|
588
576
|
// Not sure why this errors, Node should be correct (Argument of type 'Node' is not assignable to parameter of type 'INode')
|
|
589
577
|
nodeId: rrweb.record.mirror.getId(entry.element),
|
|
@@ -682,7 +670,6 @@ var EventBufferCompressionWorker = /** @class */ (function () {
|
|
|
682
670
|
method: 'addEvent',
|
|
683
671
|
args: [event],
|
|
684
672
|
});
|
|
685
|
-
logger.log('Message posted to worker');
|
|
686
673
|
// XXX: See note in `get length()`
|
|
687
674
|
_this.eventBufferItemLength++;
|
|
688
675
|
return promise;
|
|
@@ -802,7 +789,7 @@ var EventBufferCompressionWorker = /** @class */ (function () {
|
|
|
802
789
|
}());
|
|
803
790
|
|
|
804
791
|
var BASE_RETRY_INTERVAL = 5000;
|
|
805
|
-
var MAX_RETRY_COUNT =
|
|
792
|
+
var MAX_RETRY_COUNT = 3;
|
|
806
793
|
var UNABLE_TO_SEND_REPLAY = 'Unable to send replay';
|
|
807
794
|
var SentryReplay = /** @class */ (function () {
|
|
808
795
|
function SentryReplay(_a) {
|
|
@@ -827,12 +814,10 @@ var SentryReplay = /** @class */ (function () {
|
|
|
827
814
|
this.retryCount = 0;
|
|
828
815
|
this.retryInterval = BASE_RETRY_INTERVAL;
|
|
829
816
|
/**
|
|
830
|
-
* Flag
|
|
831
|
-
*
|
|
832
|
-
* event per session and it should only be created
|
|
833
|
-
* immediately before sending recording)
|
|
817
|
+
* Flag when a new session has been created. Captured replay events behave
|
|
818
|
+
* slightly differently in this case: `replay_start_timestamp` is included.
|
|
834
819
|
*/
|
|
835
|
-
this.
|
|
820
|
+
this.newSessionCreated = false;
|
|
836
821
|
/**
|
|
837
822
|
* Is the integration currently active?
|
|
838
823
|
*/
|
|
@@ -1159,7 +1144,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1159
1144
|
// If session was newly created (i.e. was not loaded from storage), then
|
|
1160
1145
|
// enable flag to create the root replay
|
|
1161
1146
|
if (type === 'new') {
|
|
1162
|
-
this.
|
|
1147
|
+
this.newSessionCreated = true;
|
|
1163
1148
|
this.setInitialState();
|
|
1164
1149
|
}
|
|
1165
1150
|
if (session.id !== ((_b = this.session) === null || _b === void 0 ? void 0 : _b.id)) {
|
|
@@ -1176,6 +1161,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1176
1161
|
var urlPath = "".concat(window.location.pathname).concat(window.location.hash).concat(window.location.search);
|
|
1177
1162
|
var url = "".concat(window.location.origin).concat(urlPath);
|
|
1178
1163
|
this.performanceEvents = [];
|
|
1164
|
+
this.initialEventTimestampSinceFlush = null;
|
|
1179
1165
|
// Reset context as well
|
|
1180
1166
|
this.popEventContext();
|
|
1181
1167
|
this.initialState = {
|
|
@@ -1307,8 +1293,11 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1307
1293
|
// requires coordination with frontend
|
|
1308
1294
|
var isMs = event.timestamp > 9999999999;
|
|
1309
1295
|
var timestampInMs = isMs ? event.timestamp : event.timestamp * 1000;
|
|
1310
|
-
if
|
|
1311
|
-
|
|
1296
|
+
// Only record earliest event if a new session was created, otherwise it
|
|
1297
|
+
// shouldn't be relevant
|
|
1298
|
+
if (this.newSessionCreated &&
|
|
1299
|
+
(!this.context.earliestEvent ||
|
|
1300
|
+
timestampInMs < this.context.earliestEvent)) {
|
|
1312
1301
|
this.context.earliestEvent = timestampInMs;
|
|
1313
1302
|
}
|
|
1314
1303
|
this.eventBuffer.addEvent(event, isCheckout);
|
|
@@ -1431,7 +1420,6 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1431
1420
|
initialState.timestamp = this.context.earliestEvent;
|
|
1432
1421
|
}
|
|
1433
1422
|
var context = {
|
|
1434
|
-
session: this.session,
|
|
1435
1423
|
initialState: initialState,
|
|
1436
1424
|
timestamp: timestamp,
|
|
1437
1425
|
errorIds: Array.from(this.context.errorIds).filter(Boolean),
|
|
@@ -1454,7 +1442,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1454
1442
|
SentryReplay.prototype.flushUpdate = function () {
|
|
1455
1443
|
var _a, _b;
|
|
1456
1444
|
return __awaiter(this, void 0, void 0, function () {
|
|
1457
|
-
var timestamp, recordingData, err_1;
|
|
1445
|
+
var timestamp, replayId, newSessionCreated, segmentId, recordingData, err_1;
|
|
1458
1446
|
return __generator(this, function (_c) {
|
|
1459
1447
|
switch (_c.label) {
|
|
1460
1448
|
case 0:
|
|
@@ -1485,12 +1473,9 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1485
1473
|
// Only attach memory event if eventBuffer is not empty
|
|
1486
1474
|
_c.sent();
|
|
1487
1475
|
timestamp = new Date().getTime();
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
captureReplay(this.popEventContext({ timestamp: timestamp }));
|
|
1492
|
-
this.needsCaptureReplay = false;
|
|
1493
|
-
}
|
|
1476
|
+
replayId = this.session.id;
|
|
1477
|
+
newSessionCreated = this.newSessionCreated;
|
|
1478
|
+
segmentId = this.session.segmentId++;
|
|
1494
1479
|
// Reset this to null regardless of `sendReplay` result so that future
|
|
1495
1480
|
// events will get flushed properly
|
|
1496
1481
|
this.initialEventTimestampSinceFlush = null;
|
|
@@ -1500,7 +1485,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1500
1485
|
return [4 /*yield*/, this.eventBuffer.finish()];
|
|
1501
1486
|
case 4:
|
|
1502
1487
|
recordingData = _c.sent();
|
|
1503
|
-
return [4 /*yield*/, this.sendReplay(
|
|
1488
|
+
return [4 /*yield*/, this.sendReplay(replayId, recordingData, segmentId)];
|
|
1504
1489
|
case 5:
|
|
1505
1490
|
_c.sent();
|
|
1506
1491
|
// The below will only happen after successfully sending replay //
|
|
@@ -1509,7 +1494,8 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1509
1494
|
// of the event is passed as an argument in the case where a timeout
|
|
1510
1495
|
// occurs.
|
|
1511
1496
|
this.updateLastActivity(timestamp);
|
|
1512
|
-
|
|
1497
|
+
captureReplayEvent(__assign(__assign({}, this.popEventContext({ timestamp: timestamp })), { replayId: replayId, segmentId: segmentId, includeReplayStartTimestamp: newSessionCreated }));
|
|
1498
|
+
this.newSessionCreated = false;
|
|
1513
1499
|
return [3 /*break*/, 7];
|
|
1514
1500
|
case 6:
|
|
1515
1501
|
err_1 = _c.sent();
|
|
@@ -1525,22 +1511,21 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1525
1511
|
* Send replay attachment using `fetch()`
|
|
1526
1512
|
*/
|
|
1527
1513
|
SentryReplay.prototype.sendReplayRequest = function (_a) {
|
|
1528
|
-
var
|
|
1529
|
-
var endpoint = _a.endpoint, events = _a.events;
|
|
1514
|
+
var endpoint = _a.endpoint, events = _a.events, event_id = _a.replayId, segment_id = _a.segmentId;
|
|
1530
1515
|
return __awaiter(this, void 0, void 0, function () {
|
|
1531
|
-
var payloadWithSequence, envelope, response,
|
|
1532
|
-
var
|
|
1533
|
-
return __generator(this, function (
|
|
1534
|
-
switch (
|
|
1516
|
+
var payloadWithSequence, envelope, response, _b, _c;
|
|
1517
|
+
var _d;
|
|
1518
|
+
return __generator(this, function (_e) {
|
|
1519
|
+
switch (_e.label) {
|
|
1535
1520
|
case 0:
|
|
1536
1521
|
payloadWithSequence = createPayload({
|
|
1537
1522
|
events: events,
|
|
1538
1523
|
headers: {
|
|
1539
|
-
segment_id:
|
|
1524
|
+
segment_id: segment_id,
|
|
1540
1525
|
},
|
|
1541
1526
|
});
|
|
1542
1527
|
envelope = utils.createEnvelope({
|
|
1543
|
-
event_id:
|
|
1528
|
+
event_id: event_id,
|
|
1544
1529
|
sent_at: new Date().toISOString(),
|
|
1545
1530
|
sdk: { name: 'sentry.javascript.integration.replay', version: '1.0.0' },
|
|
1546
1531
|
}, [
|
|
@@ -1561,17 +1546,17 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1561
1546
|
body: utils.serializeEnvelope(envelope),
|
|
1562
1547
|
})];
|
|
1563
1548
|
case 1:
|
|
1564
|
-
response =
|
|
1549
|
+
response = _e.sent();
|
|
1565
1550
|
if (!(response.status !== 200)) return [3 /*break*/, 3];
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1551
|
+
_b = core.setContext;
|
|
1552
|
+
_c = ['Send Replay Response'];
|
|
1553
|
+
_d = {
|
|
1569
1554
|
status: response.status
|
|
1570
1555
|
};
|
|
1571
1556
|
return [4 /*yield*/, response.text()];
|
|
1572
1557
|
case 2:
|
|
1573
|
-
|
|
1574
|
-
|
|
1558
|
+
_b.apply(void 0, _c.concat([(_d.body = _e.sent(),
|
|
1559
|
+
_d)]));
|
|
1575
1560
|
throw new Error(UNABLE_TO_SEND_REPLAY);
|
|
1576
1561
|
case 3: return [2 /*return*/];
|
|
1577
1562
|
}
|
|
@@ -1585,7 +1570,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1585
1570
|
/**
|
|
1586
1571
|
* Finalize and send the current replay event to Sentry
|
|
1587
1572
|
*/
|
|
1588
|
-
SentryReplay.prototype.sendReplay = function (
|
|
1573
|
+
SentryReplay.prototype.sendReplay = function (replayId, events, segmentId) {
|
|
1589
1574
|
return __awaiter(this, void 0, void 0, function () {
|
|
1590
1575
|
var client, endpoint, ex_1;
|
|
1591
1576
|
var _this = this;
|
|
@@ -1604,6 +1589,8 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1604
1589
|
return [4 /*yield*/, this.sendReplayRequest({
|
|
1605
1590
|
endpoint: endpoint,
|
|
1606
1591
|
events: events,
|
|
1592
|
+
replayId: replayId,
|
|
1593
|
+
segmentId: segmentId,
|
|
1607
1594
|
})];
|
|
1608
1595
|
case 2:
|
|
1609
1596
|
_b.sent();
|
|
@@ -1622,29 +1609,30 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1622
1609
|
// failed, we'll can retry with the same events payload
|
|
1623
1610
|
if (this.retryCount >= MAX_RETRY_COUNT) {
|
|
1624
1611
|
this.resetRetries();
|
|
1625
|
-
|
|
1612
|
+
throw new Error(UNABLE_TO_SEND_REPLAY);
|
|
1626
1613
|
}
|
|
1627
1614
|
this.retryCount = this.retryCount + 1;
|
|
1628
|
-
// will retry in intervals of 5, 10,
|
|
1615
|
+
// will retry in intervals of 5, 10, 30
|
|
1629
1616
|
this.retryInterval = this.retryCount * this.retryInterval;
|
|
1630
1617
|
_b.label = 4;
|
|
1631
1618
|
case 4:
|
|
1632
1619
|
_b.trys.push([4, 6, , 7]);
|
|
1633
1620
|
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
1634
1621
|
setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1622
|
+
return __generator(this, function (_b) {
|
|
1623
|
+
switch (_b.label) {
|
|
1624
|
+
case 0:
|
|
1625
|
+
_b.trys.push([0, 2, , 3]);
|
|
1626
|
+
return [4 /*yield*/, this.sendReplay(replayId, events, segmentId)];
|
|
1639
1627
|
case 1:
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1628
|
+
_b.sent();
|
|
1629
|
+
resolve(true);
|
|
1630
|
+
return [3 /*break*/, 3];
|
|
1631
|
+
case 2:
|
|
1632
|
+
_b.sent();
|
|
1633
|
+
reject(new Error(UNABLE_TO_SEND_REPLAY));
|
|
1634
|
+
return [3 /*break*/, 3];
|
|
1635
|
+
case 3: return [2 /*return*/];
|
|
1648
1636
|
}
|
|
1649
1637
|
});
|
|
1650
1638
|
}); }, _this.retryInterval);
|
|
@@ -1654,7 +1642,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1654
1642
|
return [2 /*return*/, true];
|
|
1655
1643
|
case 6:
|
|
1656
1644
|
_b.sent();
|
|
1657
|
-
|
|
1645
|
+
throw new Error(UNABLE_TO_SEND_REPLAY);
|
|
1658
1646
|
case 7: return [3 /*break*/, 8];
|
|
1659
1647
|
case 8: return [2 /*return*/];
|
|
1660
1648
|
}
|