@sentry/replay 0.2.0-10 → 0.2.0-14
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 +2 -3
- package/dist/index.es.js +254 -121
- package/dist/index.js +253 -121
- package/dist/index.js.map +1 -1
- package/package.json +12 -11
package/README.md
CHANGED
|
@@ -13,13 +13,13 @@ To install the stable version:
|
|
|
13
13
|
with npm:
|
|
14
14
|
|
|
15
15
|
```shell
|
|
16
|
-
npm install --save @sentry/browser @sentry/replay
|
|
16
|
+
npm install --save @sentry/browser @sentry/replay
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
with yarn:
|
|
20
20
|
|
|
21
21
|
```shell
|
|
22
|
-
yarn add @sentry/replay @sentry/browser @sentry/replay
|
|
22
|
+
yarn add @sentry/replay @sentry/browser @sentry/replay
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
## Setup
|
|
@@ -31,7 +31,6 @@ See the rrweb documentation for advice on configuring these values.
|
|
|
31
31
|
```javascript
|
|
32
32
|
import * as Sentry from '@sentry/browser';
|
|
33
33
|
import { SentryReplay } from '@sentry/replay';
|
|
34
|
-
import '@sentry/tracing';
|
|
35
34
|
|
|
36
35
|
Sentry.init({
|
|
37
36
|
dsn: '__DSN__',
|
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as Sentry from '@sentry/browser';
|
|
2
|
+
import { getCurrentHub, captureEvent } from '@sentry/browser';
|
|
3
|
+
import { logger as logger$1, uuid4, htmlTreeAsString, addInstrumentationHandler } from '@sentry/utils';
|
|
2
4
|
import { record } from 'rrweb';
|
|
3
|
-
import { logger as logger$1 } from '@sentry/utils';
|
|
4
5
|
|
|
5
6
|
/*! *****************************************************************************
|
|
6
7
|
Copyright (c) Microsoft Corporation.
|
|
@@ -154,7 +155,7 @@ function createLargestContentfulPaint(entry) {
|
|
|
154
155
|
end: start + duration,
|
|
155
156
|
data: {
|
|
156
157
|
size: size,
|
|
157
|
-
//
|
|
158
|
+
// Not sure why this errors, Node should be correct (Argument of type 'Node' is not assignable to parameter of type 'INode')
|
|
158
159
|
nodeId: record.mirror.getId(entry.element),
|
|
159
160
|
},
|
|
160
161
|
};
|
|
@@ -246,25 +247,18 @@ function saveSession(session) {
|
|
|
246
247
|
function createSession(_a) {
|
|
247
248
|
var _b = _a.stickySession, stickySession = _b === void 0 ? false : _b;
|
|
248
249
|
var currentDate = new Date().getTime();
|
|
249
|
-
|
|
250
|
-
var transaction = Sentry.getCurrentHub().startTransaction({
|
|
251
|
-
name: ROOT_REPLAY_NAME,
|
|
252
|
-
tags: {
|
|
253
|
-
isReplayRoot: 'yes',
|
|
254
|
-
},
|
|
255
|
-
});
|
|
256
|
-
// We have to finish the transaction to get an event ID to be able to
|
|
257
|
-
// upload an attachment for that event
|
|
258
|
-
// @ts-expect-error This returns an eventId (string), but is not typed as such
|
|
259
|
-
var id = transaction.finish();
|
|
260
|
-
logger.log("Creating new session: ".concat(id));
|
|
250
|
+
var hub = getCurrentHub();
|
|
261
251
|
var session = {
|
|
262
|
-
id:
|
|
263
|
-
spanId: transaction.spanId,
|
|
264
|
-
traceId: transaction.traceId,
|
|
252
|
+
id: uuid4(),
|
|
265
253
|
started: currentDate,
|
|
266
254
|
lastActivity: currentDate,
|
|
255
|
+
sequenceId: 0,
|
|
267
256
|
};
|
|
257
|
+
hub.captureEvent({
|
|
258
|
+
message: ROOT_REPLAY_NAME,
|
|
259
|
+
tags: { sequenceId: session.sequenceId },
|
|
260
|
+
}, { event_id: session.id });
|
|
261
|
+
logger.log("Creating new session: ".concat(session.id));
|
|
268
262
|
if (stickySession) {
|
|
269
263
|
saveSession(session);
|
|
270
264
|
}
|
|
@@ -288,8 +282,8 @@ function fetchSession() {
|
|
|
288
282
|
* Get or create a session
|
|
289
283
|
*/
|
|
290
284
|
function getSession(_a) {
|
|
291
|
-
var expiry = _a.expiry, stickySession = _a.stickySession;
|
|
292
|
-
var session = stickySession
|
|
285
|
+
var expiry = _a.expiry, currentSession = _a.currentSession, stickySession = _a.stickySession;
|
|
286
|
+
var session = stickySession ? fetchSession() : currentSession;
|
|
293
287
|
if (session) {
|
|
294
288
|
// If there is a session, check if it is valid (e.g. "last activity" time should be within the "session idle time")
|
|
295
289
|
// TODO: We should probably set a max age on this as well
|
|
@@ -325,6 +319,74 @@ function updateSessionActivity(_a) {
|
|
|
325
319
|
return newSession;
|
|
326
320
|
}
|
|
327
321
|
|
|
322
|
+
function handleDom(handlerData) {
|
|
323
|
+
// Taken from https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/integrations/breadcrumbs.ts#L112
|
|
324
|
+
var target;
|
|
325
|
+
var targetNode;
|
|
326
|
+
// Accessing event.target can throw (see getsentry/raven-js#838, #768)
|
|
327
|
+
try {
|
|
328
|
+
targetNode =
|
|
329
|
+
handlerData.event.target ||
|
|
330
|
+
handlerData.event;
|
|
331
|
+
target = htmlTreeAsString(targetNode);
|
|
332
|
+
}
|
|
333
|
+
catch (e) {
|
|
334
|
+
target = '<unknown>';
|
|
335
|
+
}
|
|
336
|
+
if (target.length === 0) {
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
return {
|
|
340
|
+
timestamp: new Date().getTime() / 1000,
|
|
341
|
+
type: 'default',
|
|
342
|
+
category: "ui.".concat(handlerData.name),
|
|
343
|
+
message: target,
|
|
344
|
+
data: __assign({}, (targetNode ? { nodeId: record.mirror.getId(targetNode) } : {})),
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function handleFetch(handlerData) {
|
|
349
|
+
// TODO: add status code into data, etc.
|
|
350
|
+
if (!handlerData.endTimestamp) {
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
return {
|
|
354
|
+
description: handlerData.args[1],
|
|
355
|
+
op: handlerData.args[0],
|
|
356
|
+
startTimestamp: handlerData.startTimestamp / 1000,
|
|
357
|
+
endTimestamp: handlerData.endTimestamp / 1000,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function handleScope(scope) {
|
|
362
|
+
//@ts-expect-error using private val
|
|
363
|
+
var newBreadcrumb = scope._breadcrumbs[scope._breadcrumbs.length - 1];
|
|
364
|
+
if (['fetch', 'xhr', 'sentry.event'].includes(newBreadcrumb.category) ||
|
|
365
|
+
newBreadcrumb.category.startsWith('ui.')) {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
return __assign({ type: 'default' }, newBreadcrumb);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function handleXhr(handlerData) {
|
|
372
|
+
// TODO: add status code into data, etc.
|
|
373
|
+
if (handlerData.startTimestamp) {
|
|
374
|
+
handlerData.xhr.__sentry_xhr__.startTimestamp = handlerData.startTimestamp;
|
|
375
|
+
}
|
|
376
|
+
if (!handlerData.endTimestamp) {
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
return {
|
|
380
|
+
description: handlerData.args[1],
|
|
381
|
+
op: handlerData.args[0],
|
|
382
|
+
startTimestamp: handlerData.xhr.__sentry_xhr__.startTimestamp / 1000 ||
|
|
383
|
+
handlerData.endTimestamp / 1000.0,
|
|
384
|
+
endTimestamp: handlerData.endTimestamp / 1000.0,
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
var BASE_RETRY_INTERVAL = 5000;
|
|
389
|
+
var MAX_RETRY_COUNT = 5;
|
|
328
390
|
var SentryReplay = /** @class */ (function () {
|
|
329
391
|
function SentryReplay(_a) {
|
|
330
392
|
if (_a === void 0) { _a = {}; }
|
|
@@ -340,6 +402,17 @@ var SentryReplay = /** @class */ (function () {
|
|
|
340
402
|
* Buffer of rrweb events that will be serialized as JSON and saved as an attachment to a Sentry event
|
|
341
403
|
*/
|
|
342
404
|
this.events = [];
|
|
405
|
+
/**
|
|
406
|
+
* Buffer of breadcrumbs to be uploaded
|
|
407
|
+
*/
|
|
408
|
+
this.breadcrumbs = [];
|
|
409
|
+
/**
|
|
410
|
+
* Buffer of replay spans to be uploaded
|
|
411
|
+
*/
|
|
412
|
+
this.replaySpans = [];
|
|
413
|
+
/**
|
|
414
|
+
* List of PerformanceEntry from PerformanceObserver
|
|
415
|
+
*/
|
|
343
416
|
this.performanceEvents = [];
|
|
344
417
|
/**
|
|
345
418
|
* The timestamp of the first event since the last flush.
|
|
@@ -347,14 +420,8 @@ var SentryReplay = /** @class */ (function () {
|
|
|
347
420
|
*/
|
|
348
421
|
this.initialEventTimestampSinceFlush = null;
|
|
349
422
|
this.performanceObserver = null;
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
*/
|
|
353
|
-
this.handlePerformanceObserver = function (list
|
|
354
|
-
// observer: PerformanceObserver
|
|
355
|
-
) {
|
|
356
|
-
_this.performanceEvents = __spreadArray(__spreadArray([], _this.performanceEvents, true), list.getEntries(), true);
|
|
357
|
-
};
|
|
423
|
+
this.retryCount = 0;
|
|
424
|
+
this.retryInterval = BASE_RETRY_INTERVAL;
|
|
358
425
|
/**
|
|
359
426
|
* Handle when visibility of the page changes. (e.g. new tab is opened)
|
|
360
427
|
*/
|
|
@@ -381,25 +448,51 @@ var SentryReplay = /** @class */ (function () {
|
|
|
381
448
|
// Update with current timestamp as the last session activity
|
|
382
449
|
// Only updating session on visibility change to be conservative about
|
|
383
450
|
// writing to session storage. This could be changed in the future.
|
|
384
|
-
updateSessionActivity({
|
|
451
|
+
_this.updateSession(updateSessionActivity({
|
|
385
452
|
stickySession: _this.options.stickySession,
|
|
386
|
-
});
|
|
453
|
+
}));
|
|
387
454
|
// Send replay when the page/tab becomes hidden. There is no reason to send
|
|
388
455
|
// replay if it becomes visible, since no actions we care about were done
|
|
389
456
|
// while it was hidden
|
|
390
457
|
if (document.visibilityState !== 'visible') {
|
|
391
|
-
_this.
|
|
458
|
+
_this.flushUpdate();
|
|
392
459
|
}
|
|
393
460
|
};
|
|
461
|
+
this.handleCoreListener = function (type) { return function (handlerData) {
|
|
462
|
+
var handlerMap = {
|
|
463
|
+
scope: [handleScope, _this.breadcrumbs],
|
|
464
|
+
dom: [handleDom, _this.breadcrumbs],
|
|
465
|
+
fetch: [handleFetch, _this.replaySpans],
|
|
466
|
+
xhr: [handleXhr, _this.replaySpans],
|
|
467
|
+
};
|
|
468
|
+
if (!(type in handlerMap)) {
|
|
469
|
+
throw new Error("No handler defined for type: ".concat(type));
|
|
470
|
+
}
|
|
471
|
+
var _a = handlerMap[type], handlerFn = _a[0], handlerStore = _a[1];
|
|
472
|
+
var result = handlerFn(handlerData);
|
|
473
|
+
if (result === null) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
handlerStore.push(result);
|
|
477
|
+
_this.addUpdate();
|
|
478
|
+
}; };
|
|
479
|
+
/**
|
|
480
|
+
* Keep a list of performance entries that will be sent with a replay
|
|
481
|
+
*/
|
|
482
|
+
this.handlePerformanceObserver = function (list
|
|
483
|
+
// observer: PerformanceObserver
|
|
484
|
+
) {
|
|
485
|
+
_this.performanceEvents = __spreadArray(__spreadArray([], _this.performanceEvents, true), list.getEntries(), true);
|
|
486
|
+
};
|
|
394
487
|
this.rrwebRecordOptions = __assign({ maskAllInputs: maskAllInputs, blockClass: blockClass, ignoreClass: ignoreClass, maskTextClass: maskTextClass }, rrwebRecordOptions);
|
|
395
488
|
this.options = { uploadMinDelay: uploadMinDelay, uploadMaxDelay: uploadMaxDelay, stickySession: stickySession };
|
|
396
489
|
this.events = [];
|
|
397
490
|
}
|
|
398
491
|
SentryReplay.attachmentUrlFromDsn = function (dsn, eventId) {
|
|
399
|
-
var host = dsn.host, projectId = dsn.projectId, protocol = dsn.protocol,
|
|
492
|
+
var host = dsn.host, projectId = dsn.projectId, protocol = dsn.protocol, publicKey = dsn.publicKey;
|
|
400
493
|
var port = dsn.port !== '' ? ":".concat(dsn.port) : '';
|
|
401
494
|
var path = dsn.path !== '' ? "/".concat(dsn.path) : '';
|
|
402
|
-
return "".concat(protocol, "://").concat(host).concat(port).concat(path, "/api/").concat(projectId, "/events/").concat(eventId, "/attachments/?sentry_key=").concat(
|
|
495
|
+
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");
|
|
403
496
|
};
|
|
404
497
|
SentryReplay.prototype.setupOnce = function () {
|
|
405
498
|
var _this = this;
|
|
@@ -420,71 +513,83 @@ var SentryReplay = /** @class */ (function () {
|
|
|
420
513
|
if (!this.session) {
|
|
421
514
|
throw new Error('Invalid session');
|
|
422
515
|
}
|
|
516
|
+
this.addListeners();
|
|
423
517
|
// Tag all (non replay) events that get sent to Sentry with the current
|
|
424
518
|
// replay ID so that we can reference them later in the UI
|
|
425
519
|
Sentry.addGlobalEventProcessor(function (event) {
|
|
426
|
-
// Do not apply replayId to the root
|
|
427
|
-
if (event.
|
|
520
|
+
// Do not apply replayId to the root event
|
|
521
|
+
if (event.message === ROOT_REPLAY_NAME) {
|
|
428
522
|
return event;
|
|
429
523
|
}
|
|
430
524
|
event.tags = __assign(__assign({}, event.tags), { replayId: _this.session.id });
|
|
431
525
|
return event;
|
|
432
526
|
});
|
|
433
|
-
// not fully initialized and the event will not get properly sent to Sentry
|
|
434
|
-
this.createReplayEvent();
|
|
435
527
|
record(__assign(__assign({}, this.rrwebRecordOptions), { emit: function (event, isCheckout) {
|
|
436
|
-
// We want to batch uploads of replay events. Save events only if
|
|
437
|
-
// `<uploadMinDelay>` milliseconds have elapsed since the last event
|
|
438
|
-
// *OR* if `<uploadMaxDelay>` milliseconds have elapsed.
|
|
439
|
-
var now = new Date().getTime();
|
|
440
|
-
// Timestamp of the first replay event since the last flush, this gets
|
|
441
|
-
// reset when we finish the replay event
|
|
442
|
-
if (!_this.initialEventTimestampSinceFlush) {
|
|
443
|
-
_this.initialEventTimestampSinceFlush = now;
|
|
444
|
-
}
|
|
445
|
-
// Do not finish the replay event if we receive a new replay event
|
|
446
|
-
if (_this.timeout) {
|
|
447
|
-
window.clearTimeout(_this.timeout);
|
|
448
|
-
}
|
|
449
528
|
// If this is false, it means session is expired, create and a new session and wait for checkout
|
|
450
529
|
if (!_this.checkAndHandleExpiredSession()) {
|
|
451
530
|
logger.error(new Error('Received replay event after session expired.'));
|
|
452
531
|
return;
|
|
453
532
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
// Otherwise schedule it to be finished in `this.options.uploadMinDelay`
|
|
474
|
-
if (uploadMaxDelayExceeded) {
|
|
475
|
-
logger.log('replay max delay exceeded, finishing replay event');
|
|
476
|
-
_this.finishReplayEvent();
|
|
477
|
-
return;
|
|
478
|
-
}
|
|
479
|
-
// Set timer to finish replay event and send replay attachment to
|
|
480
|
-
// Sentry. Will be cancelled if an event happens before `uploadMinDelay`
|
|
481
|
-
// elapses.
|
|
482
|
-
_this.timeout = window.setTimeout(function () {
|
|
483
|
-
logger.log('replay timeout exceeded, finishing replay event');
|
|
484
|
-
_this.finishReplayEvent();
|
|
485
|
-
}, _this.options.uploadMinDelay);
|
|
533
|
+
_this.addUpdate(function () {
|
|
534
|
+
// We need to clear existing events on a checkout, otherwise they are
|
|
535
|
+
// incremental event updates and should be appended
|
|
536
|
+
if (isCheckout) {
|
|
537
|
+
_this.events = [event];
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
_this.events.push(event);
|
|
541
|
+
}
|
|
542
|
+
// This event type is a fullsnapshot, we should save immediately when this occurs
|
|
543
|
+
// See https://github.com/rrweb-io/rrweb/blob/d8f9290ca496712aa1e7d472549480c4e7876594/packages/rrweb/src/types.ts#L16
|
|
544
|
+
if (event.type === 2) {
|
|
545
|
+
// A fullsnapshot happens on initial load and if we need to start a
|
|
546
|
+
// new replay due to idle timeout. In the latter case, a new session *should* have been started
|
|
547
|
+
// before triggering a new checkout
|
|
548
|
+
return true;
|
|
549
|
+
}
|
|
550
|
+
return false;
|
|
551
|
+
});
|
|
486
552
|
} }));
|
|
487
|
-
|
|
553
|
+
};
|
|
554
|
+
/**
|
|
555
|
+
* We want to batch uploads of replay events. Save events only if
|
|
556
|
+
* `<uploadMinDelay>` milliseconds have elapsed since the last event
|
|
557
|
+
* *OR* if `<uploadMaxDelay>` milliseconds have elapsed.
|
|
558
|
+
*
|
|
559
|
+
* Accepts a callback to perform side-effects and returns a boolean value if we
|
|
560
|
+
* should flush events immediately
|
|
561
|
+
*/
|
|
562
|
+
SentryReplay.prototype.addUpdate = function (cb) {
|
|
563
|
+
var _this = this;
|
|
564
|
+
var now = new Date().getTime();
|
|
565
|
+
// Timestamp of the first replay event since the last flush, this gets
|
|
566
|
+
// reset when we finish the replay event
|
|
567
|
+
if (!this.initialEventTimestampSinceFlush) {
|
|
568
|
+
this.initialEventTimestampSinceFlush = now;
|
|
569
|
+
}
|
|
570
|
+
// Do not finish the replay event if we receive a new replay event
|
|
571
|
+
if (this.timeout) {
|
|
572
|
+
window.clearTimeout(this.timeout);
|
|
573
|
+
}
|
|
574
|
+
if ((cb === null || cb === void 0 ? void 0 : cb()) === true) {
|
|
575
|
+
this.flushUpdate();
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
var uploadMaxDelayExceeded = isExpired(this.initialEventTimestampSinceFlush, this.options.uploadMaxDelay, now);
|
|
579
|
+
// If `uploadMaxDelayExceeded` is true, then we should finish the replay event immediately,
|
|
580
|
+
// Otherwise schedule it to be finished in `this.options.uploadMinDelay`
|
|
581
|
+
if (uploadMaxDelayExceeded) {
|
|
582
|
+
logger.log('replay max delay exceeded, finishing replay event');
|
|
583
|
+
this.flushUpdate();
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
// Set timer to finish replay event and send replay attachment to
|
|
587
|
+
// Sentry. Will be cancelled if an event happens before `uploadMinDelay`
|
|
588
|
+
// elapses.
|
|
589
|
+
this.timeout = window.setTimeout(function () {
|
|
590
|
+
logger.log('replay timeout exceeded, finishing replay event');
|
|
591
|
+
_this.flushUpdate();
|
|
592
|
+
}, this.options.uploadMinDelay);
|
|
488
593
|
};
|
|
489
594
|
/**
|
|
490
595
|
* Currently, this needs to be manually called (e.g. for tests). Sentry SDK does not support a teardown
|
|
@@ -492,6 +597,9 @@ var SentryReplay = /** @class */ (function () {
|
|
|
492
597
|
SentryReplay.prototype.teardown = function () {
|
|
493
598
|
this.removeListeners();
|
|
494
599
|
};
|
|
600
|
+
SentryReplay.prototype.clearSession = function () {
|
|
601
|
+
this.session = null;
|
|
602
|
+
};
|
|
495
603
|
/**
|
|
496
604
|
* Loads a session from storage, or creates a new one
|
|
497
605
|
*/
|
|
@@ -500,11 +608,20 @@ var SentryReplay = /** @class */ (function () {
|
|
|
500
608
|
this.session = getSession({
|
|
501
609
|
expiry: expiry,
|
|
502
610
|
stickySession: this.options.stickySession,
|
|
611
|
+
currentSession: this.session,
|
|
503
612
|
});
|
|
504
613
|
};
|
|
614
|
+
SentryReplay.prototype.updateSession = function (session) {
|
|
615
|
+
this.session = __assign(__assign({}, this.session), session);
|
|
616
|
+
};
|
|
505
617
|
SentryReplay.prototype.addListeners = function () {
|
|
506
618
|
var _this = this;
|
|
507
619
|
document.addEventListener('visibilitychange', this.handleVisibilityChange);
|
|
620
|
+
// Listeners from core SDK //
|
|
621
|
+
var scope = Sentry.getCurrentHub().getScope();
|
|
622
|
+
scope.addScopeListener(this.handleCoreListener('scope'));
|
|
623
|
+
addInstrumentationHandler('dom', this.handleCoreListener('dom'));
|
|
624
|
+
// PerformanceObserver //
|
|
508
625
|
if (!('PerformanceObserver' in window)) {
|
|
509
626
|
return;
|
|
510
627
|
}
|
|
@@ -542,40 +659,20 @@ var SentryReplay = /** @class */ (function () {
|
|
|
542
659
|
logger.log('Taking full rrweb snapshot');
|
|
543
660
|
record.takeFullSnapshot(true);
|
|
544
661
|
};
|
|
545
|
-
/**
|
|
546
|
-
* This is our pseudo replay event disguised as a transaction. It will be
|
|
547
|
-
* used to store performance entries and breadcrumbs for every incremental
|
|
548
|
-
* replay event.
|
|
549
|
-
**/
|
|
550
|
-
SentryReplay.prototype.createReplayEvent = function () {
|
|
551
|
-
var _this = this;
|
|
552
|
-
logger.log('CreateReplayEvent rootReplayId', this.session.id);
|
|
553
|
-
this.replayEvent = Sentry.getCurrentHub().startTransaction({
|
|
554
|
-
name: REPLAY_EVENT_NAME,
|
|
555
|
-
parentSpanId: this.session.spanId,
|
|
556
|
-
traceId: this.session.traceId,
|
|
557
|
-
tags: {
|
|
558
|
-
replayId: this.session.id,
|
|
559
|
-
},
|
|
560
|
-
});
|
|
561
|
-
Sentry.configureScope(function (scope) { return scope.setSpan(_this.replayEvent); });
|
|
562
|
-
return this.replayEvent;
|
|
563
|
-
};
|
|
564
662
|
/**
|
|
565
663
|
* Create a span for each performance entry. The parent transaction is `this.replayEvent`.
|
|
566
664
|
*/
|
|
567
665
|
SentryReplay.prototype.createPerformanceSpans = function (entries) {
|
|
568
666
|
var _this = this;
|
|
569
667
|
entries.forEach(function (_a) {
|
|
570
|
-
var _b;
|
|
571
668
|
var type = _a.type, start = _a.start, end = _a.end, name = _a.name, data = _a.data;
|
|
572
|
-
|
|
669
|
+
_this.replaySpans.push({
|
|
573
670
|
op: type,
|
|
574
671
|
description: name,
|
|
575
672
|
startTimestamp: start,
|
|
673
|
+
endTimestamp: end,
|
|
576
674
|
data: data,
|
|
577
675
|
});
|
|
578
|
-
span.finish(end);
|
|
579
676
|
});
|
|
580
677
|
};
|
|
581
678
|
/**
|
|
@@ -594,7 +691,6 @@ var SentryReplay = /** @class */ (function () {
|
|
|
594
691
|
// @ts-expect-error memory doesn't exist on type Performance as the API is non-standard
|
|
595
692
|
entryEvents.push(createMemoryEntry(window.performance.memory));
|
|
596
693
|
}
|
|
597
|
-
// This current implementation is to create spans on the transaction referenced in `this.replayEvent`
|
|
598
694
|
this.createPerformanceSpans(entryEvents);
|
|
599
695
|
};
|
|
600
696
|
/**
|
|
@@ -620,8 +716,7 @@ var SentryReplay = /** @class */ (function () {
|
|
|
620
716
|
this.triggerFullSnapshot();
|
|
621
717
|
return false;
|
|
622
718
|
};
|
|
623
|
-
SentryReplay.prototype.
|
|
624
|
-
var _a;
|
|
719
|
+
SentryReplay.prototype.flushUpdate = function () {
|
|
625
720
|
if (!this.checkAndHandleExpiredSession()) {
|
|
626
721
|
logger.error(new Error('Attempting to finish replay event after session expired.'));
|
|
627
722
|
}
|
|
@@ -629,15 +724,19 @@ var SentryReplay = /** @class */ (function () {
|
|
|
629
724
|
console.error(new Error('[Sentry]: No transaction, no replay'));
|
|
630
725
|
return;
|
|
631
726
|
}
|
|
727
|
+
// TEMP: keep sending a replay event just for the duration
|
|
728
|
+
captureEvent({
|
|
729
|
+
message: "".concat(REPLAY_EVENT_NAME, "-").concat(uuid4().substring(16)),
|
|
730
|
+
tags: {
|
|
731
|
+
replayId: this.session.id,
|
|
732
|
+
sequenceId: this.session.sequenceId++,
|
|
733
|
+
},
|
|
734
|
+
});
|
|
735
|
+
this.addPerformanceEntries();
|
|
632
736
|
this.sendReplay(this.session.id);
|
|
633
737
|
this.initialEventTimestampSinceFlush = null;
|
|
634
738
|
// TBD: Alternatively we could update this after every rrweb event
|
|
635
739
|
this.session.lastActivity = new Date().getTime();
|
|
636
|
-
// include performance entries
|
|
637
|
-
this.addPerformanceEntries();
|
|
638
|
-
// Close out existing replay event and create a new one
|
|
639
|
-
(_a = this.replayEvent) === null || _a === void 0 ? void 0 : _a.setStatus('ok').finish();
|
|
640
|
-
this.createReplayEvent();
|
|
641
740
|
};
|
|
642
741
|
/**
|
|
643
742
|
* Determine if there is browser support for `navigator.sendBeacon`
|
|
@@ -648,13 +747,18 @@ var SentryReplay = /** @class */ (function () {
|
|
|
648
747
|
/**
|
|
649
748
|
* Send replay attachment using either `sendBeacon()` or `fetch()`
|
|
650
749
|
*/
|
|
651
|
-
SentryReplay.prototype.sendReplayRequest = function (
|
|
750
|
+
SentryReplay.prototype.sendReplayRequest = function (_a) {
|
|
751
|
+
var endpoint = _a.endpoint, events = _a.events, replaySpans = _a.replaySpans, breadcrumbs = _a.breadcrumbs;
|
|
652
752
|
return __awaiter(this, void 0, void 0, function () {
|
|
653
753
|
var stringifiedPayload, formData;
|
|
654
|
-
return __generator(this, function (
|
|
655
|
-
switch (
|
|
754
|
+
return __generator(this, function (_b) {
|
|
755
|
+
switch (_b.label) {
|
|
656
756
|
case 0:
|
|
657
|
-
stringifiedPayload = JSON.stringify({
|
|
757
|
+
stringifiedPayload = JSON.stringify({
|
|
758
|
+
recording: events,
|
|
759
|
+
replaySpans: replaySpans,
|
|
760
|
+
breadcrumbs: breadcrumbs,
|
|
761
|
+
});
|
|
658
762
|
formData = new FormData();
|
|
659
763
|
formData.append('rrweb', new Blob([stringifiedPayload], {
|
|
660
764
|
type: 'application/json',
|
|
@@ -672,34 +776,52 @@ var SentryReplay = /** @class */ (function () {
|
|
|
672
776
|
body: formData,
|
|
673
777
|
})];
|
|
674
778
|
case 1:
|
|
675
|
-
|
|
779
|
+
_b.sent();
|
|
676
780
|
return [2 /*return*/];
|
|
677
781
|
}
|
|
678
782
|
});
|
|
679
783
|
});
|
|
680
784
|
};
|
|
785
|
+
SentryReplay.prototype.resetRetries = function () {
|
|
786
|
+
this.retryCount = 0;
|
|
787
|
+
this.retryInterval = BASE_RETRY_INTERVAL;
|
|
788
|
+
};
|
|
681
789
|
/**
|
|
682
790
|
* Finalize and send the current replay event to Sentry
|
|
683
791
|
*/
|
|
684
792
|
SentryReplay.prototype.sendReplay = function (eventId) {
|
|
685
793
|
return __awaiter(this, void 0, void 0, function () {
|
|
686
|
-
var events, client, endpoint, ex_1;
|
|
794
|
+
var events, replaySpans, breadcrumbs, client, endpoint, ex_1;
|
|
795
|
+
var _this = this;
|
|
687
796
|
return __generator(this, function (_a) {
|
|
688
797
|
switch (_a.label) {
|
|
689
798
|
case 0:
|
|
690
|
-
// short circuit if theres no events to
|
|
691
|
-
if (!this.events.length
|
|
799
|
+
// short circuit if theres no events to upload
|
|
800
|
+
if (!this.events.length &&
|
|
801
|
+
!this.replaySpans.length &&
|
|
802
|
+
!this.breadcrumbs.length) {
|
|
692
803
|
return [2 /*return*/];
|
|
804
|
+
}
|
|
693
805
|
events = this.events;
|
|
806
|
+
replaySpans = this.replaySpans;
|
|
807
|
+
breadcrumbs = this.breadcrumbs;
|
|
808
|
+
this.replaySpans = [];
|
|
809
|
+
this.breadcrumbs = [];
|
|
694
810
|
this.events = [];
|
|
695
811
|
client = Sentry.getCurrentHub().getClient();
|
|
696
812
|
endpoint = SentryReplay.attachmentUrlFromDsn(client.getDsn(), eventId);
|
|
697
813
|
_a.label = 1;
|
|
698
814
|
case 1:
|
|
699
815
|
_a.trys.push([1, 3, , 4]);
|
|
700
|
-
return [4 /*yield*/, this.sendReplayRequest(
|
|
816
|
+
return [4 /*yield*/, this.sendReplayRequest({
|
|
817
|
+
endpoint: endpoint,
|
|
818
|
+
events: events,
|
|
819
|
+
replaySpans: replaySpans,
|
|
820
|
+
breadcrumbs: breadcrumbs,
|
|
821
|
+
})];
|
|
701
822
|
case 2:
|
|
702
823
|
_a.sent();
|
|
824
|
+
this.resetRetries();
|
|
703
825
|
return [2 /*return*/, true];
|
|
704
826
|
case 3:
|
|
705
827
|
ex_1 = _a.sent();
|
|
@@ -707,6 +829,17 @@ var SentryReplay = /** @class */ (function () {
|
|
|
707
829
|
console.error(ex_1);
|
|
708
830
|
// If an error happened here, it's likely that uploading the attachment failed, we'll want to restore the events that failed to upload
|
|
709
831
|
this.events = __spreadArray(__spreadArray([], events, true), this.events, true);
|
|
832
|
+
this.replaySpans = __spreadArray(__spreadArray([], replaySpans, true), this.replaySpans, true);
|
|
833
|
+
this.breadcrumbs = __spreadArray(__spreadArray([], replaySpans, true), this.breadcrumbs, true);
|
|
834
|
+
if (this.retryCount >= MAX_RETRY_COUNT) {
|
|
835
|
+
this.resetRetries();
|
|
836
|
+
}
|
|
837
|
+
else {
|
|
838
|
+
this.retryCount = this.retryCount + 1;
|
|
839
|
+
// will retry in intervals of 5, 10, 15, 20, 25 seconds
|
|
840
|
+
this.retryInterval = this.retryCount * this.retryInterval;
|
|
841
|
+
setTimeout(function () { return _this.sendReplay(eventId); }, this.retryInterval);
|
|
842
|
+
}
|
|
710
843
|
return [2 /*return*/, false];
|
|
711
844
|
case 4: return [2 /*return*/];
|
|
712
845
|
}
|