@sentry/replay 0.5.5 → 0.5.6
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 +78 -48
- package/dist/index.js +78 -48
- package/dist/index.js.map +1 -1
- package/dist/jest.config.d.ts +3 -0
- package/dist/jest.setup.d.ts +10 -0
- package/dist/{types/src → src}/api/captureReplay.d.ts +0 -0
- package/dist/{types/src → src}/api/captureReplayUpdate.d.ts +0 -0
- package/dist/{types/src → src}/coreHandlers/getBreadcrumbHandler.d.ts +0 -0
- package/dist/{types/src → src}/coreHandlers/getSpanHandler.d.ts +0 -0
- package/dist/{types/src → src}/coreHandlers/handleDom.d.ts +0 -0
- package/dist/{types/src → src}/coreHandlers/handleFetch.d.ts +1 -1
- package/dist/src/coreHandlers/handleFetch.test.d.ts +1 -0
- package/dist/{types/src → src}/coreHandlers/handleHistory.d.ts +0 -0
- package/dist/src/coreHandlers/handleScope-unit.test.d.ts +1 -0
- package/dist/{types/src → src}/coreHandlers/handleScope.d.ts +0 -0
- package/dist/src/coreHandlers/handleScope.test.d.ts +1 -0
- package/dist/{types/src → src}/coreHandlers/handleXhr.d.ts +2 -2
- package/dist/{types/src → src}/createPerformanceEntry.d.ts +0 -0
- package/dist/src/createPerformanceEntry.test.d.ts +1 -0
- package/dist/{types/src → src}/eventBuffer.d.ts +0 -0
- package/dist/src/eventBuffer.test.d.ts +1 -0
- package/dist/{types/src → src}/flags.d.ts +0 -0
- package/dist/src/index-captureOnlyOnError.test.d.ts +1 -0
- package/dist/src/index-noSticky.test.d.ts +1 -0
- package/dist/src/index-sampling.test.d.ts +1 -0
- package/dist/{types/src → src}/index.d.ts +0 -0
- package/dist/src/index.test.d.ts +1 -0
- package/dist/{types/src → src}/session/Session.d.ts +2 -2
- package/dist/src/session/Session.test.d.ts +1 -0
- package/dist/{types/src → src}/session/constants.d.ts +0 -0
- package/dist/{types/src → src}/session/createSession.d.ts +0 -0
- package/dist/src/session/createSession.test.d.ts +1 -0
- package/dist/{types/src → src}/session/fetchSession.d.ts +0 -0
- package/dist/src/session/fetchSession.test.d.ts +1 -0
- package/dist/{types/src → src}/session/getSession.d.ts +0 -0
- package/dist/src/session/getSession.test.d.ts +1 -0
- package/dist/{types/src → src}/session/index.d.ts +0 -0
- package/dist/{types/src → src}/session/saveSession.d.ts +0 -0
- package/dist/src/session/saveSession.test.d.ts +1 -0
- package/dist/{types/src → src}/types.d.ts +0 -0
- package/dist/{types/src → src}/util/createBreadcrumb.d.ts +0 -0
- package/dist/{types/src → src}/util/createPayload.d.ts +0 -0
- package/dist/{types/src → src}/util/isExpired.d.ts +1 -1
- package/dist/src/util/isExpired.test.d.ts +1 -0
- package/dist/{types/src → src}/util/isIngestHost.d.ts +0 -0
- package/dist/{types/src → src}/util/isSampled.d.ts +0 -0
- package/dist/src/util/isSampled.test.d.ts +1 -0
- package/dist/{types/src → src}/util/isSessionExpired.d.ts +0 -0
- package/dist/src/util/isSessionExpired.test.d.ts +1 -0
- package/dist/{types/src → src}/util/logger.d.ts +0 -0
- package/dist/test/index.d.ts +3 -0
- package/dist/test/mocks/mockRrweb.d.ts +15 -0
- package/dist/test/mocks/mockSdk.d.ts +11 -0
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -180,7 +180,8 @@ function getBreadcrumbHandler(type) {
|
|
|
180
180
|
* Checks is `targetHost` is a Sentry ingestion host
|
|
181
181
|
*/
|
|
182
182
|
function isIngestHost(targetHost) {
|
|
183
|
-
var _a
|
|
183
|
+
var _a;
|
|
184
|
+
var _b = ((_a = getCurrentHub().getClient()) === null || _a === void 0 ? void 0 : _a.getDsn()) || {}, protocol = _b.protocol, host = _b.host;
|
|
184
185
|
return targetHost.startsWith("".concat(protocol, "://").concat(host));
|
|
185
186
|
}
|
|
186
187
|
|
|
@@ -220,6 +221,7 @@ function handleHistory(handlerData) {
|
|
|
220
221
|
}
|
|
221
222
|
|
|
222
223
|
function handleXhr(handlerData) {
|
|
224
|
+
var _a;
|
|
223
225
|
if (handlerData.xhr.__sentry_own_request__) {
|
|
224
226
|
// Taken from sentry-javascript
|
|
225
227
|
// Only capture non-sentry requests
|
|
@@ -227,20 +229,21 @@ function handleXhr(handlerData) {
|
|
|
227
229
|
}
|
|
228
230
|
if (handlerData.startTimestamp) {
|
|
229
231
|
// TODO: See if this is still needed
|
|
232
|
+
handlerData.xhr.__sentry_xhr__ = handlerData.xhr.__sentry_xhr__ || {};
|
|
230
233
|
handlerData.xhr.__sentry_xhr__.startTimestamp = handlerData.startTimestamp;
|
|
231
234
|
}
|
|
232
235
|
if (!handlerData.endTimestamp) {
|
|
233
236
|
return null;
|
|
234
237
|
}
|
|
235
|
-
var
|
|
238
|
+
var _b = handlerData.xhr.__sentry_xhr__ || {}, method = _b.method, url = _b.url, statusCode = _b.status_code;
|
|
236
239
|
// Do not capture fetches to Sentry ingestion endpoint
|
|
237
|
-
if (isIngestHost(url)) {
|
|
240
|
+
if (url === undefined || isIngestHost(url)) {
|
|
238
241
|
return null;
|
|
239
242
|
}
|
|
240
243
|
return {
|
|
241
244
|
type: 'resource.xhr',
|
|
242
245
|
name: url,
|
|
243
|
-
start: handlerData.xhr.__sentry_xhr__.startTimestamp / 1000 ||
|
|
246
|
+
start: (((_a = handlerData.xhr.__sentry_xhr__) === null || _a === void 0 ? void 0 : _a.startTimestamp) || 0) / 1000 ||
|
|
244
247
|
handlerData.endTimestamp / 1000.0,
|
|
245
248
|
end: handlerData.endTimestamp / 1000.0,
|
|
246
249
|
data: {
|
|
@@ -267,7 +270,7 @@ function getSpanHandler(type) {
|
|
|
267
270
|
function isExpired(initialTime, expiry, targetTime) {
|
|
268
271
|
if (targetTime === void 0) { targetTime = +new Date(); }
|
|
269
272
|
// Always expired if < 0
|
|
270
|
-
if (expiry < 0) {
|
|
273
|
+
if (initialTime === null || expiry === undefined || expiry < 0) {
|
|
271
274
|
return true;
|
|
272
275
|
}
|
|
273
276
|
// Never expires if == 0
|
|
@@ -282,7 +285,7 @@ function isExpired(initialTime, expiry, targetTime) {
|
|
|
282
285
|
*/
|
|
283
286
|
function isSessionExpired(session, expiry, targetTime) {
|
|
284
287
|
if (targetTime === void 0) { targetTime = +new Date(); }
|
|
285
|
-
return isExpired(session.lastActivity, expiry, targetTime);
|
|
288
|
+
return isExpired(session === null || session === void 0 ? void 0 : session.lastActivity, expiry, targetTime);
|
|
286
289
|
}
|
|
287
290
|
|
|
288
291
|
function wrapLogger(logFn) {
|
|
@@ -431,7 +434,9 @@ function fetchSession() {
|
|
|
431
434
|
return null;
|
|
432
435
|
}
|
|
433
436
|
try {
|
|
434
|
-
return new Session(
|
|
437
|
+
return new Session(
|
|
438
|
+
// @ts-expect-error: Type 'null' is not assignable to type 'string'.ts(2345)
|
|
439
|
+
JSON.parse(window.sessionStorage.getItem(REPLAY_SESSION_KEY)),
|
|
435
440
|
// We are assuming that if there is a saved item, then the session is sticky,
|
|
436
441
|
// however this could break down if we used a different storage mechanism (e.g. localstorage)
|
|
437
442
|
{ stickySession: true });
|
|
@@ -493,7 +498,9 @@ var ENTRY_TYPES = (_a = {
|
|
|
493
498
|
_a['largest-contentful-paint'] = createLargestContentfulPaint,
|
|
494
499
|
_a);
|
|
495
500
|
function createPerformanceEntries(entries) {
|
|
496
|
-
return entries
|
|
501
|
+
return entries
|
|
502
|
+
.map(createPerformanceEntry)
|
|
503
|
+
.filter(Boolean);
|
|
497
504
|
}
|
|
498
505
|
function createPerformanceEntry(entry) {
|
|
499
506
|
if (ENTRY_TYPES[entry.entryType] === undefined) {
|
|
@@ -687,7 +694,9 @@ var EventBufferCompressionWorker = /** @class */ (function () {
|
|
|
687
694
|
var _this = this;
|
|
688
695
|
var id = _a.id, method = _a.method, args = _a.args;
|
|
689
696
|
return new Promise(function (resolve, reject) {
|
|
697
|
+
var _a, _b;
|
|
690
698
|
var listener = function (_a) {
|
|
699
|
+
var _b;
|
|
691
700
|
var data = _a.data;
|
|
692
701
|
if (data.method !== method) {
|
|
693
702
|
return;
|
|
@@ -698,7 +707,7 @@ var EventBufferCompressionWorker = /** @class */ (function () {
|
|
|
698
707
|
return;
|
|
699
708
|
}
|
|
700
709
|
// At this point, we'll always want to remove listener regardless of result status
|
|
701
|
-
_this.worker.removeEventListener('message', listener);
|
|
710
|
+
(_b = _this.worker) === null || _b === void 0 ? void 0 : _b.removeEventListener('message', listener);
|
|
702
711
|
if (!data.success) {
|
|
703
712
|
// TODO: Do some error handling, not sure what
|
|
704
713
|
logger.error(data.response);
|
|
@@ -709,8 +718,8 @@ var EventBufferCompressionWorker = /** @class */ (function () {
|
|
|
709
718
|
};
|
|
710
719
|
// Note: we can't use `once` option because it's possible it needs to
|
|
711
720
|
// listen to multiple messages
|
|
712
|
-
_this.worker.addEventListener('message', listener);
|
|
713
|
-
_this.worker.postMessage({ id: id, method: method, args: args });
|
|
721
|
+
(_a = _this.worker) === null || _a === void 0 ? void 0 : _a.addEventListener('message', listener);
|
|
722
|
+
(_b = _this.worker) === null || _b === void 0 ? void 0 : _b.postMessage({ id: id, method: method, args: args });
|
|
714
723
|
});
|
|
715
724
|
};
|
|
716
725
|
EventBufferCompressionWorker.prototype.init = function () {
|
|
@@ -718,8 +727,9 @@ var EventBufferCompressionWorker = /** @class */ (function () {
|
|
|
718
727
|
logger.log('Initialized compression worker');
|
|
719
728
|
};
|
|
720
729
|
EventBufferCompressionWorker.prototype.destroy = function () {
|
|
730
|
+
var _a;
|
|
721
731
|
logger.log('Destroying compression worker');
|
|
722
|
-
this.worker.terminate();
|
|
732
|
+
(_a = this.worker) === null || _a === void 0 ? void 0 : _a.terminate();
|
|
723
733
|
this.worker = null;
|
|
724
734
|
};
|
|
725
735
|
Object.defineProperty(EventBufferCompressionWorker.prototype, "length", {
|
|
@@ -812,7 +822,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
812
822
|
* when an error occurs.
|
|
813
823
|
**/
|
|
814
824
|
this.handleGlobalEvent = function (event) {
|
|
815
|
-
var _a;
|
|
825
|
+
var _a, _b;
|
|
816
826
|
// Do not apply replayId to the root event
|
|
817
827
|
if (
|
|
818
828
|
// @ts-expect-error new event type
|
|
@@ -822,12 +832,13 @@ var SentryReplay = /** @class */ (function () {
|
|
|
822
832
|
delete event.breadcrumbs;
|
|
823
833
|
return event;
|
|
824
834
|
}
|
|
825
|
-
event.tags = __assign(__assign({}, event.tags), { replayId: _this.session.id });
|
|
835
|
+
event.tags = __assign(__assign({}, event.tags), { replayId: (_a = _this.session) === null || _a === void 0 ? void 0 : _a.id });
|
|
826
836
|
if (event.type === 'transaction') {
|
|
827
|
-
_this.context.traceIds.add(String(((
|
|
837
|
+
_this.context.traceIds.add(String(((_b = event.contexts) === null || _b === void 0 ? void 0 : _b.trace.trace_id) || ''));
|
|
828
838
|
return event;
|
|
829
839
|
}
|
|
830
840
|
// XXX: Is it safe to assume that all other events are error events?
|
|
841
|
+
// @ts-expect-error: Type 'undefined' is not assignable to type 'string'.ts(2345)
|
|
831
842
|
_this.context.errorIds.add(event.event_id);
|
|
832
843
|
// Need to be very careful that this does not cause an infinite loop
|
|
833
844
|
if (_this.options.captureOnlyOnError &&
|
|
@@ -852,6 +863,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
852
863
|
return;
|
|
853
864
|
}
|
|
854
865
|
_this.addUpdate(function () {
|
|
866
|
+
var _a;
|
|
855
867
|
// We need to clear existing events on a checkout, otherwise they are
|
|
856
868
|
// incremental event updates and should be appended
|
|
857
869
|
_this.addEvent(event, isCheckout);
|
|
@@ -866,7 +878,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
866
878
|
// of the previous session. Do not immediately flush in this case
|
|
867
879
|
// to avoid capturing only the checkout and instead the replay will
|
|
868
880
|
// be captured if they perform any follow-up actions.
|
|
869
|
-
if (_this.session.previousSessionId) {
|
|
881
|
+
if ((_a = _this.session) === null || _a === void 0 ? void 0 : _a.previousSessionId) {
|
|
870
882
|
return true;
|
|
871
883
|
}
|
|
872
884
|
// If the full snapshot is due to an initial load, we will not have
|
|
@@ -937,6 +949,10 @@ var SentryReplay = /** @class */ (function () {
|
|
|
937
949
|
}
|
|
938
950
|
_this.addUpdate(function () {
|
|
939
951
|
_this.createPerformanceSpans([result]);
|
|
952
|
+
// Returning true will cause `addUpdate` to not flush
|
|
953
|
+
// We do not want network requests to cause a flush. This will prevent
|
|
954
|
+
// recurring/polling requests from keeping the replay session alive.
|
|
955
|
+
return ['xhr', 'fetch'].includes(type);
|
|
940
956
|
});
|
|
941
957
|
}; };
|
|
942
958
|
/**
|
|
@@ -958,7 +974,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
958
974
|
type: EventType.Custom,
|
|
959
975
|
// TODO: We were converting from ms to seconds for breadcrumbs, spans,
|
|
960
976
|
// but maybe we should just keep them as milliseconds
|
|
961
|
-
timestamp: result.timestamp * 1000,
|
|
977
|
+
timestamp: (result.timestamp || 0) * 1000,
|
|
962
978
|
data: {
|
|
963
979
|
tag: 'breadcrumb',
|
|
964
980
|
payload: result,
|
|
@@ -1021,7 +1037,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1021
1037
|
return;
|
|
1022
1038
|
}
|
|
1023
1039
|
this.eventBuffer = createEventBuffer({
|
|
1024
|
-
useCompression: this.options.useCompression,
|
|
1040
|
+
useCompression: Boolean(this.options.useCompression),
|
|
1025
1041
|
});
|
|
1026
1042
|
this.addListeners();
|
|
1027
1043
|
// Tag all (non replay) events that get sent to Sentry with the current
|
|
@@ -1086,7 +1102,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1086
1102
|
this.removeListeners();
|
|
1087
1103
|
};
|
|
1088
1104
|
SentryReplay.prototype.clearSession = function () {
|
|
1089
|
-
this.session =
|
|
1105
|
+
this.session = undefined;
|
|
1090
1106
|
};
|
|
1091
1107
|
/**
|
|
1092
1108
|
* Loads a session from storage, or creates a new one if it does not exist or
|
|
@@ -1097,7 +1113,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1097
1113
|
var expiry = _a.expiry;
|
|
1098
1114
|
var _d = getSession({
|
|
1099
1115
|
expiry: expiry,
|
|
1100
|
-
stickySession: this.options.stickySession,
|
|
1116
|
+
stickySession: Boolean(this.options.stickySession),
|
|
1101
1117
|
currentSession: this.session,
|
|
1102
1118
|
samplingRate: this.options.replaysSamplingRate,
|
|
1103
1119
|
}), type = _d.type, session = _d.session;
|
|
@@ -1139,7 +1155,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1139
1155
|
window.addEventListener('beforeunload', this.handleWindowUnload);
|
|
1140
1156
|
// Listeners from core SDK //
|
|
1141
1157
|
var scope = getCurrentHub().getScope();
|
|
1142
|
-
scope.addScopeListener(this.handleCoreBreadcrumbListener('scope'));
|
|
1158
|
+
scope === null || scope === void 0 ? void 0 : scope.addScopeListener(this.handleCoreBreadcrumbListener('scope'));
|
|
1143
1159
|
addInstrumentationHandler('dom', this.handleCoreBreadcrumbListener('dom'));
|
|
1144
1160
|
addInstrumentationHandler('fetch', this.handleCoreSpanListener('fetch'));
|
|
1145
1161
|
addInstrumentationHandler('xhr', this.handleCoreSpanListener('xhr'));
|
|
@@ -1161,7 +1177,8 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1161
1177
|
'paint',
|
|
1162
1178
|
'resource',
|
|
1163
1179
|
].forEach(function (type) {
|
|
1164
|
-
|
|
1180
|
+
var _a;
|
|
1181
|
+
return (_a = _this.performanceObserver) === null || _a === void 0 ? void 0 : _a.observe({
|
|
1165
1182
|
type: type,
|
|
1166
1183
|
buffered: true,
|
|
1167
1184
|
});
|
|
@@ -1184,6 +1201,9 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1184
1201
|
* Tasks to run when we consider a page to be hidden (via blurring and/or visibility)
|
|
1185
1202
|
*/
|
|
1186
1203
|
SentryReplay.prototype.doChangeToBackgroundTasks = function (breadcrumb) {
|
|
1204
|
+
if (!this.session) {
|
|
1205
|
+
return;
|
|
1206
|
+
}
|
|
1187
1207
|
var isExpired = isSessionExpired(this.session, VISIBILITY_CHANGE_TIMEOUT);
|
|
1188
1208
|
if (breadcrumb) {
|
|
1189
1209
|
this.createCustomBreadcrumb(__assign(__assign({}, breadcrumb), {
|
|
@@ -1201,6 +1221,9 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1201
1221
|
* Tasks to run when we consider a page to be visible (via focus and/or visibility)
|
|
1202
1222
|
*/
|
|
1203
1223
|
SentryReplay.prototype.doChangeToForegroundTasks = function (breadcrumb) {
|
|
1224
|
+
if (!this.session) {
|
|
1225
|
+
return;
|
|
1226
|
+
}
|
|
1204
1227
|
var isExpired = isSessionExpired(this.session, VISIBILITY_CHANGE_TIMEOUT);
|
|
1205
1228
|
if (breadcrumb) {
|
|
1206
1229
|
this.createCustomBreadcrumb(__assign(__assign({}, breadcrumb), { timestamp: isExpired
|
|
@@ -1246,7 +1269,9 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1246
1269
|
*/
|
|
1247
1270
|
SentryReplay.prototype.updateLastActivity = function (lastActivity) {
|
|
1248
1271
|
if (lastActivity === void 0) { lastActivity = new Date().getTime(); }
|
|
1249
|
-
this.session
|
|
1272
|
+
if (this.session) {
|
|
1273
|
+
this.session.lastActivity = lastActivity;
|
|
1274
|
+
}
|
|
1250
1275
|
};
|
|
1251
1276
|
/**
|
|
1252
1277
|
* Helper to create (and buffer) a replay breadcrumb from a core SDK breadcrumb
|
|
@@ -1256,7 +1281,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1256
1281
|
this.addUpdate(function () {
|
|
1257
1282
|
_this.addEvent({
|
|
1258
1283
|
type: EventType.Custom,
|
|
1259
|
-
timestamp: breadcrumb.timestamp,
|
|
1284
|
+
timestamp: breadcrumb.timestamp || 0,
|
|
1260
1285
|
data: {
|
|
1261
1286
|
tag: 'breadcrumb',
|
|
1262
1287
|
payload: breadcrumb,
|
|
@@ -1318,12 +1343,13 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1318
1343
|
* Returns true if session is not expired, false otherwise.
|
|
1319
1344
|
*/
|
|
1320
1345
|
SentryReplay.prototype.checkAndHandleExpiredSession = function (expiry) {
|
|
1346
|
+
var _a, _b;
|
|
1321
1347
|
if (expiry === void 0) { expiry = SESSION_IDLE_DURATION; }
|
|
1322
|
-
var oldSessionId = this.session.id;
|
|
1348
|
+
var oldSessionId = (_a = this.session) === null || _a === void 0 ? void 0 : _a.id;
|
|
1323
1349
|
// This will create a new session if expired, based on expiry length
|
|
1324
1350
|
this.loadSession({ expiry: expiry });
|
|
1325
1351
|
// Session was expired if session ids do not match
|
|
1326
|
-
var isExpired = oldSessionId !== this.session.id;
|
|
1352
|
+
var isExpired = oldSessionId !== ((_b = this.session) === null || _b === void 0 ? void 0 : _b.id);
|
|
1327
1353
|
if (!isExpired) {
|
|
1328
1354
|
return true;
|
|
1329
1355
|
}
|
|
@@ -1367,6 +1393,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1367
1393
|
this.context.traceIds.clear();
|
|
1368
1394
|
this.context.urls = [];
|
|
1369
1395
|
this.context.earliestEvent = null;
|
|
1396
|
+
// @ts-expect-error: Type 'undefined' is not assignable to type 'Session'.ts(2322)
|
|
1370
1397
|
return context;
|
|
1371
1398
|
};
|
|
1372
1399
|
/**
|
|
@@ -1376,16 +1403,17 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1376
1403
|
* due to the buffered performance observer events.
|
|
1377
1404
|
*/
|
|
1378
1405
|
SentryReplay.prototype.flushUpdate = function (lastActivity) {
|
|
1406
|
+
var _a;
|
|
1379
1407
|
return __awaiter(this, void 0, void 0, function () {
|
|
1380
1408
|
var timestamp, recordingData, err_1;
|
|
1381
|
-
return __generator(this, function (
|
|
1382
|
-
switch (
|
|
1409
|
+
return __generator(this, function (_b) {
|
|
1410
|
+
switch (_b.label) {
|
|
1383
1411
|
case 0:
|
|
1384
1412
|
if (!this.checkAndHandleExpiredSession()) {
|
|
1385
1413
|
logger.error(new Error('Attempting to finish replay event after session expired.'));
|
|
1386
1414
|
return [2 /*return*/];
|
|
1387
1415
|
}
|
|
1388
|
-
if (!this.session.id) {
|
|
1416
|
+
if (!((_a = this.session) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
1389
1417
|
console.error(new Error('[Sentry]: No transaction, no replay'));
|
|
1390
1418
|
return [2 /*return*/];
|
|
1391
1419
|
}
|
|
@@ -1393,7 +1421,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1393
1421
|
clearTimeout(this.timeout);
|
|
1394
1422
|
return [4 /*yield*/, this.addPerformanceEntries()];
|
|
1395
1423
|
case 1:
|
|
1396
|
-
|
|
1424
|
+
_b.sent();
|
|
1397
1425
|
if (!this.eventBuffer.length) {
|
|
1398
1426
|
return [2 /*return*/];
|
|
1399
1427
|
}
|
|
@@ -1401,7 +1429,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1401
1429
|
return [4 /*yield*/, this.addMemoryEntry()];
|
|
1402
1430
|
case 2:
|
|
1403
1431
|
// Only attach memory event if eventBuffer is not empty
|
|
1404
|
-
|
|
1432
|
+
_b.sent();
|
|
1405
1433
|
timestamp = lastActivity !== null && lastActivity !== void 0 ? lastActivity : new Date().getTime();
|
|
1406
1434
|
// Only want to create replay event if session is new
|
|
1407
1435
|
if (this.needsCaptureReplay) {
|
|
@@ -1412,15 +1440,15 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1412
1440
|
// Reset this to null regardless of `sendReplay` result so that future
|
|
1413
1441
|
// events will get flushed properly
|
|
1414
1442
|
this.initialEventTimestampSinceFlush = null;
|
|
1415
|
-
|
|
1443
|
+
_b.label = 3;
|
|
1416
1444
|
case 3:
|
|
1417
|
-
|
|
1445
|
+
_b.trys.push([3, 6, , 7]);
|
|
1418
1446
|
return [4 /*yield*/, this.eventBuffer.finish()];
|
|
1419
1447
|
case 4:
|
|
1420
|
-
recordingData =
|
|
1448
|
+
recordingData = _b.sent();
|
|
1421
1449
|
return [4 /*yield*/, this.sendReplay(this.session.id, recordingData)];
|
|
1422
1450
|
case 5:
|
|
1423
|
-
|
|
1451
|
+
_b.sent();
|
|
1424
1452
|
// The below will only happen after successfully sending replay //
|
|
1425
1453
|
// TBD: Alternatively we could update this after every rrweb event
|
|
1426
1454
|
// `timestamp` should reflect when the event happens. e.g. the timestamp
|
|
@@ -1430,7 +1458,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1430
1458
|
captureReplayUpdate(this.popEventContext({ timestamp: timestamp }));
|
|
1431
1459
|
return [3 /*break*/, 7];
|
|
1432
1460
|
case 6:
|
|
1433
|
-
err_1 =
|
|
1461
|
+
err_1 = _b.sent();
|
|
1434
1462
|
captureException(err_1);
|
|
1435
1463
|
console.error(err_1);
|
|
1436
1464
|
return [3 /*break*/, 7];
|
|
@@ -1443,21 +1471,22 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1443
1471
|
* Send replay attachment using `fetch()`
|
|
1444
1472
|
*/
|
|
1445
1473
|
SentryReplay.prototype.sendReplayRequest = function (_a) {
|
|
1474
|
+
var _b, _c;
|
|
1446
1475
|
var endpoint = _a.endpoint, events = _a.events;
|
|
1447
1476
|
return __awaiter(this, void 0, void 0, function () {
|
|
1448
|
-
var payloadWithSequence, envelope, response,
|
|
1449
|
-
var
|
|
1450
|
-
return __generator(this, function (
|
|
1451
|
-
switch (
|
|
1477
|
+
var payloadWithSequence, envelope, response, _d, _e;
|
|
1478
|
+
var _f;
|
|
1479
|
+
return __generator(this, function (_g) {
|
|
1480
|
+
switch (_g.label) {
|
|
1452
1481
|
case 0:
|
|
1453
1482
|
payloadWithSequence = createPayload({
|
|
1454
1483
|
events: events,
|
|
1455
1484
|
headers: {
|
|
1456
|
-
segment_id: this.session.segmentId,
|
|
1485
|
+
segment_id: (_b = this.session) === null || _b === void 0 ? void 0 : _b.segmentId,
|
|
1457
1486
|
},
|
|
1458
1487
|
});
|
|
1459
1488
|
envelope = createEnvelope({
|
|
1460
|
-
event_id: this.session.id,
|
|
1489
|
+
event_id: (_c = this.session) === null || _c === void 0 ? void 0 : _c.id,
|
|
1461
1490
|
sent_at: new Date().toISOString(),
|
|
1462
1491
|
sdk: { name: 'sentry.javascript.integration.replay', version: '1.0.0' },
|
|
1463
1492
|
}, [
|
|
@@ -1467,6 +1496,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1467
1496
|
type: 'replay_recording',
|
|
1468
1497
|
length: payloadWithSequence.length,
|
|
1469
1498
|
},
|
|
1499
|
+
// @ts-expect-error: Type 'string' is not assignable to type 'ClientReport'.ts(2322)
|
|
1470
1500
|
payloadWithSequence,
|
|
1471
1501
|
],
|
|
1472
1502
|
]);
|
|
@@ -1477,17 +1507,17 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1477
1507
|
body: serializeEnvelope(envelope),
|
|
1478
1508
|
})];
|
|
1479
1509
|
case 1:
|
|
1480
|
-
response =
|
|
1510
|
+
response = _g.sent();
|
|
1481
1511
|
if (!(response.status !== 200)) return [3 /*break*/, 3];
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1512
|
+
_d = setContext;
|
|
1513
|
+
_e = ['Send Replay Response'];
|
|
1514
|
+
_f = {
|
|
1485
1515
|
status: response.status
|
|
1486
1516
|
};
|
|
1487
1517
|
return [4 /*yield*/, response.text()];
|
|
1488
1518
|
case 2:
|
|
1489
|
-
|
|
1490
|
-
|
|
1519
|
+
_d.apply(void 0, _e.concat([(_f.body = _g.sent(),
|
|
1520
|
+
_f)]));
|
|
1491
1521
|
throw new Error(UNABLE_TO_SEND_REPLAY);
|
|
1492
1522
|
case 3: return [2 /*return*/];
|
|
1493
1523
|
}
|