@sentry/replay 0.4.8-3 → 0.4.8
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/README.md +15 -15
- package/dist/config/dist/src/api/captureReplay.d.ts +5 -3
- package/dist/config/dist/src/api/captureReplayUpdate.d.ts +5 -3
- package/dist/config/dist/src/coreHandlers/getBreadcrumbHandler.d.ts +3 -0
- package/dist/config/dist/src/coreHandlers/getSpanHandler.d.ts +5 -0
- package/dist/config/dist/src/coreHandlers/handleFetch.d.ts +19 -2
- package/dist/config/dist/src/coreHandlers/handleHistory.d.ts +7 -0
- package/dist/config/dist/src/coreHandlers/handleXhr.d.ts +21 -2
- package/dist/config/dist/src/index.d.ts +18 -7
- package/dist/config/dist/src/types.d.ts +20 -8
- package/dist/config/dist/src/util/createPayload.d.ts +5 -0
- package/dist/dist/api/captureReplay.d.ts +5 -3
- package/dist/dist/api/captureReplayUpdate.d.ts +5 -3
- package/dist/dist/coreHandlers/getBreadcrumbHandler.d.ts +3 -0
- package/dist/dist/coreHandlers/getSpanHandler.d.ts +5 -0
- package/dist/dist/coreHandlers/handleFetch.d.ts +19 -2
- package/dist/dist/coreHandlers/handleHistory.d.ts +7 -0
- package/dist/dist/coreHandlers/handleXhr.d.ts +21 -2
- package/dist/dist/index.d.ts +18 -7
- package/dist/dist/types.d.ts +20 -8
- package/dist/index.es.js +219 -122
- package/dist/index.js +218 -121
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/dist/coreHandlers/index.d.ts +0 -4
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { captureEvent, getCurrentHub, captureException, addGlobalEventProcessor } from '@sentry/core';
|
|
2
|
-
import { uuid4, logger as logger$1,
|
|
2
|
+
import { uuid4, htmlTreeAsString, logger as logger$1, addInstrumentationHandler } from '@sentry/utils';
|
|
3
3
|
import { record, EventType } from 'rrweb';
|
|
4
4
|
|
|
5
5
|
/******************************************************************************
|
|
@@ -97,19 +97,27 @@ var SESSION_IDLE_DURATION = 900000; // 15 minutes
|
|
|
97
97
|
var VISIBILITY_CHANGE_TIMEOUT = SESSION_IDLE_DURATION;
|
|
98
98
|
|
|
99
99
|
function captureReplay(_a) {
|
|
100
|
-
var session = _a.session, initialState = _a.initialState;
|
|
100
|
+
var session = _a.session, initialState = _a.initialState, errorIds = _a.errorIds, traceIds = _a.traceIds, urls = _a.urls;
|
|
101
101
|
captureEvent({
|
|
102
102
|
message: ROOT_REPLAY_NAME,
|
|
103
103
|
tags: { segmentId: session.segmentId, url: initialState.url },
|
|
104
104
|
timestamp: initialState.timestamp / 1000,
|
|
105
|
+
// @ts-expect-error replay event type accepts this
|
|
106
|
+
error_ids: errorIds,
|
|
107
|
+
trace_ids: traceIds,
|
|
108
|
+
urls: urls,
|
|
105
109
|
}, { event_id: session.id });
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
function captureReplayUpdate(_a) {
|
|
109
|
-
var session = _a.session, timestamp = _a.timestamp;
|
|
113
|
+
var session = _a.session, timestamp = _a.timestamp, errorIds = _a.errorIds, traceIds = _a.traceIds, urls = _a.urls;
|
|
110
114
|
captureEvent({
|
|
111
115
|
timestamp: timestamp / 1000,
|
|
112
116
|
message: "".concat(REPLAY_EVENT_NAME, "-").concat(uuid4().substring(16)),
|
|
117
|
+
// @ts-expect-error replay event type accepts this
|
|
118
|
+
error_ids: errorIds,
|
|
119
|
+
trace_ids: traceIds,
|
|
120
|
+
urls: urls,
|
|
113
121
|
tags: {
|
|
114
122
|
replayId: session.id,
|
|
115
123
|
segmentId: session.segmentId++,
|
|
@@ -117,6 +125,143 @@ function captureReplayUpdate(_a) {
|
|
|
117
125
|
});
|
|
118
126
|
}
|
|
119
127
|
|
|
128
|
+
function createBreadcrumb(breadcrumb) {
|
|
129
|
+
return __assign({ timestamp: new Date().getTime() / 1000, type: 'default' }, breadcrumb);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function handleDom(handlerData) {
|
|
133
|
+
// Taken from https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/integrations/breadcrumbs.ts#L112
|
|
134
|
+
var target;
|
|
135
|
+
var targetNode;
|
|
136
|
+
// Accessing event.target can throw (see getsentry/raven-js#838, #768)
|
|
137
|
+
try {
|
|
138
|
+
targetNode =
|
|
139
|
+
handlerData.event.target ||
|
|
140
|
+
handlerData.event;
|
|
141
|
+
target = htmlTreeAsString(targetNode);
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
target = '<unknown>';
|
|
145
|
+
}
|
|
146
|
+
if (target.length === 0) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
return createBreadcrumb({
|
|
150
|
+
category: "ui.".concat(handlerData.name),
|
|
151
|
+
message: target,
|
|
152
|
+
data: __assign({}, (targetNode ? { nodeId: record.mirror.getId(targetNode) } : {})),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
var _LAST_BREADCRUMB = null;
|
|
157
|
+
function handleScope(scope) {
|
|
158
|
+
var _a;
|
|
159
|
+
//@ts-expect-error using private val
|
|
160
|
+
var newBreadcrumb = scope._breadcrumbs[scope._breadcrumbs.length - 1];
|
|
161
|
+
// Listener can be called when breadcrumbs have not changed, so we store the
|
|
162
|
+
// reference to the last crumb and only return a crumb if it has changed
|
|
163
|
+
if (_LAST_BREADCRUMB === newBreadcrumb || !newBreadcrumb) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
_LAST_BREADCRUMB = newBreadcrumb;
|
|
167
|
+
if (['fetch', 'xhr', 'sentry.event', 'sentry.transaction'].includes(newBreadcrumb.category) ||
|
|
168
|
+
((_a = newBreadcrumb.category) === null || _a === void 0 ? void 0 : _a.startsWith('ui.'))) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
return createBreadcrumb(newBreadcrumb);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function getBreadcrumbHandler(type) {
|
|
175
|
+
if (type === 'scope') {
|
|
176
|
+
return handleScope;
|
|
177
|
+
}
|
|
178
|
+
return handleDom;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Checks is `targetHost` is a Sentry ingestion host
|
|
183
|
+
*/
|
|
184
|
+
function isIngestHost(targetHost) {
|
|
185
|
+
var _a = getCurrentHub().getClient().getDsn(), protocol = _a.protocol, host = _a.host;
|
|
186
|
+
return targetHost.startsWith("".concat(protocol, "://").concat(host));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function handleFetch(handlerData) {
|
|
190
|
+
if (!handlerData.endTimestamp) {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
var startTimestamp = handlerData.startTimestamp, endTimestamp = handlerData.endTimestamp, fetchData = handlerData.fetchData, response = handlerData.response;
|
|
194
|
+
// Do not capture fetches to Sentry ingestion endpoint
|
|
195
|
+
if (isIngestHost(fetchData.url)) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
type: 'resource.fetch',
|
|
200
|
+
start: startTimestamp / 1000,
|
|
201
|
+
end: endTimestamp / 1000,
|
|
202
|
+
name: fetchData.url,
|
|
203
|
+
data: {
|
|
204
|
+
method: fetchData.method,
|
|
205
|
+
statusCode: response.status,
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function handleHistory(handlerData) {
|
|
211
|
+
var from = handlerData.from, to = handlerData.to;
|
|
212
|
+
var now = new Date().getTime() / 1000;
|
|
213
|
+
return {
|
|
214
|
+
type: 'navigation.push',
|
|
215
|
+
start: now,
|
|
216
|
+
end: now,
|
|
217
|
+
name: to,
|
|
218
|
+
data: {
|
|
219
|
+
previous: from,
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function handleXhr(handlerData) {
|
|
225
|
+
if (handlerData.xhr.__sentry_own_request__) {
|
|
226
|
+
// Taken from sentry-javascript
|
|
227
|
+
// Only capture non-sentry requests
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
if (handlerData.startTimestamp) {
|
|
231
|
+
// TODO: See if this is still needed
|
|
232
|
+
handlerData.xhr.__sentry_xhr__.startTimestamp = handlerData.startTimestamp;
|
|
233
|
+
}
|
|
234
|
+
if (!handlerData.endTimestamp) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
var _a = handlerData.xhr.__sentry_xhr__ || {}, method = _a.method, url = _a.url, statusCode = _a.status_code;
|
|
238
|
+
// Do not capture fetches to Sentry ingestion endpoint
|
|
239
|
+
if (isIngestHost(url)) {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
type: 'resource.xhr',
|
|
244
|
+
name: url,
|
|
245
|
+
start: handlerData.xhr.__sentry_xhr__.startTimestamp / 1000 ||
|
|
246
|
+
handlerData.endTimestamp / 1000.0,
|
|
247
|
+
end: handlerData.endTimestamp / 1000.0,
|
|
248
|
+
data: {
|
|
249
|
+
method: method,
|
|
250
|
+
statusCode: statusCode,
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function getSpanHandler(type) {
|
|
256
|
+
if (type === 'fetch') {
|
|
257
|
+
return handleFetch;
|
|
258
|
+
}
|
|
259
|
+
if (type === 'xhr') {
|
|
260
|
+
return handleXhr;
|
|
261
|
+
}
|
|
262
|
+
return handleHistory;
|
|
263
|
+
}
|
|
264
|
+
|
|
120
265
|
/**
|
|
121
266
|
* Given an initial timestamp and an expiry duration, checks to see if current
|
|
122
267
|
* time should be considered as expired.
|
|
@@ -320,10 +465,6 @@ function getSession(_a) {
|
|
|
320
465
|
return { type: 'new', session: newSession };
|
|
321
466
|
}
|
|
322
467
|
|
|
323
|
-
function createBreadcrumb(breadcrumb) {
|
|
324
|
-
return __assign({ timestamp: new Date().getTime() / 1000, type: 'default' }, breadcrumb);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
468
|
/**
|
|
328
469
|
* Determine if there is browser support for `navigator.sendBeacon`
|
|
329
470
|
*/
|
|
@@ -331,92 +472,6 @@ function supportsSendBeacon() {
|
|
|
331
472
|
return 'navigator' in window && 'sendBeacon' in window.navigator;
|
|
332
473
|
}
|
|
333
474
|
|
|
334
|
-
function handleDom(handlerData) {
|
|
335
|
-
// Taken from https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/integrations/breadcrumbs.ts#L112
|
|
336
|
-
var target;
|
|
337
|
-
var targetNode;
|
|
338
|
-
// Accessing event.target can throw (see getsentry/raven-js#838, #768)
|
|
339
|
-
try {
|
|
340
|
-
targetNode =
|
|
341
|
-
handlerData.event.target ||
|
|
342
|
-
handlerData.event;
|
|
343
|
-
target = htmlTreeAsString(targetNode);
|
|
344
|
-
}
|
|
345
|
-
catch (e) {
|
|
346
|
-
target = '<unknown>';
|
|
347
|
-
}
|
|
348
|
-
if (target.length === 0) {
|
|
349
|
-
return null;
|
|
350
|
-
}
|
|
351
|
-
return createBreadcrumb({
|
|
352
|
-
category: "ui.".concat(handlerData.name),
|
|
353
|
-
message: target,
|
|
354
|
-
data: __assign({}, (targetNode ? { nodeId: record.mirror.getId(targetNode) } : {})),
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
function handleFetch(handlerData) {
|
|
359
|
-
if (!handlerData.endTimestamp) {
|
|
360
|
-
return null;
|
|
361
|
-
}
|
|
362
|
-
var _a = handlerData.args, op = _a[0], description = _a[1];
|
|
363
|
-
return {
|
|
364
|
-
description: description,
|
|
365
|
-
op: op,
|
|
366
|
-
startTimestamp: handlerData.startTimestamp / 1000,
|
|
367
|
-
endTimestamp: handlerData.endTimestamp / 1000,
|
|
368
|
-
data: {
|
|
369
|
-
statusCode: handlerData.response.status,
|
|
370
|
-
},
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
var _LAST_BREADCRUMB = null;
|
|
375
|
-
function handleScope(scope) {
|
|
376
|
-
var _a;
|
|
377
|
-
//@ts-expect-error using private val
|
|
378
|
-
var newBreadcrumb = scope._breadcrumbs[scope._breadcrumbs.length - 1];
|
|
379
|
-
// Listener can be called when breadcrumbs have not changed, so we store the
|
|
380
|
-
// reference to the last crumb and only return a crumb if it has changed
|
|
381
|
-
if (_LAST_BREADCRUMB === newBreadcrumb || !newBreadcrumb) {
|
|
382
|
-
return null;
|
|
383
|
-
}
|
|
384
|
-
_LAST_BREADCRUMB = newBreadcrumb;
|
|
385
|
-
if (['fetch', 'xhr', 'sentry.event', 'sentry.transaction'].includes(newBreadcrumb.category) ||
|
|
386
|
-
((_a = newBreadcrumb.category) === null || _a === void 0 ? void 0 : _a.startsWith('ui.'))) {
|
|
387
|
-
return null;
|
|
388
|
-
}
|
|
389
|
-
return createBreadcrumb(newBreadcrumb);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
function handleXhr(handlerData) {
|
|
393
|
-
if (handlerData.startTimestamp) {
|
|
394
|
-
handlerData.xhr.__sentry_xhr__.startTimestamp = handlerData.startTimestamp;
|
|
395
|
-
}
|
|
396
|
-
if (!handlerData.endTimestamp) {
|
|
397
|
-
return null;
|
|
398
|
-
}
|
|
399
|
-
var _a = handlerData.args, op = _a[0], description = _a[1];
|
|
400
|
-
return {
|
|
401
|
-
description: description,
|
|
402
|
-
op: op,
|
|
403
|
-
startTimestamp: handlerData.xhr.__sentry_xhr__.startTimestamp / 1000 ||
|
|
404
|
-
handlerData.endTimestamp / 1000.0,
|
|
405
|
-
endTimestamp: handlerData.endTimestamp / 1000.0,
|
|
406
|
-
data: {
|
|
407
|
-
statusCode: handlerData.response.status,
|
|
408
|
-
},
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* Checks is `targetHost` is a Sentry ingestion host
|
|
414
|
-
*/
|
|
415
|
-
function isIngestHost(targetHost) {
|
|
416
|
-
var _a = getCurrentHub().getClient().getDsn(), protocol = _a.protocol, host = _a.host;
|
|
417
|
-
return targetHost.startsWith("".concat(protocol, "://").concat(host));
|
|
418
|
-
}
|
|
419
|
-
|
|
420
475
|
var _a;
|
|
421
476
|
// Map entryType -> function to normalize data for event
|
|
422
477
|
var ENTRY_TYPES = (_a = {
|
|
@@ -467,6 +522,10 @@ function createResourceEntry(entry) {
|
|
|
467
522
|
if (isIngestHost(name)) {
|
|
468
523
|
return null;
|
|
469
524
|
}
|
|
525
|
+
// Core SDK handles these
|
|
526
|
+
if (['fetch', 'xmlhttprequest'].includes(initiatorType)) {
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
470
529
|
return {
|
|
471
530
|
type: "".concat(entryType, ".").concat(initiatorType),
|
|
472
531
|
start: getAbsoluteTime(startTime),
|
|
@@ -527,7 +586,6 @@ function createEventBuffer(_a) {
|
|
|
527
586
|
return new EventBufferCompressionWorker(worker);
|
|
528
587
|
}
|
|
529
588
|
else {
|
|
530
|
-
// TODO: Debugging
|
|
531
589
|
captureException(new Error('Unable to create compression worker'));
|
|
532
590
|
}
|
|
533
591
|
}
|
|
@@ -697,10 +755,6 @@ var SentryReplay = /** @class */ (function () {
|
|
|
697
755
|
* Buffer of breadcrumbs to be uploaded
|
|
698
756
|
*/
|
|
699
757
|
this.breadcrumbs = [];
|
|
700
|
-
/**
|
|
701
|
-
* Buffer of replay spans to be uploaded
|
|
702
|
-
*/
|
|
703
|
-
this.replaySpans = [];
|
|
704
758
|
/**
|
|
705
759
|
* List of PerformanceEntry from PerformanceObserver
|
|
706
760
|
*/
|
|
@@ -721,19 +775,30 @@ var SentryReplay = /** @class */ (function () {
|
|
|
721
775
|
* immediately before sending recording)
|
|
722
776
|
*/
|
|
723
777
|
this.needsCaptureReplay = false;
|
|
778
|
+
this.context = {
|
|
779
|
+
errorIds: new Set(),
|
|
780
|
+
traceIds: new Set(),
|
|
781
|
+
urls: [],
|
|
782
|
+
};
|
|
724
783
|
/**
|
|
725
784
|
* Core Sentry SDK global event handler. Attaches `replayId` to all [non-replay]
|
|
726
785
|
* events as a tag. Also handles the case where we only want to capture a reply
|
|
727
786
|
* when an error occurs.
|
|
728
787
|
**/
|
|
729
788
|
this.handleGlobalEvent = function (event) {
|
|
730
|
-
var _a;
|
|
789
|
+
var _a, _b;
|
|
731
790
|
// Do not apply replayId to the root event
|
|
732
791
|
if (event.message === ROOT_REPLAY_NAME ||
|
|
733
792
|
((_a = event.message) === null || _a === void 0 ? void 0 : _a.startsWith(REPLAY_EVENT_NAME))) {
|
|
734
793
|
return event;
|
|
735
794
|
}
|
|
736
795
|
event.tags = __assign(__assign({}, event.tags), { replayId: _this.session.id });
|
|
796
|
+
if (event.type === 'transaction') {
|
|
797
|
+
_this.context.traceIds.add(String(((_b = event.contexts) === null || _b === void 0 ? void 0 : _b.trace.trace_id) || ''));
|
|
798
|
+
return event;
|
|
799
|
+
}
|
|
800
|
+
// XXX: Is it safe to assume that all other events are error events?
|
|
801
|
+
_this.context.errorIds.add(event.event_id);
|
|
737
802
|
// Need to be very careful that this does not cause an infinite loop
|
|
738
803
|
if (_this.options.captureOnlyOnError && event.exception) {
|
|
739
804
|
// TODO: Do we continue to record after?
|
|
@@ -824,25 +889,35 @@ var SentryReplay = /** @class */ (function () {
|
|
|
824
889
|
/**
|
|
825
890
|
* Handler for Sentry Core SDK events.
|
|
826
891
|
*
|
|
827
|
-
*
|
|
892
|
+
* These specific events will create span-like objects in the recording.
|
|
828
893
|
*
|
|
829
894
|
*/
|
|
830
|
-
this.
|
|
831
|
-
var
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
895
|
+
this.handleCoreSpanListener = function (type) { return function (handlerData) {
|
|
896
|
+
var handler = getSpanHandler(type);
|
|
897
|
+
var result = handler(handlerData);
|
|
898
|
+
if (result === null) {
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
if (type === 'history') {
|
|
902
|
+
// Need to collect visited URLs
|
|
903
|
+
_this.context.urls.push(result.name);
|
|
839
904
|
}
|
|
840
|
-
|
|
841
|
-
|
|
905
|
+
_this.addUpdate(function () {
|
|
906
|
+
_this.createPerformanceSpans([result]);
|
|
907
|
+
});
|
|
908
|
+
}; };
|
|
909
|
+
/**
|
|
910
|
+
* Handler for Sentry Core SDK events.
|
|
911
|
+
*
|
|
912
|
+
* These events will create breadcrumb-like objects in the recording.
|
|
913
|
+
*/
|
|
914
|
+
this.handleCoreBreadcrumbListener = function (type) { return function (handlerData) {
|
|
915
|
+
var handler = getBreadcrumbHandler(type);
|
|
916
|
+
var result = handler(handlerData);
|
|
842
917
|
if (result === null) {
|
|
843
918
|
return;
|
|
844
919
|
}
|
|
845
|
-
if (
|
|
920
|
+
if (result.category === 'sentry.transaction') {
|
|
846
921
|
return;
|
|
847
922
|
}
|
|
848
923
|
_this.addUpdate(function () {
|
|
@@ -850,10 +925,9 @@ var SentryReplay = /** @class */ (function () {
|
|
|
850
925
|
type: EventType.Custom,
|
|
851
926
|
// TODO: We were converting from ms to seconds for breadcrumbs, spans,
|
|
852
927
|
// but maybe we should just keep them as milliseconds
|
|
853
|
-
timestamp: result.timestamp * 1000
|
|
854
|
-
result.startTimestamp * 1000,
|
|
928
|
+
timestamp: result.timestamp * 1000,
|
|
855
929
|
data: {
|
|
856
|
-
tag:
|
|
930
|
+
tag: 'breadcrumb',
|
|
857
931
|
payload: result,
|
|
858
932
|
},
|
|
859
933
|
});
|
|
@@ -927,12 +1001,15 @@ var SentryReplay = /** @class */ (function () {
|
|
|
927
1001
|
// replay ID so that we can reference them later in the UI
|
|
928
1002
|
addGlobalEventProcessor(this.handleGlobalEvent);
|
|
929
1003
|
record(__assign(__assign({}, this.recordingOptions), { emit: this.handleRecordingEmit }));
|
|
1004
|
+
var urlPath = "".concat(window.location.pathname).concat(window.location.hash).concat(window.location.search);
|
|
1005
|
+
var url = "".concat(window.location.origin).concat(urlPath);
|
|
930
1006
|
// Otherwise, these will be captured after the first flush, which means the
|
|
931
1007
|
// URL and timestamps could be incorrect
|
|
932
1008
|
this.initialState = {
|
|
933
1009
|
timestamp: new Date().getTime(),
|
|
934
|
-
url:
|
|
1010
|
+
url: url,
|
|
935
1011
|
};
|
|
1012
|
+
this.context.urls.push(url);
|
|
936
1013
|
};
|
|
937
1014
|
/**
|
|
938
1015
|
* We want to batch uploads of replay events. Save events only if
|
|
@@ -989,7 +1066,6 @@ var SentryReplay = /** @class */ (function () {
|
|
|
989
1066
|
SentryReplay.prototype.destroy = function () {
|
|
990
1067
|
logger.log('Destroying instance');
|
|
991
1068
|
this.removeListeners();
|
|
992
|
-
// this.eventBuffer.clear();
|
|
993
1069
|
};
|
|
994
1070
|
SentryReplay.prototype.clearSession = function () {
|
|
995
1071
|
this.session = null;
|
|
@@ -1028,8 +1104,11 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1028
1104
|
window.addEventListener('beforeunload', this.handleWindowUnload);
|
|
1029
1105
|
// Listeners from core SDK //
|
|
1030
1106
|
var scope = getCurrentHub().getScope();
|
|
1031
|
-
scope.addScopeListener(this.
|
|
1032
|
-
addInstrumentationHandler('dom', this.
|
|
1107
|
+
scope.addScopeListener(this.handleCoreBreadcrumbListener('scope'));
|
|
1108
|
+
addInstrumentationHandler('dom', this.handleCoreBreadcrumbListener('dom'));
|
|
1109
|
+
addInstrumentationHandler('fetch', this.handleCoreSpanListener('fetch'));
|
|
1110
|
+
addInstrumentationHandler('xhr', this.handleCoreSpanListener('xhr'));
|
|
1111
|
+
addInstrumentationHandler('history', this.handleCoreSpanListener('history'));
|
|
1033
1112
|
// PerformanceObserver //
|
|
1034
1113
|
if (!('PerformanceObserver' in window)) {
|
|
1035
1114
|
return;
|
|
@@ -1212,6 +1291,24 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1212
1291
|
}
|
|
1213
1292
|
return this.flushUpdate(lastActivity);
|
|
1214
1293
|
};
|
|
1294
|
+
/**
|
|
1295
|
+
* Return and clear context
|
|
1296
|
+
*/
|
|
1297
|
+
SentryReplay.prototype.popEventContext = function (_a) {
|
|
1298
|
+
var timestamp = _a.timestamp;
|
|
1299
|
+
var context = {
|
|
1300
|
+
session: this.session,
|
|
1301
|
+
initialState: this.initialState,
|
|
1302
|
+
timestamp: timestamp,
|
|
1303
|
+
errorIds: Array.from(this.context.errorIds).filter(Boolean),
|
|
1304
|
+
traceIds: Array.from(this.context.traceIds).filter(Boolean),
|
|
1305
|
+
urls: this.context.urls,
|
|
1306
|
+
};
|
|
1307
|
+
this.context.errorIds.clear();
|
|
1308
|
+
this.context.traceIds.clear();
|
|
1309
|
+
this.context.urls = [];
|
|
1310
|
+
return context;
|
|
1311
|
+
};
|
|
1215
1312
|
/**
|
|
1216
1313
|
* Flushes replay event buffer to Sentry.
|
|
1217
1314
|
*
|
|
@@ -1236,10 +1333,11 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1236
1333
|
if (!this.eventBuffer.length) {
|
|
1237
1334
|
return [2 /*return*/];
|
|
1238
1335
|
}
|
|
1336
|
+
timestamp = lastActivity !== null && lastActivity !== void 0 ? lastActivity : new Date().getTime();
|
|
1239
1337
|
// Only want to create replay event if session is new
|
|
1240
1338
|
if (this.needsCaptureReplay) {
|
|
1241
1339
|
// This event needs to exist before calling `sendReplay`
|
|
1242
|
-
captureReplay(
|
|
1340
|
+
captureReplay(this.popEventContext({ timestamp: timestamp }));
|
|
1243
1341
|
this.needsCaptureReplay = false;
|
|
1244
1342
|
}
|
|
1245
1343
|
// Reset this to null regardless of `sendReplay` result so that future
|
|
@@ -1248,7 +1346,6 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1248
1346
|
_a.label = 1;
|
|
1249
1347
|
case 1:
|
|
1250
1348
|
_a.trys.push([1, 4, , 5]);
|
|
1251
|
-
timestamp = lastActivity !== null && lastActivity !== void 0 ? lastActivity : new Date().getTime();
|
|
1252
1349
|
return [4 /*yield*/, this.eventBuffer.finish()];
|
|
1253
1350
|
case 2:
|
|
1254
1351
|
recordingData = _a.sent();
|
|
@@ -1261,7 +1358,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
1261
1358
|
// of the event is passed as an argument in the case where a timeout
|
|
1262
1359
|
// occurs.
|
|
1263
1360
|
this.updateLastActivity(timestamp);
|
|
1264
|
-
captureReplayUpdate(
|
|
1361
|
+
captureReplayUpdate(this.popEventContext({ timestamp: timestamp }));
|
|
1265
1362
|
return [3 /*break*/, 5];
|
|
1266
1363
|
case 4:
|
|
1267
1364
|
err_1 = _a.sent();
|