@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.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { captureEvent, getCurrentHub, captureException, addGlobalEventProcessor } from '@sentry/core';
|
|
2
|
-
import {
|
|
1
|
+
import { captureEvent, getCurrentHub, captureException, addGlobalEventProcessor, getEnvelopeEndpointWithUrlEncodedAuth } from '@sentry/core';
|
|
2
|
+
import { htmlTreeAsString, logger as logger$1, uuid4, addInstrumentationHandler, createEnvelope, serializeEnvelope } from '@sentry/utils';
|
|
3
3
|
import { record, EventType } from 'rrweb';
|
|
4
4
|
|
|
5
5
|
/******************************************************************************
|
|
@@ -89,8 +89,7 @@ function __spreadArray(to, from, pack) {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
var REPLAY_SESSION_KEY = 'sentryReplaySession';
|
|
92
|
-
var
|
|
93
|
-
var REPLAY_EVENT_NAME = 'sentry-replay-event';
|
|
92
|
+
var REPLAY_EVENT_NAME = 'replay_event';
|
|
94
93
|
// The idle limit for a session
|
|
95
94
|
var SESSION_IDLE_DURATION = 900000; // 15 minutes
|
|
96
95
|
// Grace period to keep a session when a user changes tabs or hides window
|
|
@@ -99,29 +98,28 @@ var VISIBILITY_CHANGE_TIMEOUT = SESSION_IDLE_DURATION;
|
|
|
99
98
|
function captureReplay(_a) {
|
|
100
99
|
var session = _a.session, initialState = _a.initialState, errorIds = _a.errorIds, traceIds = _a.traceIds, urls = _a.urls;
|
|
101
100
|
captureEvent({
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
// @ts-expect-error replay event type accepts this
|
|
101
|
+
// @ts-expect-error replay_event is a new event type
|
|
102
|
+
type: REPLAY_EVENT_NAME,
|
|
103
|
+
replay_start_timestamp: initialState.timestamp / 1000,
|
|
106
104
|
error_ids: errorIds,
|
|
107
105
|
trace_ids: traceIds,
|
|
108
106
|
urls: urls,
|
|
107
|
+
replay_id: session.id,
|
|
108
|
+
segment_id: session.segmentId, // TODO: Should this increment?
|
|
109
109
|
}, { event_id: session.id });
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
function captureReplayUpdate(_a) {
|
|
113
113
|
var session = _a.session, timestamp = _a.timestamp, errorIds = _a.errorIds, traceIds = _a.traceIds, urls = _a.urls;
|
|
114
114
|
captureEvent({
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
// @ts-expect-error replay_event is a new event type
|
|
116
|
+
type: REPLAY_EVENT_NAME,
|
|
117
|
+
replay_start_timestamp: timestamp / 1000,
|
|
118
118
|
error_ids: errorIds,
|
|
119
119
|
trace_ids: traceIds,
|
|
120
120
|
urls: urls,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
segmentId: session.segmentId++,
|
|
124
|
-
},
|
|
121
|
+
replay_id: session.id,
|
|
122
|
+
segment_id: ++session.segmentId,
|
|
125
123
|
});
|
|
126
124
|
}
|
|
127
125
|
|
|
@@ -465,6 +463,26 @@ function getSession(_a) {
|
|
|
465
463
|
return { type: 'new', session: newSession };
|
|
466
464
|
}
|
|
467
465
|
|
|
466
|
+
function createPayload(_a) {
|
|
467
|
+
var events = _a.events, headers = _a.headers;
|
|
468
|
+
var payloadWithSequence;
|
|
469
|
+
// XXX: newline is needed to separate sequence id from events
|
|
470
|
+
var replayHeaders = "".concat(JSON.stringify(headers), "\n");
|
|
471
|
+
if (typeof events === 'string') {
|
|
472
|
+
payloadWithSequence = "".concat(replayHeaders).concat(events);
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
var enc = new TextEncoder();
|
|
476
|
+
// XXX: newline is needed to separate sequence id from events
|
|
477
|
+
var sequence = enc.encode(replayHeaders);
|
|
478
|
+
// Merge the two Uint8Arrays
|
|
479
|
+
payloadWithSequence = new Uint8Array(sequence.length + events.length);
|
|
480
|
+
payloadWithSequence.set(sequence);
|
|
481
|
+
payloadWithSequence.set(events, sequence.length);
|
|
482
|
+
}
|
|
483
|
+
return payloadWithSequence;
|
|
484
|
+
}
|
|
485
|
+
|
|
468
486
|
/**
|
|
469
487
|
* Determine if there is browser support for `navigator.sendBeacon`
|
|
470
488
|
*/
|
|
@@ -638,38 +656,25 @@ var EventBufferCompressionWorker = /** @class */ (function () {
|
|
|
638
656
|
this.eventBufferItemLength = 0;
|
|
639
657
|
this._id = 0;
|
|
640
658
|
this.sendEventToWorker = function (event) {
|
|
641
|
-
_this.postMessage({
|
|
659
|
+
var promise = _this.postMessage({
|
|
642
660
|
id: _this.id,
|
|
643
661
|
method: 'addEvent',
|
|
644
662
|
args: [event],
|
|
645
663
|
});
|
|
664
|
+
logger.log('Message posted to worker');
|
|
665
|
+
// XXX: See note in `get length()`
|
|
646
666
|
_this.eventBufferItemLength++;
|
|
667
|
+
return promise;
|
|
647
668
|
};
|
|
648
|
-
this.finishRequest = function (id) {
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
if (data.id !== id) {
|
|
656
|
-
return;
|
|
657
|
-
}
|
|
658
|
-
if (!data.success) {
|
|
659
|
-
// TODO: Do some error handling, not sure what
|
|
660
|
-
logger.error(data.response);
|
|
661
|
-
reject(new Error('Error in compression worker'));
|
|
662
|
-
return;
|
|
663
|
-
}
|
|
664
|
-
resolve(data.response);
|
|
665
|
-
logger.log('Worker responded with compressed payload');
|
|
666
|
-
_this.eventBufferItemLength = 0;
|
|
667
|
-
_this.worker.removeEventListener('message', finishListener);
|
|
668
|
-
};
|
|
669
|
-
_this.worker.addEventListener('message', finishListener);
|
|
670
|
-
_this.postMessage({ id: id, method: 'finish', args: [] });
|
|
669
|
+
this.finishRequest = function (id) { return __awaiter(_this, void 0, void 0, function () {
|
|
670
|
+
var promise;
|
|
671
|
+
return __generator(this, function (_a) {
|
|
672
|
+
promise = this.postMessage({ id: id, method: 'finish', args: [] });
|
|
673
|
+
// XXX: See note in `get length()`
|
|
674
|
+
this.eventBufferItemLength = 0;
|
|
675
|
+
return [2 /*return*/, promise];
|
|
671
676
|
});
|
|
672
|
-
};
|
|
677
|
+
}); };
|
|
673
678
|
this.worker = worker;
|
|
674
679
|
}
|
|
675
680
|
Object.defineProperty(EventBufferCompressionWorker.prototype, "id", {
|
|
@@ -682,8 +687,38 @@ var EventBufferCompressionWorker = /** @class */ (function () {
|
|
|
682
687
|
enumerable: false,
|
|
683
688
|
configurable: true
|
|
684
689
|
});
|
|
685
|
-
|
|
686
|
-
|
|
690
|
+
/**
|
|
691
|
+
* Post message to worker and wait for response before resolving promise.
|
|
692
|
+
*/
|
|
693
|
+
EventBufferCompressionWorker.prototype.postMessage = function (_a) {
|
|
694
|
+
var _this = this;
|
|
695
|
+
var id = _a.id, method = _a.method, args = _a.args;
|
|
696
|
+
return new Promise(function (resolve, reject) {
|
|
697
|
+
var listener = function (_a) {
|
|
698
|
+
var data = _a.data;
|
|
699
|
+
if (data.method !== method) {
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
// There can be multiple listeners for a single method, the id ensures
|
|
703
|
+
// that the response matches the caller.
|
|
704
|
+
if (data.id !== id) {
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
// At this point, we'll always want to remove listener regardless of result status
|
|
708
|
+
_this.worker.removeEventListener('message', listener);
|
|
709
|
+
if (!data.success) {
|
|
710
|
+
// TODO: Do some error handling, not sure what
|
|
711
|
+
logger.error(data.response);
|
|
712
|
+
reject(new Error('Error in compression worker'));
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
resolve(data.response);
|
|
716
|
+
};
|
|
717
|
+
// Note: we can't use `once` option because it's possible it needs to
|
|
718
|
+
// listen to multiple messages
|
|
719
|
+
_this.worker.addEventListener('message', listener);
|
|
720
|
+
_this.worker.postMessage({ id: id, method: method, args: args });
|
|
721
|
+
});
|
|
687
722
|
};
|
|
688
723
|
EventBufferCompressionWorker.prototype.init = function () {
|
|
689
724
|
this.postMessage({ id: this.id, method: 'init', args: [] });
|
|
@@ -695,6 +730,10 @@ var EventBufferCompressionWorker = /** @class */ (function () {
|
|
|
695
730
|
this.worker = null;
|
|
696
731
|
};
|
|
697
732
|
Object.defineProperty(EventBufferCompressionWorker.prototype, "length", {
|
|
733
|
+
/**
|
|
734
|
+
* Note that this may not reflect what is actually in the event buffer. This
|
|
735
|
+
* is only a local count of the buffer size since `addEvent` is async.
|
|
736
|
+
*/
|
|
698
737
|
get: function () {
|
|
699
738
|
return this.eventBufferItemLength;
|
|
700
739
|
},
|
|
@@ -702,39 +741,31 @@ var EventBufferCompressionWorker = /** @class */ (function () {
|
|
|
702
741
|
configurable: true
|
|
703
742
|
});
|
|
704
743
|
EventBufferCompressionWorker.prototype.addEvent = function (event, isCheckout) {
|
|
705
|
-
var _this = this;
|
|
706
|
-
// If it is a checkout we should make sure worker buffer is cleared before proceeding
|
|
707
|
-
if (!isCheckout) {
|
|
708
|
-
this.sendEventToWorker(event);
|
|
709
|
-
return;
|
|
710
|
-
}
|
|
711
|
-
var initListener = function (_a) {
|
|
712
|
-
var data = _a.data;
|
|
713
|
-
if (data.method !== 'init') {
|
|
714
|
-
return;
|
|
715
|
-
}
|
|
716
|
-
if (!data.success) {
|
|
717
|
-
// TODO: Do some error handling, not sure what
|
|
718
|
-
logger.error(data.response);
|
|
719
|
-
return;
|
|
720
|
-
}
|
|
721
|
-
// Worker has been re-initialized, can add event now
|
|
722
|
-
_this.sendEventToWorker(event);
|
|
723
|
-
_this.worker.removeEventListener('message', initListener);
|
|
724
|
-
};
|
|
725
|
-
this.worker.addEventListener('message', initListener);
|
|
726
|
-
this.postMessage({ id: this.id, method: 'init', args: [] });
|
|
727
|
-
};
|
|
728
|
-
EventBufferCompressionWorker.prototype.finish = function () {
|
|
729
744
|
return __awaiter(this, void 0, void 0, function () {
|
|
730
745
|
return __generator(this, function (_a) {
|
|
731
746
|
switch (_a.label) {
|
|
732
|
-
case 0:
|
|
733
|
-
|
|
747
|
+
case 0:
|
|
748
|
+
if (!isCheckout) return [3 /*break*/, 2];
|
|
749
|
+
// This event is a checkout, make sure worker buffer is cleared before
|
|
750
|
+
// proceeding.
|
|
751
|
+
return [4 /*yield*/, this.postMessage({
|
|
752
|
+
id: this.id,
|
|
753
|
+
method: 'init',
|
|
754
|
+
args: [],
|
|
755
|
+
})];
|
|
756
|
+
case 1:
|
|
757
|
+
// This event is a checkout, make sure worker buffer is cleared before
|
|
758
|
+
// proceeding.
|
|
759
|
+
_a.sent();
|
|
760
|
+
_a.label = 2;
|
|
761
|
+
case 2: return [2 /*return*/, this.sendEventToWorker(event)];
|
|
734
762
|
}
|
|
735
763
|
});
|
|
736
764
|
});
|
|
737
765
|
};
|
|
766
|
+
EventBufferCompressionWorker.prototype.finish = function () {
|
|
767
|
+
return this.finishRequest(this.id);
|
|
768
|
+
};
|
|
738
769
|
return EventBufferCompressionWorker;
|
|
739
770
|
}());
|
|
740
771
|
|
|
@@ -786,15 +817,19 @@ var SentryReplay = /** @class */ (function () {
|
|
|
786
817
|
* when an error occurs.
|
|
787
818
|
**/
|
|
788
819
|
this.handleGlobalEvent = function (event) {
|
|
789
|
-
var _a
|
|
820
|
+
var _a;
|
|
790
821
|
// Do not apply replayId to the root event
|
|
791
|
-
if (
|
|
792
|
-
|
|
822
|
+
if (
|
|
823
|
+
// @ts-expect-error new event type
|
|
824
|
+
event.type === REPLAY_EVENT_NAME) {
|
|
825
|
+
// Replays have separate set of breadcrumbs, do not include breadcrumbs
|
|
826
|
+
// from core SDK
|
|
827
|
+
delete event.breadcrumbs;
|
|
793
828
|
return event;
|
|
794
829
|
}
|
|
795
830
|
event.tags = __assign(__assign({}, event.tags), { replayId: _this.session.id });
|
|
796
831
|
if (event.type === 'transaction') {
|
|
797
|
-
_this.context.traceIds.add(String(((
|
|
832
|
+
_this.context.traceIds.add(String(((_a = event.contexts) === null || _a === void 0 ? void 0 : _a.trace.trace_id) || ''));
|
|
798
833
|
return event;
|
|
799
834
|
}
|
|
800
835
|
// XXX: Is it safe to assume that all other events are error events?
|
|
@@ -958,12 +993,6 @@ var SentryReplay = /** @class */ (function () {
|
|
|
958
993
|
this.recordingOptions.checkoutEveryNms = 60000;
|
|
959
994
|
}
|
|
960
995
|
}
|
|
961
|
-
SentryReplay.attachmentUrlFromDsn = function (dsn, eventId) {
|
|
962
|
-
var host = dsn.host, projectId = dsn.projectId, protocol = dsn.protocol, publicKey = dsn.publicKey;
|
|
963
|
-
var port = dsn.port !== '' ? ":".concat(dsn.port) : '';
|
|
964
|
-
var path = dsn.path !== '' ? "/".concat(dsn.path) : '';
|
|
965
|
-
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");
|
|
966
|
-
};
|
|
967
996
|
/**
|
|
968
997
|
* Because we create a transaction in `setupOnce`, we can potentially create a
|
|
969
998
|
* transaction before some native SDK integrations have run and applied their
|
|
@@ -1219,13 +1248,13 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1219
1248
|
});
|
|
1220
1249
|
};
|
|
1221
1250
|
/**
|
|
1222
|
-
* Create a span for each performance entry. The parent transaction is `this.replayEvent`.
|
|
1251
|
+
* Create a "span" for each performance entry. The parent transaction is `this.replayEvent`.
|
|
1223
1252
|
*/
|
|
1224
1253
|
SentryReplay.prototype.createPerformanceSpans = function (entries) {
|
|
1225
1254
|
var _this = this;
|
|
1226
|
-
entries.
|
|
1255
|
+
return Promise.all(entries.map(function (_a) {
|
|
1227
1256
|
var type = _a.type, start = _a.start, end = _a.end, name = _a.name, data = _a.data;
|
|
1228
|
-
_this.eventBuffer.addEvent({
|
|
1257
|
+
return _this.eventBuffer.addEvent({
|
|
1229
1258
|
type: EventType.Custom,
|
|
1230
1259
|
timestamp: start,
|
|
1231
1260
|
data: {
|
|
@@ -1239,7 +1268,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1239
1268
|
},
|
|
1240
1269
|
},
|
|
1241
1270
|
});
|
|
1242
|
-
});
|
|
1271
|
+
}));
|
|
1243
1272
|
};
|
|
1244
1273
|
/**
|
|
1245
1274
|
* Observed performance events are added to `this.performanceEvents`. These
|
|
@@ -1249,15 +1278,22 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1249
1278
|
// Copy and reset entries before processing
|
|
1250
1279
|
var entries = __spreadArray([], this.performanceEvents, true);
|
|
1251
1280
|
this.performanceEvents = [];
|
|
1252
|
-
|
|
1253
|
-
|
|
1281
|
+
return this.createPerformanceSpans(createPerformanceEntries(entries));
|
|
1282
|
+
};
|
|
1283
|
+
/**
|
|
1284
|
+
* Create a "span" for the total amount of memory being used by JS objects
|
|
1285
|
+
* (including v8 internal objects).
|
|
1286
|
+
*/
|
|
1287
|
+
SentryReplay.prototype.addMemoryEntry = function () {
|
|
1254
1288
|
// window.performance.memory is a non-standard API and doesn't work on all browsers
|
|
1255
1289
|
// so we check before creating the event.
|
|
1256
|
-
if ('memory' in window.performance) {
|
|
1257
|
-
|
|
1258
|
-
entryEvents.push(createMemoryEntry(window.performance.memory));
|
|
1290
|
+
if (!('memory' in window.performance)) {
|
|
1291
|
+
return;
|
|
1259
1292
|
}
|
|
1260
|
-
this.createPerformanceSpans(
|
|
1293
|
+
return this.createPerformanceSpans([
|
|
1294
|
+
// @ts-expect-error memory doesn't exist on type Performance as the API is non-standard (we check that it exists above)
|
|
1295
|
+
createMemoryEntry(window.performance.memory),
|
|
1296
|
+
]);
|
|
1261
1297
|
};
|
|
1262
1298
|
/**
|
|
1263
1299
|
*
|
|
@@ -1329,10 +1365,19 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1329
1365
|
console.error(new Error('[Sentry]: No transaction, no replay'));
|
|
1330
1366
|
return [2 /*return*/];
|
|
1331
1367
|
}
|
|
1332
|
-
|
|
1368
|
+
// Since already flushing, ensure other queued flushes are cancelled
|
|
1369
|
+
clearTimeout(this.timeout);
|
|
1370
|
+
return [4 /*yield*/, this.addPerformanceEntries()];
|
|
1371
|
+
case 1:
|
|
1372
|
+
_a.sent();
|
|
1333
1373
|
if (!this.eventBuffer.length) {
|
|
1334
1374
|
return [2 /*return*/];
|
|
1335
1375
|
}
|
|
1376
|
+
// Only attach memory event if eventBuffer is not empty
|
|
1377
|
+
return [4 /*yield*/, this.addMemoryEntry()];
|
|
1378
|
+
case 2:
|
|
1379
|
+
// Only attach memory event if eventBuffer is not empty
|
|
1380
|
+
_a.sent();
|
|
1336
1381
|
timestamp = lastActivity !== null && lastActivity !== void 0 ? lastActivity : new Date().getTime();
|
|
1337
1382
|
// Only want to create replay event if session is new
|
|
1338
1383
|
if (this.needsCaptureReplay) {
|
|
@@ -1343,14 +1388,14 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1343
1388
|
// Reset this to null regardless of `sendReplay` result so that future
|
|
1344
1389
|
// events will get flushed properly
|
|
1345
1390
|
this.initialEventTimestampSinceFlush = null;
|
|
1346
|
-
_a.label =
|
|
1347
|
-
case
|
|
1348
|
-
_a.trys.push([
|
|
1391
|
+
_a.label = 3;
|
|
1392
|
+
case 3:
|
|
1393
|
+
_a.trys.push([3, 6, , 7]);
|
|
1349
1394
|
return [4 /*yield*/, this.eventBuffer.finish()];
|
|
1350
|
-
case
|
|
1395
|
+
case 4:
|
|
1351
1396
|
recordingData = _a.sent();
|
|
1352
1397
|
return [4 /*yield*/, this.sendReplay(this.session.id, recordingData)];
|
|
1353
|
-
case
|
|
1398
|
+
case 5:
|
|
1354
1399
|
_a.sent();
|
|
1355
1400
|
// The below will only happen after successfully sending replay //
|
|
1356
1401
|
// TBD: Alternatively we could update this after every rrweb event
|
|
@@ -1359,12 +1404,13 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1359
1404
|
// occurs.
|
|
1360
1405
|
this.updateLastActivity(timestamp);
|
|
1361
1406
|
captureReplayUpdate(this.popEventContext({ timestamp: timestamp }));
|
|
1362
|
-
return [3 /*break*/,
|
|
1363
|
-
case
|
|
1407
|
+
return [3 /*break*/, 7];
|
|
1408
|
+
case 6:
|
|
1364
1409
|
err_1 = _a.sent();
|
|
1410
|
+
captureException(err_1);
|
|
1365
1411
|
console.error(err_1);
|
|
1366
|
-
return [3 /*break*/,
|
|
1367
|
-
case
|
|
1412
|
+
return [3 /*break*/, 7];
|
|
1413
|
+
case 7: return [2 /*return*/];
|
|
1368
1414
|
}
|
|
1369
1415
|
});
|
|
1370
1416
|
});
|
|
@@ -1375,27 +1421,41 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1375
1421
|
SentryReplay.prototype.sendReplayRequest = function (_a) {
|
|
1376
1422
|
var endpoint = _a.endpoint, events = _a.events;
|
|
1377
1423
|
return __awaiter(this, void 0, void 0, function () {
|
|
1378
|
-
var
|
|
1424
|
+
var payloadWithSequence, envelope;
|
|
1379
1425
|
return __generator(this, function (_b) {
|
|
1380
1426
|
switch (_b.label) {
|
|
1381
1427
|
case 0:
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1428
|
+
payloadWithSequence = createPayload({
|
|
1429
|
+
events: events,
|
|
1430
|
+
headers: {
|
|
1431
|
+
segment_id: this.session.segmentId,
|
|
1432
|
+
},
|
|
1385
1433
|
});
|
|
1386
|
-
|
|
1387
|
-
|
|
1434
|
+
envelope = createEnvelope({
|
|
1435
|
+
event_id: this.session.id,
|
|
1436
|
+
sent_at: new Date().toISOString(),
|
|
1437
|
+
sdk: { name: 'sentry.javascript.integration.replay', version: '1.0.0' },
|
|
1438
|
+
}, [
|
|
1439
|
+
[
|
|
1440
|
+
{
|
|
1441
|
+
// @ts-expect-error setting envelope
|
|
1442
|
+
type: 'replay_recording',
|
|
1443
|
+
length: payloadWithSequence.length,
|
|
1444
|
+
},
|
|
1445
|
+
payloadWithSequence,
|
|
1446
|
+
],
|
|
1447
|
+
]);
|
|
1388
1448
|
// If sendBeacon is supported and payload is smol enough...
|
|
1389
|
-
if (supportsSendBeacon() &&
|
|
1449
|
+
if (supportsSendBeacon() && events.length <= 65536) {
|
|
1390
1450
|
logger.log("uploading attachment via sendBeacon()");
|
|
1391
|
-
window.navigator.sendBeacon(endpoint,
|
|
1451
|
+
window.navigator.sendBeacon(endpoint, serializeEnvelope(envelope));
|
|
1392
1452
|
return [2 /*return*/];
|
|
1393
1453
|
}
|
|
1394
1454
|
// Otherwise use `fetch`, which *WILL* get cancelled on page reloads/unloads
|
|
1395
1455
|
logger.log("uploading attachment via fetch()");
|
|
1396
1456
|
return [4 /*yield*/, fetch(endpoint, {
|
|
1397
1457
|
method: 'POST',
|
|
1398
|
-
body:
|
|
1458
|
+
body: serializeEnvelope(envelope),
|
|
1399
1459
|
})];
|
|
1400
1460
|
case 1:
|
|
1401
1461
|
_b.sent();
|
|
@@ -1423,7 +1483,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1423
1483
|
return [2 /*return*/];
|
|
1424
1484
|
}
|
|
1425
1485
|
client = getCurrentHub().getClient();
|
|
1426
|
-
endpoint =
|
|
1486
|
+
endpoint = getEnvelopeEndpointWithUrlEncodedAuth(client.getDsn());
|
|
1427
1487
|
_b.label = 1;
|
|
1428
1488
|
case 1:
|
|
1429
1489
|
_b.trys.push([1, 3, , 8]);
|