@sentry/replay 0.4.8 → 0.4.9
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/dist/src/eventBuffer.d.ts +11 -4
- package/dist/config/dist/src/index.d.ts +8 -3
- package/dist/dist/eventBuffer.d.ts +11 -4
- package/dist/dist/index.d.ts +8 -3
- package/dist/index.es.js +106 -73
- package/dist/index.js +106 -73
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -642,38 +642,25 @@ var EventBufferCompressionWorker = /** @class */ (function () {
|
|
|
642
642
|
this.eventBufferItemLength = 0;
|
|
643
643
|
this._id = 0;
|
|
644
644
|
this.sendEventToWorker = function (event) {
|
|
645
|
-
_this.postMessage({
|
|
645
|
+
var promise = _this.postMessage({
|
|
646
646
|
id: _this.id,
|
|
647
647
|
method: 'addEvent',
|
|
648
648
|
args: [event],
|
|
649
649
|
});
|
|
650
|
+
logger.log('Message posted to worker');
|
|
651
|
+
// XXX: See note in `get length()`
|
|
650
652
|
_this.eventBufferItemLength++;
|
|
653
|
+
return promise;
|
|
651
654
|
};
|
|
652
|
-
this.finishRequest = function (id) {
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
if (data.id !== id) {
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
if (!data.success) {
|
|
663
|
-
// TODO: Do some error handling, not sure what
|
|
664
|
-
logger.error(data.response);
|
|
665
|
-
reject(new Error('Error in compression worker'));
|
|
666
|
-
return;
|
|
667
|
-
}
|
|
668
|
-
resolve(data.response);
|
|
669
|
-
logger.log('Worker responded with compressed payload');
|
|
670
|
-
_this.eventBufferItemLength = 0;
|
|
671
|
-
_this.worker.removeEventListener('message', finishListener);
|
|
672
|
-
};
|
|
673
|
-
_this.worker.addEventListener('message', finishListener);
|
|
674
|
-
_this.postMessage({ id: id, method: 'finish', args: [] });
|
|
655
|
+
this.finishRequest = function (id) { return __awaiter(_this, void 0, void 0, function () {
|
|
656
|
+
var promise;
|
|
657
|
+
return __generator(this, function (_a) {
|
|
658
|
+
promise = this.postMessage({ id: id, method: 'finish', args: [] });
|
|
659
|
+
// XXX: See note in `get length()`
|
|
660
|
+
this.eventBufferItemLength = 0;
|
|
661
|
+
return [2 /*return*/, promise];
|
|
675
662
|
});
|
|
676
|
-
};
|
|
663
|
+
}); };
|
|
677
664
|
this.worker = worker;
|
|
678
665
|
}
|
|
679
666
|
Object.defineProperty(EventBufferCompressionWorker.prototype, "id", {
|
|
@@ -686,8 +673,38 @@ var EventBufferCompressionWorker = /** @class */ (function () {
|
|
|
686
673
|
enumerable: false,
|
|
687
674
|
configurable: true
|
|
688
675
|
});
|
|
689
|
-
|
|
690
|
-
|
|
676
|
+
/**
|
|
677
|
+
* Post message to worker and wait for response before resolving promise.
|
|
678
|
+
*/
|
|
679
|
+
EventBufferCompressionWorker.prototype.postMessage = function (_a) {
|
|
680
|
+
var _this = this;
|
|
681
|
+
var id = _a.id, method = _a.method, args = _a.args;
|
|
682
|
+
return new Promise(function (resolve, reject) {
|
|
683
|
+
var listener = function (_a) {
|
|
684
|
+
var data = _a.data;
|
|
685
|
+
if (data.method !== method) {
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
// There can be multiple listeners for a single method, the id ensures
|
|
689
|
+
// that the response matches the caller.
|
|
690
|
+
if (data.id !== id) {
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
// At this point, we'll always want to remove listener regardless of result status
|
|
694
|
+
_this.worker.removeEventListener('message', listener);
|
|
695
|
+
if (!data.success) {
|
|
696
|
+
// TODO: Do some error handling, not sure what
|
|
697
|
+
logger.error(data.response);
|
|
698
|
+
reject(new Error('Error in compression worker'));
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
resolve(data.response);
|
|
702
|
+
};
|
|
703
|
+
// Note: we can't use `once` option because it's possible it needs to
|
|
704
|
+
// listen to multiple messages
|
|
705
|
+
_this.worker.addEventListener('message', listener);
|
|
706
|
+
_this.worker.postMessage({ id: id, method: method, args: args });
|
|
707
|
+
});
|
|
691
708
|
};
|
|
692
709
|
EventBufferCompressionWorker.prototype.init = function () {
|
|
693
710
|
this.postMessage({ id: this.id, method: 'init', args: [] });
|
|
@@ -699,6 +716,10 @@ var EventBufferCompressionWorker = /** @class */ (function () {
|
|
|
699
716
|
this.worker = null;
|
|
700
717
|
};
|
|
701
718
|
Object.defineProperty(EventBufferCompressionWorker.prototype, "length", {
|
|
719
|
+
/**
|
|
720
|
+
* Note that this may not reflect what is actually in the event buffer. This
|
|
721
|
+
* is only a local count of the buffer size since `addEvent` is async.
|
|
722
|
+
*/
|
|
702
723
|
get: function () {
|
|
703
724
|
return this.eventBufferItemLength;
|
|
704
725
|
},
|
|
@@ -706,39 +727,31 @@ var EventBufferCompressionWorker = /** @class */ (function () {
|
|
|
706
727
|
configurable: true
|
|
707
728
|
});
|
|
708
729
|
EventBufferCompressionWorker.prototype.addEvent = function (event, isCheckout) {
|
|
709
|
-
var _this = this;
|
|
710
|
-
// If it is a checkout we should make sure worker buffer is cleared before proceeding
|
|
711
|
-
if (!isCheckout) {
|
|
712
|
-
this.sendEventToWorker(event);
|
|
713
|
-
return;
|
|
714
|
-
}
|
|
715
|
-
var initListener = function (_a) {
|
|
716
|
-
var data = _a.data;
|
|
717
|
-
if (data.method !== 'init') {
|
|
718
|
-
return;
|
|
719
|
-
}
|
|
720
|
-
if (!data.success) {
|
|
721
|
-
// TODO: Do some error handling, not sure what
|
|
722
|
-
logger.error(data.response);
|
|
723
|
-
return;
|
|
724
|
-
}
|
|
725
|
-
// Worker has been re-initialized, can add event now
|
|
726
|
-
_this.sendEventToWorker(event);
|
|
727
|
-
_this.worker.removeEventListener('message', initListener);
|
|
728
|
-
};
|
|
729
|
-
this.worker.addEventListener('message', initListener);
|
|
730
|
-
this.postMessage({ id: this.id, method: 'init', args: [] });
|
|
731
|
-
};
|
|
732
|
-
EventBufferCompressionWorker.prototype.finish = function () {
|
|
733
730
|
return __awaiter(this, void 0, void 0, function () {
|
|
734
731
|
return __generator(this, function (_a) {
|
|
735
732
|
switch (_a.label) {
|
|
736
|
-
case 0:
|
|
737
|
-
|
|
733
|
+
case 0:
|
|
734
|
+
if (!isCheckout) return [3 /*break*/, 2];
|
|
735
|
+
// This event is a checkout, make sure worker buffer is cleared before
|
|
736
|
+
// proceeding.
|
|
737
|
+
return [4 /*yield*/, this.postMessage({
|
|
738
|
+
id: this.id,
|
|
739
|
+
method: 'init',
|
|
740
|
+
args: [],
|
|
741
|
+
})];
|
|
742
|
+
case 1:
|
|
743
|
+
// This event is a checkout, make sure worker buffer is cleared before
|
|
744
|
+
// proceeding.
|
|
745
|
+
_a.sent();
|
|
746
|
+
_a.label = 2;
|
|
747
|
+
case 2: return [2 /*return*/, this.sendEventToWorker(event)];
|
|
738
748
|
}
|
|
739
749
|
});
|
|
740
750
|
});
|
|
741
751
|
};
|
|
752
|
+
EventBufferCompressionWorker.prototype.finish = function () {
|
|
753
|
+
return this.finishRequest(this.id);
|
|
754
|
+
};
|
|
742
755
|
return EventBufferCompressionWorker;
|
|
743
756
|
}());
|
|
744
757
|
|
|
@@ -794,6 +807,9 @@ var SentryReplay = /** @class */ (function () {
|
|
|
794
807
|
// Do not apply replayId to the root event
|
|
795
808
|
if (event.message === ROOT_REPLAY_NAME ||
|
|
796
809
|
((_a = event.message) === null || _a === void 0 ? void 0 : _a.startsWith(REPLAY_EVENT_NAME))) {
|
|
810
|
+
// Replays have separate set of breadcrumbs, do not include breadcrumbs
|
|
811
|
+
// from core SDK
|
|
812
|
+
delete event.breadcrumbs;
|
|
797
813
|
return event;
|
|
798
814
|
}
|
|
799
815
|
event.tags = __assign(__assign({}, event.tags), { replayId: _this.session.id });
|
|
@@ -1223,13 +1239,13 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1223
1239
|
});
|
|
1224
1240
|
};
|
|
1225
1241
|
/**
|
|
1226
|
-
* Create a span for each performance entry. The parent transaction is `this.replayEvent`.
|
|
1242
|
+
* Create a "span" for each performance entry. The parent transaction is `this.replayEvent`.
|
|
1227
1243
|
*/
|
|
1228
1244
|
SentryReplay.prototype.createPerformanceSpans = function (entries) {
|
|
1229
1245
|
var _this = this;
|
|
1230
|
-
entries.
|
|
1246
|
+
return Promise.all(entries.map(function (_a) {
|
|
1231
1247
|
var type = _a.type, start = _a.start, end = _a.end, name = _a.name, data = _a.data;
|
|
1232
|
-
_this.eventBuffer.addEvent({
|
|
1248
|
+
return _this.eventBuffer.addEvent({
|
|
1233
1249
|
type: rrweb.EventType.Custom,
|
|
1234
1250
|
timestamp: start,
|
|
1235
1251
|
data: {
|
|
@@ -1243,7 +1259,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1243
1259
|
},
|
|
1244
1260
|
},
|
|
1245
1261
|
});
|
|
1246
|
-
});
|
|
1262
|
+
}));
|
|
1247
1263
|
};
|
|
1248
1264
|
/**
|
|
1249
1265
|
* Observed performance events are added to `this.performanceEvents`. These
|
|
@@ -1253,15 +1269,22 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1253
1269
|
// Copy and reset entries before processing
|
|
1254
1270
|
var entries = __spreadArray([], this.performanceEvents, true);
|
|
1255
1271
|
this.performanceEvents = [];
|
|
1256
|
-
|
|
1257
|
-
|
|
1272
|
+
return this.createPerformanceSpans(createPerformanceEntries(entries));
|
|
1273
|
+
};
|
|
1274
|
+
/**
|
|
1275
|
+
* Create a "span" for the total amount of memory being used by JS objects
|
|
1276
|
+
* (including v8 internal objects).
|
|
1277
|
+
*/
|
|
1278
|
+
SentryReplay.prototype.addMemoryEntry = function () {
|
|
1258
1279
|
// window.performance.memory is a non-standard API and doesn't work on all browsers
|
|
1259
1280
|
// so we check before creating the event.
|
|
1260
|
-
if ('memory' in window.performance) {
|
|
1261
|
-
|
|
1262
|
-
entryEvents.push(createMemoryEntry(window.performance.memory));
|
|
1281
|
+
if (!('memory' in window.performance)) {
|
|
1282
|
+
return;
|
|
1263
1283
|
}
|
|
1264
|
-
this.createPerformanceSpans(
|
|
1284
|
+
return this.createPerformanceSpans([
|
|
1285
|
+
// @ts-expect-error memory doesn't exist on type Performance as the API is non-standard (we check that it exists above)
|
|
1286
|
+
createMemoryEntry(window.performance.memory),
|
|
1287
|
+
]);
|
|
1265
1288
|
};
|
|
1266
1289
|
/**
|
|
1267
1290
|
*
|
|
@@ -1333,10 +1356,19 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1333
1356
|
console.error(new Error('[Sentry]: No transaction, no replay'));
|
|
1334
1357
|
return [2 /*return*/];
|
|
1335
1358
|
}
|
|
1336
|
-
|
|
1359
|
+
// Since already flushing, ensure other queued flushes are cancelled
|
|
1360
|
+
clearTimeout(this.timeout);
|
|
1361
|
+
return [4 /*yield*/, this.addPerformanceEntries()];
|
|
1362
|
+
case 1:
|
|
1363
|
+
_a.sent();
|
|
1337
1364
|
if (!this.eventBuffer.length) {
|
|
1338
1365
|
return [2 /*return*/];
|
|
1339
1366
|
}
|
|
1367
|
+
// Only attach memory event if eventBuffer is not empty
|
|
1368
|
+
return [4 /*yield*/, this.addMemoryEntry()];
|
|
1369
|
+
case 2:
|
|
1370
|
+
// Only attach memory event if eventBuffer is not empty
|
|
1371
|
+
_a.sent();
|
|
1340
1372
|
timestamp = lastActivity !== null && lastActivity !== void 0 ? lastActivity : new Date().getTime();
|
|
1341
1373
|
// Only want to create replay event if session is new
|
|
1342
1374
|
if (this.needsCaptureReplay) {
|
|
@@ -1347,14 +1379,14 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1347
1379
|
// Reset this to null regardless of `sendReplay` result so that future
|
|
1348
1380
|
// events will get flushed properly
|
|
1349
1381
|
this.initialEventTimestampSinceFlush = null;
|
|
1350
|
-
_a.label =
|
|
1351
|
-
case
|
|
1352
|
-
_a.trys.push([
|
|
1382
|
+
_a.label = 3;
|
|
1383
|
+
case 3:
|
|
1384
|
+
_a.trys.push([3, 6, , 7]);
|
|
1353
1385
|
return [4 /*yield*/, this.eventBuffer.finish()];
|
|
1354
|
-
case
|
|
1386
|
+
case 4:
|
|
1355
1387
|
recordingData = _a.sent();
|
|
1356
1388
|
return [4 /*yield*/, this.sendReplay(this.session.id, recordingData)];
|
|
1357
|
-
case
|
|
1389
|
+
case 5:
|
|
1358
1390
|
_a.sent();
|
|
1359
1391
|
// The below will only happen after successfully sending replay //
|
|
1360
1392
|
// TBD: Alternatively we could update this after every rrweb event
|
|
@@ -1363,12 +1395,13 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1363
1395
|
// occurs.
|
|
1364
1396
|
this.updateLastActivity(timestamp);
|
|
1365
1397
|
captureReplayUpdate(this.popEventContext({ timestamp: timestamp }));
|
|
1366
|
-
return [3 /*break*/,
|
|
1367
|
-
case
|
|
1398
|
+
return [3 /*break*/, 7];
|
|
1399
|
+
case 6:
|
|
1368
1400
|
err_1 = _a.sent();
|
|
1401
|
+
core.captureException(err_1);
|
|
1369
1402
|
console.error(err_1);
|
|
1370
|
-
return [3 /*break*/,
|
|
1371
|
-
case
|
|
1403
|
+
return [3 /*break*/, 7];
|
|
1404
|
+
case 7: return [2 /*return*/];
|
|
1372
1405
|
}
|
|
1373
1406
|
});
|
|
1374
1407
|
});
|