@sentry/replay 0.5.21 → 0.5.22
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/index.es.js +138 -38
- package/dist/index.js +137 -38
- package/dist/index.js.map +1 -1
- package/dist/{config/types/jest.config.d.ts → jest.config.d.ts} +0 -0
- package/dist/{config/types/jest.setup.d.ts → jest.setup.d.ts} +0 -0
- package/dist/{config/types/src → src}/api/captureReplayEvent.d.ts +0 -0
- package/dist/{config/types/src → src}/coreHandlers/getBreadcrumbHandler.d.ts +0 -0
- package/dist/{config/types/src → src}/coreHandlers/getSpanHandler.d.ts +0 -0
- package/dist/{config/types/src → src}/coreHandlers/handleDom.d.ts +0 -0
- package/dist/{config/types/src → src}/coreHandlers/handleFetch.d.ts +0 -0
- package/dist/{config/types/src → src}/coreHandlers/handleFetch.test.d.ts +0 -0
- package/dist/{config/types/src → src}/coreHandlers/handleHistory.d.ts +0 -0
- package/dist/{config/types/src → src}/coreHandlers/handleScope-unit.test.d.ts +0 -0
- package/dist/{config/types/src → src}/coreHandlers/handleScope.d.ts +0 -0
- package/dist/{config/types/src → src}/coreHandlers/handleScope.test.d.ts +0 -0
- package/dist/{config/types/src → src}/coreHandlers/handleXhr.d.ts +0 -0
- package/dist/{config/types/src → src}/createPerformanceEntry.d.ts +0 -0
- package/dist/{config/types/src → src}/createPerformanceEntry.test.d.ts +0 -0
- package/dist/{config/types/src → src}/eventBuffer.d.ts +0 -0
- package/dist/{config/types/src → src}/eventBuffer.test.d.ts +0 -0
- package/dist/{config/types/src → src}/flags.d.ts +0 -0
- package/dist/{config/types/src → src}/flush.test.d.ts +0 -0
- package/dist/{config/types/src → src}/index-captureOnlyOnError.test.d.ts +0 -0
- package/dist/{config/types/src → src}/index-noSticky.test.d.ts +0 -0
- package/dist/{config/types/src → src}/index-sampling.test.d.ts +0 -0
- package/dist/{config/types/src → src}/index.d.ts +2 -8
- package/dist/{config/types/src → src}/index.test.d.ts +0 -0
- package/dist/{config/types/src → src}/session/Session.d.ts +0 -0
- package/dist/{config/types/src → src}/session/Session.test.d.ts +0 -0
- package/dist/{config/types/src → src}/session/constants.d.ts +0 -0
- package/dist/{config/types/src → src}/session/createSession.d.ts +0 -0
- package/dist/{config/types/src → src}/session/createSession.test.d.ts +0 -0
- package/dist/{config/types/src → src}/session/deleteSession.d.ts +0 -0
- package/dist/{config/types/src → src}/session/deleteSession.test.d.ts +0 -0
- package/dist/{config/types/src → src}/session/fetchSession.d.ts +0 -0
- package/dist/{config/types/src → src}/session/fetchSession.test.d.ts +0 -0
- package/dist/{config/types/src → src}/session/getSession.d.ts +0 -0
- package/dist/{config/types/src → src}/session/getSession.test.d.ts +0 -0
- package/dist/{config/types/src → src}/session/index.d.ts +0 -0
- package/dist/{config/types/src → src}/session/saveSession.d.ts +0 -0
- package/dist/{config/types/src → src}/session/saveSession.test.d.ts +0 -0
- package/dist/{config/types/src → src}/stop.test.d.ts +0 -0
- package/dist/{config/types/src → src}/types.d.ts +3 -0
- package/dist/src/util/addInternalBreadcrumb.d.ts +5 -0
- package/dist/{config/types/src → src}/util/createBreadcrumb.d.ts +0 -0
- package/dist/{config/types/src → src}/util/createPayload.d.ts +0 -0
- package/dist/{config/types/src/util/dedupeNavigationEntries.d.ts → src/util/dedupePerformanceEntries.d.ts} +1 -1
- package/dist/{config/types/src/util/isExpired.test.d.ts → src/util/dedupePerformanceEntries.test.d.ts} +0 -0
- package/dist/{config/types/src → src}/util/isExpired.d.ts +0 -0
- package/dist/{config/types/src/util/isSampled.test.d.ts → src/util/isExpired.test.d.ts} +0 -0
- package/dist/{config/types/src → src}/util/isIngestHost.d.ts +0 -0
- package/dist/src/util/isInternal.d.ts +5 -0
- package/dist/{config/types/src → src}/util/isSampled.d.ts +0 -0
- package/dist/{config/types/src/util/isSessionExpired.test.d.ts → src/util/isSampled.test.d.ts} +0 -0
- package/dist/{config/types/src → src}/util/isSessionExpired.d.ts +0 -0
- package/dist/src/util/isSessionExpired.test.d.ts +1 -0
- package/dist/{config/types/src → src}/util/logger.d.ts +0 -0
- package/dist/test/fixtures/performanceEntry/lcp.d.ts +1 -0
- package/dist/test/fixtures/performanceEntry/navigation.d.ts +1 -0
- package/dist/test/fixtures/performanceEntry/resource.d.ts +1 -0
- package/dist/{config/types/test → test}/index.d.ts +0 -0
- package/dist/{config/types/test → test}/mocks/mockRrweb.d.ts +0 -0
- package/dist/{config/types/test → test}/mocks/mockSdk.d.ts +0 -0
- package/dist/types/src/index.d.ts +2 -8
- package/dist/types/src/types.d.ts +3 -0
- package/dist/types/src/util/addInternalBreadcrumb.d.ts +5 -0
- package/dist/types/src/util/dedupePerformanceEntries.d.ts +10 -0
- package/dist/types/src/util/isInternal.d.ts +5 -0
- package/package.json +1 -2
- package/dist/config/types/src/coreHandlers/handleConsole.d.ts +0 -1
package/dist/index.es.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { captureEvent, getCurrentHub, captureException, addGlobalEventProcessor, setContext, getEnvelopeEndpointWithUrlEncodedAuth } from '@sentry/core';
|
|
1
|
+
import { addBreadcrumb, withScope, captureEvent, getCurrentHub, captureException, addGlobalEventProcessor, setContext, getEnvelopeEndpointWithUrlEncodedAuth } from '@sentry/core';
|
|
2
2
|
import { htmlTreeAsString, logger as logger$1, uuid4, addInstrumentationHandler, createEnvelope, serializeEnvelope } from '@sentry/utils';
|
|
3
3
|
import debounce from 'lodash.debounce';
|
|
4
|
-
import throttle from 'lodash.throttle';
|
|
5
4
|
import { record, EventType } from 'rrweb';
|
|
6
5
|
|
|
7
6
|
/******************************************************************************
|
|
@@ -97,13 +96,40 @@ var SESSION_IDLE_DURATION = 300000; // 5 minutes in ms
|
|
|
97
96
|
// Grace period to keep a session when a user changes tabs or hides window
|
|
98
97
|
var VISIBILITY_CHANGE_TIMEOUT = SESSION_IDLE_DURATION;
|
|
99
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Returns true if we are currently recording an internal to Sentry replay
|
|
101
|
+
* (e.g. on https://sentry.io )
|
|
102
|
+
*/
|
|
103
|
+
function isInternal() {
|
|
104
|
+
return ['sentry.io', 'dev.getsentry.net'].includes(window.location.host);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Wrapper for core SDK's `addBreadcrumb` only when used on `sentry.io`
|
|
109
|
+
*/
|
|
110
|
+
function addInternalBreadcrumb(arg) {
|
|
111
|
+
if (!isInternal()) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
var category = arg.category, level = arg.level, message = arg.message, rest = __rest(arg, ["category", "level", "message"]);
|
|
115
|
+
addBreadcrumb(__assign({ category: category || 'console', level: level || 'debug', message: "[debug]: ".concat(message) }, rest));
|
|
116
|
+
}
|
|
117
|
+
|
|
100
118
|
function captureReplayEvent(_a) {
|
|
101
119
|
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;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
120
|
+
if (segment_id !== 0 && includeReplayStartTimestamp) {
|
|
121
|
+
addInternalBreadcrumb({
|
|
122
|
+
message: "Including replay_start_timestamp on non-initial segment (id: ".concat(segment_id, ")"),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
withScope(function (scope) {
|
|
126
|
+
scope.setTag('replay_sdk_version', "0.5.22");
|
|
127
|
+
captureEvent(__assign(__assign({
|
|
128
|
+
// @ts-expect-error replay_event is a new event type
|
|
129
|
+
type: REPLAY_EVENT_NAME }, (includeReplayStartTimestamp
|
|
130
|
+
? { replay_start_timestamp: initialState.timestamp / 1000 }
|
|
131
|
+
: {})), { timestamp: timestamp / 1000, error_ids: errorIds, trace_ids: traceIds, urls: urls, replay_id: replay_id, segment_id: segment_id }), { event_id: replay_id });
|
|
132
|
+
});
|
|
107
133
|
}
|
|
108
134
|
|
|
109
135
|
function createBreadcrumb(breadcrumb) {
|
|
@@ -167,7 +193,7 @@ function isIngestHost(targetHost) {
|
|
|
167
193
|
var _b = ((_a = getCurrentHub().getClient()) === null || _a === void 0 ? void 0 : _a.getDsn()) || {}, protocol = _b.protocol, host = _b.host;
|
|
168
194
|
// XXX: Special case when this integration is used by Sentry on `sentry.io`
|
|
169
195
|
// We would like to capture network requests made to our ingest endpoints for debugging
|
|
170
|
-
if (
|
|
196
|
+
if (isInternal()) {
|
|
171
197
|
return false;
|
|
172
198
|
}
|
|
173
199
|
return targetHost.startsWith("".concat(protocol, "://").concat(host));
|
|
@@ -493,6 +519,75 @@ function createPayload(_a) {
|
|
|
493
519
|
return payloadWithSequence;
|
|
494
520
|
}
|
|
495
521
|
|
|
522
|
+
var NAVIGATION_ENTRY_KEYS = [
|
|
523
|
+
'name',
|
|
524
|
+
'type',
|
|
525
|
+
'startTime',
|
|
526
|
+
'transferSize',
|
|
527
|
+
'duration',
|
|
528
|
+
];
|
|
529
|
+
function isNavigationEntryEqual(a) {
|
|
530
|
+
return function (b) {
|
|
531
|
+
return NAVIGATION_ENTRY_KEYS.every(function (key) { return a[key] === b[key]; });
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* There are some difficulties diagnosing why there are duplicate navigation
|
|
536
|
+
* entries. We've witnessed several intermittent results:
|
|
537
|
+
* - duplicate entries have duration = 0
|
|
538
|
+
* - duplicate entries are the same object reference
|
|
539
|
+
* - none of the above
|
|
540
|
+
*
|
|
541
|
+
* Compare the values of several keys to determine if the entries are duplicates or not.
|
|
542
|
+
*/
|
|
543
|
+
function dedupePerformanceEntries(currentList, newList) {
|
|
544
|
+
// Partition `currentList` into 3 different lists based on entryType
|
|
545
|
+
var _a = currentList.reduce(function (acc, entry) {
|
|
546
|
+
if (entry.entryType === 'navigation') {
|
|
547
|
+
acc[0].push(entry);
|
|
548
|
+
}
|
|
549
|
+
else if (entry.entryType === 'largest-contentful-paint') {
|
|
550
|
+
acc[1].push(entry);
|
|
551
|
+
}
|
|
552
|
+
else {
|
|
553
|
+
acc[2].push(entry);
|
|
554
|
+
}
|
|
555
|
+
return acc;
|
|
556
|
+
}, [[], [], []]), existingNavigationEntries = _a[0], existingLcpEntries = _a[1], existingEntries = _a[2];
|
|
557
|
+
var newEntries = [];
|
|
558
|
+
var newNavigationEntries = [];
|
|
559
|
+
var newLcpEntry = existingLcpEntries.length
|
|
560
|
+
? existingLcpEntries[existingLcpEntries.length - 1] // Take the last element as list is sorted
|
|
561
|
+
: undefined;
|
|
562
|
+
newList.forEach(function (entry) {
|
|
563
|
+
if (entry.entryType === 'largest-contentful-paint') {
|
|
564
|
+
// We want the latest LCP event only
|
|
565
|
+
if (!newLcpEntry || newLcpEntry.startTime < entry.startTime) {
|
|
566
|
+
newLcpEntry = entry;
|
|
567
|
+
}
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
if (entry.entryType === 'navigation') {
|
|
571
|
+
var navigationEntry = entry;
|
|
572
|
+
// Check if the navigation entry is contained in currentList or newList
|
|
573
|
+
if (
|
|
574
|
+
// Ignore any navigation entries with duration 0, as they are likely duplicates
|
|
575
|
+
entry.duration > 0 &&
|
|
576
|
+
// Ensure new entry does not already exist in existing entries
|
|
577
|
+
!existingNavigationEntries.find(isNavigationEntryEqual(navigationEntry)) &&
|
|
578
|
+
// Ensure new entry does not already exist in new list of navigation entries
|
|
579
|
+
!newNavigationEntries.find(isNavigationEntryEqual(navigationEntry))) {
|
|
580
|
+
newNavigationEntries.push(navigationEntry);
|
|
581
|
+
}
|
|
582
|
+
// Otherwise this navigation entry is considered a duplicate and is thrown away
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
newEntries.push(entry);
|
|
586
|
+
});
|
|
587
|
+
// Re-combine and sort by startTime
|
|
588
|
+
return __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], (newLcpEntry ? [newLcpEntry] : []), true), existingNavigationEntries, true), existingEntries, true), newEntries, true), newNavigationEntries, true).sort(function (a, b) { return a.startTime - b.startTime; });
|
|
589
|
+
}
|
|
590
|
+
|
|
496
591
|
var _a;
|
|
497
592
|
// Map entryType -> function to normalize data for event
|
|
498
593
|
var ENTRY_TYPES = (_a = {
|
|
@@ -847,7 +942,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
847
942
|
* when an error occurs.
|
|
848
943
|
**/
|
|
849
944
|
this.handleGlobalEvent = function (event) {
|
|
850
|
-
var _a, _b;
|
|
945
|
+
var _a, _b, _c, _d;
|
|
851
946
|
// Do not apply replayId to the root event
|
|
852
947
|
if (
|
|
853
948
|
// @ts-expect-error new event type
|
|
@@ -865,6 +960,12 @@ var SentryReplay = /** @class */ (function () {
|
|
|
865
960
|
// XXX: Is it safe to assume that all other events are error events?
|
|
866
961
|
// @ts-expect-error: Type 'undefined' is not assignable to type 'string'.ts(2345)
|
|
867
962
|
_this.context.errorIds.add(event.event_id);
|
|
963
|
+
if (event.exception) {
|
|
964
|
+
var exc = (_d = (_c = event.exception) === null || _c === void 0 ? void 0 : _c.values) === null || _d === void 0 ? void 0 : _d[0];
|
|
965
|
+
addInternalBreadcrumb({
|
|
966
|
+
message: "Tagging event (".concat(event.event_id, ") - ").concat((exc === null || exc === void 0 ? void 0 : exc.type) || 'Unknown', ": ").concat((exc === null || exc === void 0 ? void 0 : exc.value) || 'n/a'),
|
|
967
|
+
});
|
|
968
|
+
}
|
|
868
969
|
// Need to be very careful that this does not cause an infinite loop
|
|
869
970
|
if (_this.options.captureOnlyOnError &&
|
|
870
971
|
event.exception &&
|
|
@@ -1019,8 +1120,8 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1019
1120
|
this.handlePerformanceObserver = function (list) {
|
|
1020
1121
|
// For whatever reason the observer was returning duplicate navigation
|
|
1021
1122
|
// entries (the other entry types were not duplicated).
|
|
1022
|
-
var
|
|
1023
|
-
_this.performanceEvents =
|
|
1123
|
+
var newPerformanceEntries = dedupePerformanceEntries(_this.performanceEvents, list.getEntries());
|
|
1124
|
+
_this.performanceEvents = newPerformanceEntries;
|
|
1024
1125
|
};
|
|
1025
1126
|
/**
|
|
1026
1127
|
* Flush recording data to Sentry. Creates a lock so that only a single flush
|
|
@@ -1045,9 +1146,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1045
1146
|
console.error(new Error('[Sentry]: No transaction, no replay'));
|
|
1046
1147
|
return [2 /*return*/];
|
|
1047
1148
|
}
|
|
1048
|
-
//
|
|
1049
|
-
// We do this regardless of having a queued flush since the event updates
|
|
1050
|
-
// will be handled by queued flush
|
|
1149
|
+
// A flush is about to happen, cancel any queued flushes
|
|
1051
1150
|
(_b = this.debouncedFlush) === null || _b === void 0 ? void 0 : _b.cancel();
|
|
1052
1151
|
if (!!this.flushLock) return [3 /*break*/, 2];
|
|
1053
1152
|
this.flushLock = this.runFlush();
|
|
@@ -1067,22 +1166,12 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1067
1166
|
console.error(err_1);
|
|
1068
1167
|
return [3 /*break*/, 6];
|
|
1069
1168
|
case 5:
|
|
1070
|
-
this.
|
|
1169
|
+
this.debouncedFlush();
|
|
1071
1170
|
return [7 /*endfinally*/];
|
|
1072
1171
|
case 6: return [2 /*return*/];
|
|
1073
1172
|
}
|
|
1074
1173
|
});
|
|
1075
1174
|
}); };
|
|
1076
|
-
/**
|
|
1077
|
-
* A throttled `flush()` that is called after a flush is completed and there
|
|
1078
|
-
* are other queued flushes.
|
|
1079
|
-
*
|
|
1080
|
-
* Instead of calling a flush for every <n> queued flush, condense it to a single call
|
|
1081
|
-
*/
|
|
1082
|
-
this.throttledFlush = throttle(this.flush, 1000, {
|
|
1083
|
-
leading: false,
|
|
1084
|
-
trailing: true,
|
|
1085
|
-
});
|
|
1086
1175
|
this.recordingOptions = __assign({ maskAllInputs: maskAllInputs, blockClass: blockClass, ignoreClass: ignoreClass, maskTextClass: maskTextClass }, recordingOptions);
|
|
1087
1176
|
this.options = {
|
|
1088
1177
|
flushMinDelay: flushMinDelay,
|
|
@@ -1179,6 +1268,8 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1179
1268
|
if (cbResult === true) {
|
|
1180
1269
|
return;
|
|
1181
1270
|
}
|
|
1271
|
+
// addUpdate is called quite frequently - use debouncedFlush so that it
|
|
1272
|
+
// respects the flush delays and does not flush immediately
|
|
1182
1273
|
this.debouncedFlush();
|
|
1183
1274
|
};
|
|
1184
1275
|
/**
|
|
@@ -1512,50 +1603,56 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1512
1603
|
*
|
|
1513
1604
|
* Performance events are only added right before flushing - this is
|
|
1514
1605
|
* due to the buffered performance observer events.
|
|
1606
|
+
*
|
|
1607
|
+
* Should never be called directly, only by `flush`
|
|
1515
1608
|
*/
|
|
1516
1609
|
SentryReplay.prototype.runFlush = function () {
|
|
1517
|
-
var _a;
|
|
1610
|
+
var _a, _b, _c;
|
|
1518
1611
|
return __awaiter(this, void 0, void 0, function () {
|
|
1519
|
-
var replayId, newSessionCreated, segmentId, recordingData, err_2;
|
|
1520
|
-
return __generator(this, function (
|
|
1521
|
-
switch (
|
|
1612
|
+
var stack, replayId, newSessionCreated, segmentId, recordingData, err_2;
|
|
1613
|
+
return __generator(this, function (_d) {
|
|
1614
|
+
switch (_d.label) {
|
|
1522
1615
|
case 0:
|
|
1616
|
+
stack = ((_a = new Error('trace').stack) === null || _a === void 0 ? void 0 : _a.split('\n')) || [];
|
|
1617
|
+
addInternalBreadcrumb({
|
|
1618
|
+
message: "runFlush (".concat((_b = this.session) === null || _b === void 0 ? void 0 : _b.segmentId, ")\n\n").concat(stack.slice(1).join('\n')),
|
|
1619
|
+
});
|
|
1523
1620
|
if (!this.session) {
|
|
1524
1621
|
console.error(new Error('[Sentry]: No transaction, no replay'));
|
|
1525
1622
|
return [2 /*return*/];
|
|
1526
1623
|
}
|
|
1527
1624
|
return [4 /*yield*/, this.addPerformanceEntries()];
|
|
1528
1625
|
case 1:
|
|
1529
|
-
|
|
1530
|
-
if (!((
|
|
1626
|
+
_d.sent();
|
|
1627
|
+
if (!((_c = this.eventBuffer) === null || _c === void 0 ? void 0 : _c.length)) {
|
|
1531
1628
|
return [2 /*return*/];
|
|
1532
1629
|
}
|
|
1533
1630
|
// Only attach memory event if eventBuffer is not empty
|
|
1534
1631
|
return [4 /*yield*/, this.addMemoryEntry()];
|
|
1535
1632
|
case 2:
|
|
1536
1633
|
// Only attach memory event if eventBuffer is not empty
|
|
1537
|
-
|
|
1634
|
+
_d.sent();
|
|
1538
1635
|
replayId = this.session.id;
|
|
1539
1636
|
newSessionCreated = this.newSessionCreated;
|
|
1540
1637
|
segmentId = this.session.segmentId++;
|
|
1541
1638
|
// Reset this to null regardless of `sendReplay` result so that future
|
|
1542
1639
|
// events will get flushed properly
|
|
1543
1640
|
this.initialEventTimestampSinceFlush = null;
|
|
1544
|
-
|
|
1641
|
+
_d.label = 3;
|
|
1545
1642
|
case 3:
|
|
1546
|
-
|
|
1643
|
+
_d.trys.push([3, 6, , 7]);
|
|
1547
1644
|
return [4 /*yield*/, this.eventBuffer.finish()];
|
|
1548
1645
|
case 4:
|
|
1549
|
-
recordingData =
|
|
1646
|
+
recordingData = _d.sent();
|
|
1550
1647
|
return [4 /*yield*/, this.sendReplay(replayId, recordingData, segmentId)];
|
|
1551
1648
|
case 5:
|
|
1552
|
-
|
|
1649
|
+
_d.sent();
|
|
1553
1650
|
// The below will only happen after successfully sending replay //
|
|
1554
1651
|
captureReplayEvent(__assign(__assign({}, this.popEventContext({ timestamp: new Date().getTime() })), { replayId: replayId, segmentId: segmentId, includeReplayStartTimestamp: newSessionCreated }));
|
|
1555
1652
|
this.newSessionCreated = false;
|
|
1556
1653
|
return [3 /*break*/, 7];
|
|
1557
1654
|
case 6:
|
|
1558
|
-
err_2 =
|
|
1655
|
+
err_2 = _d.sent();
|
|
1559
1656
|
captureException(err_2);
|
|
1560
1657
|
console.error(err_2);
|
|
1561
1658
|
return [3 /*break*/, 7];
|
|
@@ -1584,7 +1681,10 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1584
1681
|
envelope = createEnvelope({
|
|
1585
1682
|
event_id: event_id,
|
|
1586
1683
|
sent_at: new Date().toISOString(),
|
|
1587
|
-
sdk: {
|
|
1684
|
+
sdk: {
|
|
1685
|
+
name: 'sentry.javascript.integration.replay',
|
|
1686
|
+
version: "0.5.22",
|
|
1687
|
+
},
|
|
1588
1688
|
}, [
|
|
1589
1689
|
[
|
|
1590
1690
|
{
|
package/dist/index.js
CHANGED
|
@@ -5,13 +5,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var core = require('@sentry/core');
|
|
6
6
|
var utils = require('@sentry/utils');
|
|
7
7
|
var debounce = require('lodash.debounce');
|
|
8
|
-
var throttle = require('lodash.throttle');
|
|
9
8
|
var rrweb = require('rrweb');
|
|
10
9
|
|
|
11
10
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
11
|
|
|
13
12
|
var debounce__default = /*#__PURE__*/_interopDefaultLegacy(debounce);
|
|
14
|
-
var throttle__default = /*#__PURE__*/_interopDefaultLegacy(throttle);
|
|
15
13
|
|
|
16
14
|
/******************************************************************************
|
|
17
15
|
Copyright (c) Microsoft Corporation.
|
|
@@ -106,13 +104,40 @@ var SESSION_IDLE_DURATION = 300000; // 5 minutes in ms
|
|
|
106
104
|
// Grace period to keep a session when a user changes tabs or hides window
|
|
107
105
|
var VISIBILITY_CHANGE_TIMEOUT = SESSION_IDLE_DURATION;
|
|
108
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Returns true if we are currently recording an internal to Sentry replay
|
|
109
|
+
* (e.g. on https://sentry.io )
|
|
110
|
+
*/
|
|
111
|
+
function isInternal() {
|
|
112
|
+
return ['sentry.io', 'dev.getsentry.net'].includes(window.location.host);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Wrapper for core SDK's `addBreadcrumb` only when used on `sentry.io`
|
|
117
|
+
*/
|
|
118
|
+
function addInternalBreadcrumb(arg) {
|
|
119
|
+
if (!isInternal()) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
var category = arg.category, level = arg.level, message = arg.message, rest = __rest(arg, ["category", "level", "message"]);
|
|
123
|
+
core.addBreadcrumb(__assign({ category: category || 'console', level: level || 'debug', message: "[debug]: ".concat(message) }, rest));
|
|
124
|
+
}
|
|
125
|
+
|
|
109
126
|
function captureReplayEvent(_a) {
|
|
110
127
|
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;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
128
|
+
if (segment_id !== 0 && includeReplayStartTimestamp) {
|
|
129
|
+
addInternalBreadcrumb({
|
|
130
|
+
message: "Including replay_start_timestamp on non-initial segment (id: ".concat(segment_id, ")"),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
core.withScope(function (scope) {
|
|
134
|
+
scope.setTag('replay_sdk_version', "0.5.22");
|
|
135
|
+
core.captureEvent(__assign(__assign({
|
|
136
|
+
// @ts-expect-error replay_event is a new event type
|
|
137
|
+
type: REPLAY_EVENT_NAME }, (includeReplayStartTimestamp
|
|
138
|
+
? { replay_start_timestamp: initialState.timestamp / 1000 }
|
|
139
|
+
: {})), { timestamp: timestamp / 1000, error_ids: errorIds, trace_ids: traceIds, urls: urls, replay_id: replay_id, segment_id: segment_id }), { event_id: replay_id });
|
|
140
|
+
});
|
|
116
141
|
}
|
|
117
142
|
|
|
118
143
|
function createBreadcrumb(breadcrumb) {
|
|
@@ -176,7 +201,7 @@ function isIngestHost(targetHost) {
|
|
|
176
201
|
var _b = ((_a = core.getCurrentHub().getClient()) === null || _a === void 0 ? void 0 : _a.getDsn()) || {}, protocol = _b.protocol, host = _b.host;
|
|
177
202
|
// XXX: Special case when this integration is used by Sentry on `sentry.io`
|
|
178
203
|
// We would like to capture network requests made to our ingest endpoints for debugging
|
|
179
|
-
if (
|
|
204
|
+
if (isInternal()) {
|
|
180
205
|
return false;
|
|
181
206
|
}
|
|
182
207
|
return targetHost.startsWith("".concat(protocol, "://").concat(host));
|
|
@@ -502,6 +527,75 @@ function createPayload(_a) {
|
|
|
502
527
|
return payloadWithSequence;
|
|
503
528
|
}
|
|
504
529
|
|
|
530
|
+
var NAVIGATION_ENTRY_KEYS = [
|
|
531
|
+
'name',
|
|
532
|
+
'type',
|
|
533
|
+
'startTime',
|
|
534
|
+
'transferSize',
|
|
535
|
+
'duration',
|
|
536
|
+
];
|
|
537
|
+
function isNavigationEntryEqual(a) {
|
|
538
|
+
return function (b) {
|
|
539
|
+
return NAVIGATION_ENTRY_KEYS.every(function (key) { return a[key] === b[key]; });
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* There are some difficulties diagnosing why there are duplicate navigation
|
|
544
|
+
* entries. We've witnessed several intermittent results:
|
|
545
|
+
* - duplicate entries have duration = 0
|
|
546
|
+
* - duplicate entries are the same object reference
|
|
547
|
+
* - none of the above
|
|
548
|
+
*
|
|
549
|
+
* Compare the values of several keys to determine if the entries are duplicates or not.
|
|
550
|
+
*/
|
|
551
|
+
function dedupePerformanceEntries(currentList, newList) {
|
|
552
|
+
// Partition `currentList` into 3 different lists based on entryType
|
|
553
|
+
var _a = currentList.reduce(function (acc, entry) {
|
|
554
|
+
if (entry.entryType === 'navigation') {
|
|
555
|
+
acc[0].push(entry);
|
|
556
|
+
}
|
|
557
|
+
else if (entry.entryType === 'largest-contentful-paint') {
|
|
558
|
+
acc[1].push(entry);
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
acc[2].push(entry);
|
|
562
|
+
}
|
|
563
|
+
return acc;
|
|
564
|
+
}, [[], [], []]), existingNavigationEntries = _a[0], existingLcpEntries = _a[1], existingEntries = _a[2];
|
|
565
|
+
var newEntries = [];
|
|
566
|
+
var newNavigationEntries = [];
|
|
567
|
+
var newLcpEntry = existingLcpEntries.length
|
|
568
|
+
? existingLcpEntries[existingLcpEntries.length - 1] // Take the last element as list is sorted
|
|
569
|
+
: undefined;
|
|
570
|
+
newList.forEach(function (entry) {
|
|
571
|
+
if (entry.entryType === 'largest-contentful-paint') {
|
|
572
|
+
// We want the latest LCP event only
|
|
573
|
+
if (!newLcpEntry || newLcpEntry.startTime < entry.startTime) {
|
|
574
|
+
newLcpEntry = entry;
|
|
575
|
+
}
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
if (entry.entryType === 'navigation') {
|
|
579
|
+
var navigationEntry = entry;
|
|
580
|
+
// Check if the navigation entry is contained in currentList or newList
|
|
581
|
+
if (
|
|
582
|
+
// Ignore any navigation entries with duration 0, as they are likely duplicates
|
|
583
|
+
entry.duration > 0 &&
|
|
584
|
+
// Ensure new entry does not already exist in existing entries
|
|
585
|
+
!existingNavigationEntries.find(isNavigationEntryEqual(navigationEntry)) &&
|
|
586
|
+
// Ensure new entry does not already exist in new list of navigation entries
|
|
587
|
+
!newNavigationEntries.find(isNavigationEntryEqual(navigationEntry))) {
|
|
588
|
+
newNavigationEntries.push(navigationEntry);
|
|
589
|
+
}
|
|
590
|
+
// Otherwise this navigation entry is considered a duplicate and is thrown away
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
newEntries.push(entry);
|
|
594
|
+
});
|
|
595
|
+
// Re-combine and sort by startTime
|
|
596
|
+
return __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], (newLcpEntry ? [newLcpEntry] : []), true), existingNavigationEntries, true), existingEntries, true), newEntries, true), newNavigationEntries, true).sort(function (a, b) { return a.startTime - b.startTime; });
|
|
597
|
+
}
|
|
598
|
+
|
|
505
599
|
var _a;
|
|
506
600
|
// Map entryType -> function to normalize data for event
|
|
507
601
|
var ENTRY_TYPES = (_a = {
|
|
@@ -856,7 +950,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
856
950
|
* when an error occurs.
|
|
857
951
|
**/
|
|
858
952
|
this.handleGlobalEvent = function (event) {
|
|
859
|
-
var _a, _b;
|
|
953
|
+
var _a, _b, _c, _d;
|
|
860
954
|
// Do not apply replayId to the root event
|
|
861
955
|
if (
|
|
862
956
|
// @ts-expect-error new event type
|
|
@@ -874,6 +968,12 @@ var SentryReplay = /** @class */ (function () {
|
|
|
874
968
|
// XXX: Is it safe to assume that all other events are error events?
|
|
875
969
|
// @ts-expect-error: Type 'undefined' is not assignable to type 'string'.ts(2345)
|
|
876
970
|
_this.context.errorIds.add(event.event_id);
|
|
971
|
+
if (event.exception) {
|
|
972
|
+
var exc = (_d = (_c = event.exception) === null || _c === void 0 ? void 0 : _c.values) === null || _d === void 0 ? void 0 : _d[0];
|
|
973
|
+
addInternalBreadcrumb({
|
|
974
|
+
message: "Tagging event (".concat(event.event_id, ") - ").concat((exc === null || exc === void 0 ? void 0 : exc.type) || 'Unknown', ": ").concat((exc === null || exc === void 0 ? void 0 : exc.value) || 'n/a'),
|
|
975
|
+
});
|
|
976
|
+
}
|
|
877
977
|
// Need to be very careful that this does not cause an infinite loop
|
|
878
978
|
if (_this.options.captureOnlyOnError &&
|
|
879
979
|
event.exception &&
|
|
@@ -1028,8 +1128,8 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1028
1128
|
this.handlePerformanceObserver = function (list) {
|
|
1029
1129
|
// For whatever reason the observer was returning duplicate navigation
|
|
1030
1130
|
// entries (the other entry types were not duplicated).
|
|
1031
|
-
var
|
|
1032
|
-
_this.performanceEvents =
|
|
1131
|
+
var newPerformanceEntries = dedupePerformanceEntries(_this.performanceEvents, list.getEntries());
|
|
1132
|
+
_this.performanceEvents = newPerformanceEntries;
|
|
1033
1133
|
};
|
|
1034
1134
|
/**
|
|
1035
1135
|
* Flush recording data to Sentry. Creates a lock so that only a single flush
|
|
@@ -1054,9 +1154,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1054
1154
|
console.error(new Error('[Sentry]: No transaction, no replay'));
|
|
1055
1155
|
return [2 /*return*/];
|
|
1056
1156
|
}
|
|
1057
|
-
//
|
|
1058
|
-
// We do this regardless of having a queued flush since the event updates
|
|
1059
|
-
// will be handled by queued flush
|
|
1157
|
+
// A flush is about to happen, cancel any queued flushes
|
|
1060
1158
|
(_b = this.debouncedFlush) === null || _b === void 0 ? void 0 : _b.cancel();
|
|
1061
1159
|
if (!!this.flushLock) return [3 /*break*/, 2];
|
|
1062
1160
|
this.flushLock = this.runFlush();
|
|
@@ -1076,22 +1174,12 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1076
1174
|
console.error(err_1);
|
|
1077
1175
|
return [3 /*break*/, 6];
|
|
1078
1176
|
case 5:
|
|
1079
|
-
this.
|
|
1177
|
+
this.debouncedFlush();
|
|
1080
1178
|
return [7 /*endfinally*/];
|
|
1081
1179
|
case 6: return [2 /*return*/];
|
|
1082
1180
|
}
|
|
1083
1181
|
});
|
|
1084
1182
|
}); };
|
|
1085
|
-
/**
|
|
1086
|
-
* A throttled `flush()` that is called after a flush is completed and there
|
|
1087
|
-
* are other queued flushes.
|
|
1088
|
-
*
|
|
1089
|
-
* Instead of calling a flush for every <n> queued flush, condense it to a single call
|
|
1090
|
-
*/
|
|
1091
|
-
this.throttledFlush = throttle__default["default"](this.flush, 1000, {
|
|
1092
|
-
leading: false,
|
|
1093
|
-
trailing: true,
|
|
1094
|
-
});
|
|
1095
1183
|
this.recordingOptions = __assign({ maskAllInputs: maskAllInputs, blockClass: blockClass, ignoreClass: ignoreClass, maskTextClass: maskTextClass }, recordingOptions);
|
|
1096
1184
|
this.options = {
|
|
1097
1185
|
flushMinDelay: flushMinDelay,
|
|
@@ -1188,6 +1276,8 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1188
1276
|
if (cbResult === true) {
|
|
1189
1277
|
return;
|
|
1190
1278
|
}
|
|
1279
|
+
// addUpdate is called quite frequently - use debouncedFlush so that it
|
|
1280
|
+
// respects the flush delays and does not flush immediately
|
|
1191
1281
|
this.debouncedFlush();
|
|
1192
1282
|
};
|
|
1193
1283
|
/**
|
|
@@ -1521,50 +1611,56 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1521
1611
|
*
|
|
1522
1612
|
* Performance events are only added right before flushing - this is
|
|
1523
1613
|
* due to the buffered performance observer events.
|
|
1614
|
+
*
|
|
1615
|
+
* Should never be called directly, only by `flush`
|
|
1524
1616
|
*/
|
|
1525
1617
|
SentryReplay.prototype.runFlush = function () {
|
|
1526
|
-
var _a;
|
|
1618
|
+
var _a, _b, _c;
|
|
1527
1619
|
return __awaiter(this, void 0, void 0, function () {
|
|
1528
|
-
var replayId, newSessionCreated, segmentId, recordingData, err_2;
|
|
1529
|
-
return __generator(this, function (
|
|
1530
|
-
switch (
|
|
1620
|
+
var stack, replayId, newSessionCreated, segmentId, recordingData, err_2;
|
|
1621
|
+
return __generator(this, function (_d) {
|
|
1622
|
+
switch (_d.label) {
|
|
1531
1623
|
case 0:
|
|
1624
|
+
stack = ((_a = new Error('trace').stack) === null || _a === void 0 ? void 0 : _a.split('\n')) || [];
|
|
1625
|
+
addInternalBreadcrumb({
|
|
1626
|
+
message: "runFlush (".concat((_b = this.session) === null || _b === void 0 ? void 0 : _b.segmentId, ")\n\n").concat(stack.slice(1).join('\n')),
|
|
1627
|
+
});
|
|
1532
1628
|
if (!this.session) {
|
|
1533
1629
|
console.error(new Error('[Sentry]: No transaction, no replay'));
|
|
1534
1630
|
return [2 /*return*/];
|
|
1535
1631
|
}
|
|
1536
1632
|
return [4 /*yield*/, this.addPerformanceEntries()];
|
|
1537
1633
|
case 1:
|
|
1538
|
-
|
|
1539
|
-
if (!((
|
|
1634
|
+
_d.sent();
|
|
1635
|
+
if (!((_c = this.eventBuffer) === null || _c === void 0 ? void 0 : _c.length)) {
|
|
1540
1636
|
return [2 /*return*/];
|
|
1541
1637
|
}
|
|
1542
1638
|
// Only attach memory event if eventBuffer is not empty
|
|
1543
1639
|
return [4 /*yield*/, this.addMemoryEntry()];
|
|
1544
1640
|
case 2:
|
|
1545
1641
|
// Only attach memory event if eventBuffer is not empty
|
|
1546
|
-
|
|
1642
|
+
_d.sent();
|
|
1547
1643
|
replayId = this.session.id;
|
|
1548
1644
|
newSessionCreated = this.newSessionCreated;
|
|
1549
1645
|
segmentId = this.session.segmentId++;
|
|
1550
1646
|
// Reset this to null regardless of `sendReplay` result so that future
|
|
1551
1647
|
// events will get flushed properly
|
|
1552
1648
|
this.initialEventTimestampSinceFlush = null;
|
|
1553
|
-
|
|
1649
|
+
_d.label = 3;
|
|
1554
1650
|
case 3:
|
|
1555
|
-
|
|
1651
|
+
_d.trys.push([3, 6, , 7]);
|
|
1556
1652
|
return [4 /*yield*/, this.eventBuffer.finish()];
|
|
1557
1653
|
case 4:
|
|
1558
|
-
recordingData =
|
|
1654
|
+
recordingData = _d.sent();
|
|
1559
1655
|
return [4 /*yield*/, this.sendReplay(replayId, recordingData, segmentId)];
|
|
1560
1656
|
case 5:
|
|
1561
|
-
|
|
1657
|
+
_d.sent();
|
|
1562
1658
|
// The below will only happen after successfully sending replay //
|
|
1563
1659
|
captureReplayEvent(__assign(__assign({}, this.popEventContext({ timestamp: new Date().getTime() })), { replayId: replayId, segmentId: segmentId, includeReplayStartTimestamp: newSessionCreated }));
|
|
1564
1660
|
this.newSessionCreated = false;
|
|
1565
1661
|
return [3 /*break*/, 7];
|
|
1566
1662
|
case 6:
|
|
1567
|
-
err_2 =
|
|
1663
|
+
err_2 = _d.sent();
|
|
1568
1664
|
core.captureException(err_2);
|
|
1569
1665
|
console.error(err_2);
|
|
1570
1666
|
return [3 /*break*/, 7];
|
|
@@ -1593,7 +1689,10 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1593
1689
|
envelope = utils.createEnvelope({
|
|
1594
1690
|
event_id: event_id,
|
|
1595
1691
|
sent_at: new Date().toISOString(),
|
|
1596
|
-
sdk: {
|
|
1692
|
+
sdk: {
|
|
1693
|
+
name: 'sentry.javascript.integration.replay',
|
|
1694
|
+
version: "0.5.22",
|
|
1695
|
+
},
|
|
1597
1696
|
}, [
|
|
1598
1697
|
[
|
|
1599
1698
|
{
|