@sentry/replay 0.4.8 → 0.5.1
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 +168 -108
- package/dist/index.js +166 -106
- package/dist/index.js.map +1 -1
- package/dist/{config/dist → types}/src/api/captureReplay.d.ts +0 -0
- package/dist/{config/dist → types}/src/api/captureReplayUpdate.d.ts +0 -0
- package/dist/{config/dist → types}/src/coreHandlers/getBreadcrumbHandler.d.ts +0 -0
- package/dist/{config/dist → types}/src/coreHandlers/getSpanHandler.d.ts +0 -0
- package/dist/{config/dist → types}/src/coreHandlers/handleDom.d.ts +0 -0
- package/dist/{config/dist → types}/src/coreHandlers/handleFetch.d.ts +0 -0
- package/dist/{config/dist → types}/src/coreHandlers/handleHistory.d.ts +0 -0
- package/dist/{config/dist → types}/src/coreHandlers/handleScope.d.ts +0 -0
- package/dist/{config/dist → types}/src/coreHandlers/handleXhr.d.ts +0 -0
- package/dist/{config/dist → types}/src/createPerformanceEntry.d.ts +0 -0
- package/dist/{dist → types/src}/eventBuffer.d.ts +11 -4
- package/dist/{config/dist → types}/src/flags.d.ts +0 -0
- package/dist/{dist → types/src}/index.d.ts +11 -7
- package/dist/{config/dist → types}/src/session/Session.d.ts +0 -0
- package/dist/{config/dist → types}/src/session/constants.d.ts +2 -2
- package/dist/{config/dist → types}/src/session/createSession.d.ts +0 -0
- package/dist/{config/dist → types}/src/session/fetchSession.d.ts +0 -0
- package/dist/{config/dist → types}/src/session/getSession.d.ts +0 -0
- package/dist/{config/dist → types}/src/session/index.d.ts +0 -0
- package/dist/{config/dist → types}/src/session/saveSession.d.ts +0 -0
- package/dist/{config/dist → types}/src/types.d.ts +2 -1
- package/dist/{config/dist → types}/src/util/createBreadcrumb.d.ts +0 -0
- package/dist/{config/dist → types}/src/util/createPayload.d.ts +0 -0
- package/dist/{config/dist → types}/src/util/isExpired.d.ts +0 -0
- package/dist/{config/dist → types}/src/util/isIngestHost.d.ts +0 -0
- package/dist/{config/dist → types}/src/util/isSampled.d.ts +0 -0
- package/dist/{config/dist → types}/src/util/isSessionExpired.d.ts +0 -0
- package/dist/{config/dist → types}/src/util/logger.d.ts +0 -0
- package/dist/{config/dist → types}/src/util/supportsSendBeacon.d.ts +0 -0
- package/package.json +2 -2
- package/dist/config/dist/jest.config.d.ts +0 -3
- package/dist/config/dist/jest.setup.d.ts +0 -10
- package/dist/config/dist/src/coreHandlers/handleFetch.test.d.ts +0 -1
- package/dist/config/dist/src/coreHandlers/handleScope-unit.test.d.ts +0 -1
- package/dist/config/dist/src/coreHandlers/handleScope.test.d.ts +0 -1
- package/dist/config/dist/src/coreHandlers/index.d.ts +0 -4
- package/dist/config/dist/src/createPerformanceEntry.test.d.ts +0 -1
- package/dist/config/dist/src/eventBuffer.d.ts +0 -38
- package/dist/config/dist/src/eventBuffer.test.d.ts +0 -1
- package/dist/config/dist/src/index-captureOnlyOnError.test.d.ts +0 -1
- package/dist/config/dist/src/index-noSticky.test.d.ts +0 -1
- package/dist/config/dist/src/index-sampling.test.d.ts +0 -1
- package/dist/config/dist/src/index.d.ts +0 -220
- package/dist/config/dist/src/index.test.d.ts +0 -1
- package/dist/config/dist/src/session/Session.test.d.ts +0 -1
- package/dist/config/dist/src/session/createSession.test.d.ts +0 -1
- package/dist/config/dist/src/session/fetchSession.test.d.ts +0 -1
- package/dist/config/dist/src/session/getSession.test.d.ts +0 -1
- package/dist/config/dist/src/session/saveSession.test.d.ts +0 -1
- package/dist/config/dist/src/util/isExpired.test.d.ts +0 -1
- package/dist/config/dist/src/util/isSampled.test.d.ts +0 -1
- package/dist/config/dist/src/util/isSessionExpired.test.d.ts +0 -1
- package/dist/config/dist/test/index.d.ts +0 -3
- package/dist/config/dist/test/mocks/mockRrweb.d.ts +0 -15
- package/dist/config/dist/test/mocks/mockSdk.d.ts +0 -11
- package/dist/dist/api/captureReplay.d.ts +0 -10
- package/dist/dist/api/captureReplayUpdate.d.ts +0 -12
- package/dist/dist/coreHandlers/getBreadcrumbHandler.d.ts +0 -3
- package/dist/dist/coreHandlers/getSpanHandler.d.ts +0 -5
- package/dist/dist/coreHandlers/handleDom.d.ts +0 -1
- package/dist/dist/coreHandlers/handleFetch.d.ts +0 -19
- package/dist/dist/coreHandlers/handleHistory.d.ts +0 -7
- package/dist/dist/coreHandlers/handleScope.d.ts +0 -2
- package/dist/dist/coreHandlers/handleXhr.d.ts +0 -21
- package/dist/dist/createPerformanceEntry.d.ts +0 -42
- package/dist/dist/flags.d.ts +0 -2
- package/dist/dist/session/Session.d.ts +0 -63
- package/dist/dist/session/constants.d.ts +0 -5
- package/dist/dist/session/createSession.d.ts +0 -19
- package/dist/dist/session/fetchSession.d.ts +0 -5
- package/dist/dist/session/getSession.d.ts +0 -28
- package/dist/dist/session/index.d.ts +0 -1
- package/dist/dist/session/saveSession.d.ts +0 -2
- package/dist/dist/types.d.ts +0 -90
- package/dist/dist/util/createBreadcrumb.d.ts +0 -4
- package/dist/dist/util/isExpired.d.ts +0 -5
- package/dist/dist/util/isIngestHost.d.ts +0 -4
- package/dist/dist/util/isSampled.d.ts +0 -7
- package/dist/dist/util/isSessionExpired.d.ts +0 -5
- package/dist/dist/util/logger.d.ts +0 -12
- package/dist/dist/util/supportsSendBeacon.d.ts +0 -4
package/dist/index.js
CHANGED
|
@@ -93,8 +93,7 @@ function __spreadArray(to, from, pack) {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
var REPLAY_SESSION_KEY = 'sentryReplaySession';
|
|
96
|
-
var
|
|
97
|
-
var REPLAY_EVENT_NAME = 'sentry-replay-event';
|
|
96
|
+
var REPLAY_EVENT_NAME = 'replay_event';
|
|
98
97
|
// The idle limit for a session
|
|
99
98
|
var SESSION_IDLE_DURATION = 900000; // 15 minutes
|
|
100
99
|
// Grace period to keep a session when a user changes tabs or hides window
|
|
@@ -103,29 +102,28 @@ var VISIBILITY_CHANGE_TIMEOUT = SESSION_IDLE_DURATION;
|
|
|
103
102
|
function captureReplay(_a) {
|
|
104
103
|
var session = _a.session, initialState = _a.initialState, errorIds = _a.errorIds, traceIds = _a.traceIds, urls = _a.urls;
|
|
105
104
|
core.captureEvent({
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// @ts-expect-error replay event type accepts this
|
|
105
|
+
// @ts-expect-error replay_event is a new event type
|
|
106
|
+
type: REPLAY_EVENT_NAME,
|
|
107
|
+
replay_start_timestamp: initialState.timestamp / 1000,
|
|
110
108
|
error_ids: errorIds,
|
|
111
109
|
trace_ids: traceIds,
|
|
112
110
|
urls: urls,
|
|
111
|
+
replay_id: session.id,
|
|
112
|
+
segment_id: session.segmentId, // TODO: Should this increment?
|
|
113
113
|
}, { event_id: session.id });
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
function captureReplayUpdate(_a) {
|
|
117
117
|
var session = _a.session, timestamp = _a.timestamp, errorIds = _a.errorIds, traceIds = _a.traceIds, urls = _a.urls;
|
|
118
118
|
core.captureEvent({
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
// @ts-expect-error replay_event is a new event type
|
|
120
|
+
type: REPLAY_EVENT_NAME,
|
|
121
|
+
replay_start_timestamp: timestamp / 1000,
|
|
122
122
|
error_ids: errorIds,
|
|
123
123
|
trace_ids: traceIds,
|
|
124
124
|
urls: urls,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
segmentId: session.segmentId++,
|
|
128
|
-
},
|
|
125
|
+
replay_id: session.id,
|
|
126
|
+
segment_id: ++session.segmentId,
|
|
129
127
|
});
|
|
130
128
|
}
|
|
131
129
|
|
|
@@ -469,6 +467,26 @@ function getSession(_a) {
|
|
|
469
467
|
return { type: 'new', session: newSession };
|
|
470
468
|
}
|
|
471
469
|
|
|
470
|
+
function createPayload(_a) {
|
|
471
|
+
var events = _a.events, headers = _a.headers;
|
|
472
|
+
var payloadWithSequence;
|
|
473
|
+
// XXX: newline is needed to separate sequence id from events
|
|
474
|
+
var replayHeaders = "".concat(JSON.stringify(headers), "\n");
|
|
475
|
+
if (typeof events === 'string') {
|
|
476
|
+
payloadWithSequence = "".concat(replayHeaders).concat(events);
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
var enc = new TextEncoder();
|
|
480
|
+
// XXX: newline is needed to separate sequence id from events
|
|
481
|
+
var sequence = enc.encode(replayHeaders);
|
|
482
|
+
// Merge the two Uint8Arrays
|
|
483
|
+
payloadWithSequence = new Uint8Array(sequence.length + events.length);
|
|
484
|
+
payloadWithSequence.set(sequence);
|
|
485
|
+
payloadWithSequence.set(events, sequence.length);
|
|
486
|
+
}
|
|
487
|
+
return payloadWithSequence;
|
|
488
|
+
}
|
|
489
|
+
|
|
472
490
|
/**
|
|
473
491
|
* Determine if there is browser support for `navigator.sendBeacon`
|
|
474
492
|
*/
|
|
@@ -642,38 +660,25 @@ var EventBufferCompressionWorker = /** @class */ (function () {
|
|
|
642
660
|
this.eventBufferItemLength = 0;
|
|
643
661
|
this._id = 0;
|
|
644
662
|
this.sendEventToWorker = function (event) {
|
|
645
|
-
_this.postMessage({
|
|
663
|
+
var promise = _this.postMessage({
|
|
646
664
|
id: _this.id,
|
|
647
665
|
method: 'addEvent',
|
|
648
666
|
args: [event],
|
|
649
667
|
});
|
|
668
|
+
logger.log('Message posted to worker');
|
|
669
|
+
// XXX: See note in `get length()`
|
|
650
670
|
_this.eventBufferItemLength++;
|
|
671
|
+
return promise;
|
|
651
672
|
};
|
|
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: [] });
|
|
673
|
+
this.finishRequest = function (id) { return __awaiter(_this, void 0, void 0, function () {
|
|
674
|
+
var promise;
|
|
675
|
+
return __generator(this, function (_a) {
|
|
676
|
+
promise = this.postMessage({ id: id, method: 'finish', args: [] });
|
|
677
|
+
// XXX: See note in `get length()`
|
|
678
|
+
this.eventBufferItemLength = 0;
|
|
679
|
+
return [2 /*return*/, promise];
|
|
675
680
|
});
|
|
676
|
-
};
|
|
681
|
+
}); };
|
|
677
682
|
this.worker = worker;
|
|
678
683
|
}
|
|
679
684
|
Object.defineProperty(EventBufferCompressionWorker.prototype, "id", {
|
|
@@ -686,8 +691,38 @@ var EventBufferCompressionWorker = /** @class */ (function () {
|
|
|
686
691
|
enumerable: false,
|
|
687
692
|
configurable: true
|
|
688
693
|
});
|
|
689
|
-
|
|
690
|
-
|
|
694
|
+
/**
|
|
695
|
+
* Post message to worker and wait for response before resolving promise.
|
|
696
|
+
*/
|
|
697
|
+
EventBufferCompressionWorker.prototype.postMessage = function (_a) {
|
|
698
|
+
var _this = this;
|
|
699
|
+
var id = _a.id, method = _a.method, args = _a.args;
|
|
700
|
+
return new Promise(function (resolve, reject) {
|
|
701
|
+
var listener = function (_a) {
|
|
702
|
+
var data = _a.data;
|
|
703
|
+
if (data.method !== method) {
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
// There can be multiple listeners for a single method, the id ensures
|
|
707
|
+
// that the response matches the caller.
|
|
708
|
+
if (data.id !== id) {
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
// At this point, we'll always want to remove listener regardless of result status
|
|
712
|
+
_this.worker.removeEventListener('message', listener);
|
|
713
|
+
if (!data.success) {
|
|
714
|
+
// TODO: Do some error handling, not sure what
|
|
715
|
+
logger.error(data.response);
|
|
716
|
+
reject(new Error('Error in compression worker'));
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
resolve(data.response);
|
|
720
|
+
};
|
|
721
|
+
// Note: we can't use `once` option because it's possible it needs to
|
|
722
|
+
// listen to multiple messages
|
|
723
|
+
_this.worker.addEventListener('message', listener);
|
|
724
|
+
_this.worker.postMessage({ id: id, method: method, args: args });
|
|
725
|
+
});
|
|
691
726
|
};
|
|
692
727
|
EventBufferCompressionWorker.prototype.init = function () {
|
|
693
728
|
this.postMessage({ id: this.id, method: 'init', args: [] });
|
|
@@ -699,6 +734,10 @@ var EventBufferCompressionWorker = /** @class */ (function () {
|
|
|
699
734
|
this.worker = null;
|
|
700
735
|
};
|
|
701
736
|
Object.defineProperty(EventBufferCompressionWorker.prototype, "length", {
|
|
737
|
+
/**
|
|
738
|
+
* Note that this may not reflect what is actually in the event buffer. This
|
|
739
|
+
* is only a local count of the buffer size since `addEvent` is async.
|
|
740
|
+
*/
|
|
702
741
|
get: function () {
|
|
703
742
|
return this.eventBufferItemLength;
|
|
704
743
|
},
|
|
@@ -706,39 +745,31 @@ var EventBufferCompressionWorker = /** @class */ (function () {
|
|
|
706
745
|
configurable: true
|
|
707
746
|
});
|
|
708
747
|
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
748
|
return __awaiter(this, void 0, void 0, function () {
|
|
734
749
|
return __generator(this, function (_a) {
|
|
735
750
|
switch (_a.label) {
|
|
736
|
-
case 0:
|
|
737
|
-
|
|
751
|
+
case 0:
|
|
752
|
+
if (!isCheckout) return [3 /*break*/, 2];
|
|
753
|
+
// This event is a checkout, make sure worker buffer is cleared before
|
|
754
|
+
// proceeding.
|
|
755
|
+
return [4 /*yield*/, this.postMessage({
|
|
756
|
+
id: this.id,
|
|
757
|
+
method: 'init',
|
|
758
|
+
args: [],
|
|
759
|
+
})];
|
|
760
|
+
case 1:
|
|
761
|
+
// This event is a checkout, make sure worker buffer is cleared before
|
|
762
|
+
// proceeding.
|
|
763
|
+
_a.sent();
|
|
764
|
+
_a.label = 2;
|
|
765
|
+
case 2: return [2 /*return*/, this.sendEventToWorker(event)];
|
|
738
766
|
}
|
|
739
767
|
});
|
|
740
768
|
});
|
|
741
769
|
};
|
|
770
|
+
EventBufferCompressionWorker.prototype.finish = function () {
|
|
771
|
+
return this.finishRequest(this.id);
|
|
772
|
+
};
|
|
742
773
|
return EventBufferCompressionWorker;
|
|
743
774
|
}());
|
|
744
775
|
|
|
@@ -790,15 +821,19 @@ var SentryReplay = /** @class */ (function () {
|
|
|
790
821
|
* when an error occurs.
|
|
791
822
|
**/
|
|
792
823
|
this.handleGlobalEvent = function (event) {
|
|
793
|
-
var _a
|
|
824
|
+
var _a;
|
|
794
825
|
// Do not apply replayId to the root event
|
|
795
|
-
if (
|
|
796
|
-
|
|
826
|
+
if (
|
|
827
|
+
// @ts-expect-error new event type
|
|
828
|
+
event.type === REPLAY_EVENT_NAME) {
|
|
829
|
+
// Replays have separate set of breadcrumbs, do not include breadcrumbs
|
|
830
|
+
// from core SDK
|
|
831
|
+
delete event.breadcrumbs;
|
|
797
832
|
return event;
|
|
798
833
|
}
|
|
799
834
|
event.tags = __assign(__assign({}, event.tags), { replayId: _this.session.id });
|
|
800
835
|
if (event.type === 'transaction') {
|
|
801
|
-
_this.context.traceIds.add(String(((
|
|
836
|
+
_this.context.traceIds.add(String(((_a = event.contexts) === null || _a === void 0 ? void 0 : _a.trace.trace_id) || ''));
|
|
802
837
|
return event;
|
|
803
838
|
}
|
|
804
839
|
// XXX: Is it safe to assume that all other events are error events?
|
|
@@ -962,12 +997,6 @@ var SentryReplay = /** @class */ (function () {
|
|
|
962
997
|
this.recordingOptions.checkoutEveryNms = 60000;
|
|
963
998
|
}
|
|
964
999
|
}
|
|
965
|
-
SentryReplay.attachmentUrlFromDsn = function (dsn, eventId) {
|
|
966
|
-
var host = dsn.host, projectId = dsn.projectId, protocol = dsn.protocol, publicKey = dsn.publicKey;
|
|
967
|
-
var port = dsn.port !== '' ? ":".concat(dsn.port) : '';
|
|
968
|
-
var path = dsn.path !== '' ? "/".concat(dsn.path) : '';
|
|
969
|
-
return "".concat(protocol, "://").concat(host).concat(port).concat(path, "/api/").concat(projectId, "/events/").concat(eventId, "/attachments/?sentry_key=").concat(publicKey, "&sentry_version=7&sentry_client=replay");
|
|
970
|
-
};
|
|
971
1000
|
/**
|
|
972
1001
|
* Because we create a transaction in `setupOnce`, we can potentially create a
|
|
973
1002
|
* transaction before some native SDK integrations have run and applied their
|
|
@@ -1223,13 +1252,13 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1223
1252
|
});
|
|
1224
1253
|
};
|
|
1225
1254
|
/**
|
|
1226
|
-
* Create a span for each performance entry. The parent transaction is `this.replayEvent`.
|
|
1255
|
+
* Create a "span" for each performance entry. The parent transaction is `this.replayEvent`.
|
|
1227
1256
|
*/
|
|
1228
1257
|
SentryReplay.prototype.createPerformanceSpans = function (entries) {
|
|
1229
1258
|
var _this = this;
|
|
1230
|
-
entries.
|
|
1259
|
+
return Promise.all(entries.map(function (_a) {
|
|
1231
1260
|
var type = _a.type, start = _a.start, end = _a.end, name = _a.name, data = _a.data;
|
|
1232
|
-
_this.eventBuffer.addEvent({
|
|
1261
|
+
return _this.eventBuffer.addEvent({
|
|
1233
1262
|
type: rrweb.EventType.Custom,
|
|
1234
1263
|
timestamp: start,
|
|
1235
1264
|
data: {
|
|
@@ -1243,7 +1272,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1243
1272
|
},
|
|
1244
1273
|
},
|
|
1245
1274
|
});
|
|
1246
|
-
});
|
|
1275
|
+
}));
|
|
1247
1276
|
};
|
|
1248
1277
|
/**
|
|
1249
1278
|
* Observed performance events are added to `this.performanceEvents`. These
|
|
@@ -1253,15 +1282,22 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1253
1282
|
// Copy and reset entries before processing
|
|
1254
1283
|
var entries = __spreadArray([], this.performanceEvents, true);
|
|
1255
1284
|
this.performanceEvents = [];
|
|
1256
|
-
|
|
1257
|
-
|
|
1285
|
+
return this.createPerformanceSpans(createPerformanceEntries(entries));
|
|
1286
|
+
};
|
|
1287
|
+
/**
|
|
1288
|
+
* Create a "span" for the total amount of memory being used by JS objects
|
|
1289
|
+
* (including v8 internal objects).
|
|
1290
|
+
*/
|
|
1291
|
+
SentryReplay.prototype.addMemoryEntry = function () {
|
|
1258
1292
|
// window.performance.memory is a non-standard API and doesn't work on all browsers
|
|
1259
1293
|
// so we check before creating the event.
|
|
1260
|
-
if ('memory' in window.performance) {
|
|
1261
|
-
|
|
1262
|
-
entryEvents.push(createMemoryEntry(window.performance.memory));
|
|
1294
|
+
if (!('memory' in window.performance)) {
|
|
1295
|
+
return;
|
|
1263
1296
|
}
|
|
1264
|
-
this.createPerformanceSpans(
|
|
1297
|
+
return this.createPerformanceSpans([
|
|
1298
|
+
// @ts-expect-error memory doesn't exist on type Performance as the API is non-standard (we check that it exists above)
|
|
1299
|
+
createMemoryEntry(window.performance.memory),
|
|
1300
|
+
]);
|
|
1265
1301
|
};
|
|
1266
1302
|
/**
|
|
1267
1303
|
*
|
|
@@ -1333,10 +1369,19 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1333
1369
|
console.error(new Error('[Sentry]: No transaction, no replay'));
|
|
1334
1370
|
return [2 /*return*/];
|
|
1335
1371
|
}
|
|
1336
|
-
|
|
1372
|
+
// Since already flushing, ensure other queued flushes are cancelled
|
|
1373
|
+
clearTimeout(this.timeout);
|
|
1374
|
+
return [4 /*yield*/, this.addPerformanceEntries()];
|
|
1375
|
+
case 1:
|
|
1376
|
+
_a.sent();
|
|
1337
1377
|
if (!this.eventBuffer.length) {
|
|
1338
1378
|
return [2 /*return*/];
|
|
1339
1379
|
}
|
|
1380
|
+
// Only attach memory event if eventBuffer is not empty
|
|
1381
|
+
return [4 /*yield*/, this.addMemoryEntry()];
|
|
1382
|
+
case 2:
|
|
1383
|
+
// Only attach memory event if eventBuffer is not empty
|
|
1384
|
+
_a.sent();
|
|
1340
1385
|
timestamp = lastActivity !== null && lastActivity !== void 0 ? lastActivity : new Date().getTime();
|
|
1341
1386
|
// Only want to create replay event if session is new
|
|
1342
1387
|
if (this.needsCaptureReplay) {
|
|
@@ -1347,14 +1392,14 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1347
1392
|
// Reset this to null regardless of `sendReplay` result so that future
|
|
1348
1393
|
// events will get flushed properly
|
|
1349
1394
|
this.initialEventTimestampSinceFlush = null;
|
|
1350
|
-
_a.label =
|
|
1351
|
-
case
|
|
1352
|
-
_a.trys.push([
|
|
1395
|
+
_a.label = 3;
|
|
1396
|
+
case 3:
|
|
1397
|
+
_a.trys.push([3, 6, , 7]);
|
|
1353
1398
|
return [4 /*yield*/, this.eventBuffer.finish()];
|
|
1354
|
-
case
|
|
1399
|
+
case 4:
|
|
1355
1400
|
recordingData = _a.sent();
|
|
1356
1401
|
return [4 /*yield*/, this.sendReplay(this.session.id, recordingData)];
|
|
1357
|
-
case
|
|
1402
|
+
case 5:
|
|
1358
1403
|
_a.sent();
|
|
1359
1404
|
// The below will only happen after successfully sending replay //
|
|
1360
1405
|
// TBD: Alternatively we could update this after every rrweb event
|
|
@@ -1363,12 +1408,13 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1363
1408
|
// occurs.
|
|
1364
1409
|
this.updateLastActivity(timestamp);
|
|
1365
1410
|
captureReplayUpdate(this.popEventContext({ timestamp: timestamp }));
|
|
1366
|
-
return [3 /*break*/,
|
|
1367
|
-
case
|
|
1411
|
+
return [3 /*break*/, 7];
|
|
1412
|
+
case 6:
|
|
1368
1413
|
err_1 = _a.sent();
|
|
1414
|
+
core.captureException(err_1);
|
|
1369
1415
|
console.error(err_1);
|
|
1370
|
-
return [3 /*break*/,
|
|
1371
|
-
case
|
|
1416
|
+
return [3 /*break*/, 7];
|
|
1417
|
+
case 7: return [2 /*return*/];
|
|
1372
1418
|
}
|
|
1373
1419
|
});
|
|
1374
1420
|
});
|
|
@@ -1379,27 +1425,41 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1379
1425
|
SentryReplay.prototype.sendReplayRequest = function (_a) {
|
|
1380
1426
|
var endpoint = _a.endpoint, events = _a.events;
|
|
1381
1427
|
return __awaiter(this, void 0, void 0, function () {
|
|
1382
|
-
var
|
|
1428
|
+
var payloadWithSequence, envelope;
|
|
1383
1429
|
return __generator(this, function (_b) {
|
|
1384
1430
|
switch (_b.label) {
|
|
1385
1431
|
case 0:
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1432
|
+
payloadWithSequence = createPayload({
|
|
1433
|
+
events: events,
|
|
1434
|
+
headers: {
|
|
1435
|
+
segment_id: this.session.segmentId,
|
|
1436
|
+
},
|
|
1389
1437
|
});
|
|
1390
|
-
|
|
1391
|
-
|
|
1438
|
+
envelope = utils.createEnvelope({
|
|
1439
|
+
event_id: this.session.id,
|
|
1440
|
+
sent_at: new Date().toISOString(),
|
|
1441
|
+
sdk: { name: 'sentry.javascript.integration.replay', version: '1.0.0' },
|
|
1442
|
+
}, [
|
|
1443
|
+
[
|
|
1444
|
+
{
|
|
1445
|
+
// @ts-expect-error setting envelope
|
|
1446
|
+
type: 'replay_recording',
|
|
1447
|
+
length: payloadWithSequence.length,
|
|
1448
|
+
},
|
|
1449
|
+
payloadWithSequence,
|
|
1450
|
+
],
|
|
1451
|
+
]);
|
|
1392
1452
|
// If sendBeacon is supported and payload is smol enough...
|
|
1393
|
-
if (supportsSendBeacon() &&
|
|
1453
|
+
if (supportsSendBeacon() && events.length <= 65536) {
|
|
1394
1454
|
logger.log("uploading attachment via sendBeacon()");
|
|
1395
|
-
window.navigator.sendBeacon(endpoint,
|
|
1455
|
+
window.navigator.sendBeacon(endpoint, utils.serializeEnvelope(envelope));
|
|
1396
1456
|
return [2 /*return*/];
|
|
1397
1457
|
}
|
|
1398
1458
|
// Otherwise use `fetch`, which *WILL* get cancelled on page reloads/unloads
|
|
1399
1459
|
logger.log("uploading attachment via fetch()");
|
|
1400
1460
|
return [4 /*yield*/, fetch(endpoint, {
|
|
1401
1461
|
method: 'POST',
|
|
1402
|
-
body:
|
|
1462
|
+
body: utils.serializeEnvelope(envelope),
|
|
1403
1463
|
})];
|
|
1404
1464
|
case 1:
|
|
1405
1465
|
_b.sent();
|
|
@@ -1427,7 +1487,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1427
1487
|
return [2 /*return*/];
|
|
1428
1488
|
}
|
|
1429
1489
|
client = core.getCurrentHub().getClient();
|
|
1430
|
-
endpoint =
|
|
1490
|
+
endpoint = core.getEnvelopeEndpointWithUrlEncodedAuth(client.getDsn());
|
|
1431
1491
|
_b.label = 1;
|
|
1432
1492
|
case 1:
|
|
1433
1493
|
_b.trys.push([1, 3, , 8]);
|