@sentry/replay 7.43.0 → 7.44.0
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/cjs/index.js +708 -344
- package/cjs/index.js.map +1 -1
- package/esm/index.js +708 -344
- package/esm/index.js.map +1 -1
- package/package.json +7 -6
- package/types/coreHandlers/addNetworkBreadcrumb.d.ts +4 -0
- package/types/coreHandlers/addNetworkBreadcrumb.d.ts.map +1 -0
- package/types/coreHandlers/handleAfterSendEvent.d.ts +9 -0
- package/types/coreHandlers/handleAfterSendEvent.d.ts.map +1 -0
- package/types/coreHandlers/handleDom.d.ts.map +1 -1
- package/types/coreHandlers/handleFetch.d.ts +3 -19
- package/types/coreHandlers/handleFetch.d.ts.map +1 -1
- package/types/coreHandlers/handleGlobalEvent.d.ts +1 -1
- package/types/coreHandlers/handleGlobalEvent.d.ts.map +1 -1
- package/types/coreHandlers/handleNetworkBreadcrumbs.d.ts +24 -0
- package/types/coreHandlers/handleNetworkBreadcrumbs.d.ts.map +1 -0
- package/types/coreHandlers/handleXhr.d.ts +5 -21
- package/types/coreHandlers/handleXhr.d.ts.map +1 -1
- package/types/coreHandlers/util/getAttributesToRecord.d.ts +5 -0
- package/types/coreHandlers/util/getAttributesToRecord.d.ts.map +1 -0
- package/types/replay.d.ts.map +1 -1
- package/types/util/addGlobalListeners.d.ts.map +1 -1
- package/types/util/eventUtils.d.ts +8 -0
- package/types/util/eventUtils.d.ts.map +1 -0
- package/types/util/monkeyPatchRecordDroppedEvent.d.ts +0 -9
- package/types/util/monkeyPatchRecordDroppedEvent.d.ts.map +0 -1
package/esm/index.js
CHANGED
|
@@ -29,7 +29,7 @@ const ERROR_CHECKOUT_TIME = 60000;
|
|
|
29
29
|
const RETRY_BASE_INTERVAL = 5000;
|
|
30
30
|
const RETRY_MAX_COUNT = 3;
|
|
31
31
|
|
|
32
|
-
var NodeType;
|
|
32
|
+
var NodeType$1;
|
|
33
33
|
(function (NodeType) {
|
|
34
34
|
NodeType[NodeType["Document"] = 0] = "Document";
|
|
35
35
|
NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
|
|
@@ -37,7 +37,7 @@ var NodeType;
|
|
|
37
37
|
NodeType[NodeType["Text"] = 3] = "Text";
|
|
38
38
|
NodeType[NodeType["CDATA"] = 4] = "CDATA";
|
|
39
39
|
NodeType[NodeType["Comment"] = 5] = "Comment";
|
|
40
|
-
})(NodeType || (NodeType = {}));
|
|
40
|
+
})(NodeType$1 || (NodeType$1 = {}));
|
|
41
41
|
|
|
42
42
|
function isElement(n) {
|
|
43
43
|
return n.nodeType === n.ELEMENT_NODE;
|
|
@@ -47,8 +47,13 @@ function isShadowRoot(n) {
|
|
|
47
47
|
return Boolean(host && host.shadowRoot && host.shadowRoot === n);
|
|
48
48
|
}
|
|
49
49
|
function isInputTypeMasked({ maskInputOptions, tagName, type, }) {
|
|
50
|
+
if (tagName.toLowerCase() === 'option') {
|
|
51
|
+
tagName = 'select';
|
|
52
|
+
}
|
|
53
|
+
const actualType = typeof type === 'string' ? type.toLowerCase() : undefined;
|
|
50
54
|
return (maskInputOptions[tagName.toLowerCase()] ||
|
|
51
|
-
maskInputOptions[
|
|
55
|
+
(actualType && maskInputOptions[actualType]) ||
|
|
56
|
+
actualType === 'password' ||
|
|
52
57
|
(tagName === 'input' && !type && maskInputOptions['text']));
|
|
53
58
|
}
|
|
54
59
|
function hasInputMaskOptions({ tagName, type, maskInputOptions, maskInputSelector, }) {
|
|
@@ -59,6 +64,9 @@ function maskInputValue({ input, maskInputSelector, unmaskInputSelector, maskInp
|
|
|
59
64
|
if (unmaskInputSelector && input.matches(unmaskInputSelector)) {
|
|
60
65
|
return text;
|
|
61
66
|
}
|
|
67
|
+
if (input.hasAttribute('rr_is_password')) {
|
|
68
|
+
type = 'password';
|
|
69
|
+
}
|
|
62
70
|
if (isInputTypeMasked({ maskInputOptions, tagName, type }) ||
|
|
63
71
|
(maskInputSelector && input.matches(maskInputSelector))) {
|
|
64
72
|
if (maskInputFn) {
|
|
@@ -264,10 +272,12 @@ function getHref() {
|
|
|
264
272
|
a.href = '';
|
|
265
273
|
return a.href;
|
|
266
274
|
}
|
|
267
|
-
function transformAttribute(doc, element,
|
|
275
|
+
function transformAttribute(doc, element, _tagName, _name, value, maskAllText, unmaskTextSelector, maskTextFn) {
|
|
268
276
|
if (!value) {
|
|
269
277
|
return value;
|
|
270
278
|
}
|
|
279
|
+
const name = _name.toLowerCase();
|
|
280
|
+
const tagName = _tagName.toLowerCase();
|
|
271
281
|
if (name === 'src' || name === 'href') {
|
|
272
282
|
return absoluteToDoc(doc, value);
|
|
273
283
|
}
|
|
@@ -288,15 +298,21 @@ function transformAttribute(doc, element, tagName, name, value, maskAllText, mas
|
|
|
288
298
|
return absoluteToDoc(doc, value);
|
|
289
299
|
}
|
|
290
300
|
else if (maskAllText &&
|
|
291
|
-
(
|
|
292
|
-
(tagName === 'input' &&
|
|
293
|
-
name === 'value' &&
|
|
294
|
-
element.getAttribute('type') &&
|
|
295
|
-
['submit', 'button'].indexOf(element.getAttribute('type').toLowerCase()) > -1))) {
|
|
301
|
+
_shouldMaskAttribute(element, name, tagName, unmaskTextSelector)) {
|
|
296
302
|
return maskTextFn ? maskTextFn(value) : defaultMaskFn(value);
|
|
297
303
|
}
|
|
298
304
|
return value;
|
|
299
305
|
}
|
|
306
|
+
function _shouldMaskAttribute(element, attribute, tagName, unmaskTextSelector) {
|
|
307
|
+
if (unmaskTextSelector && element.matches(unmaskTextSelector)) {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
return (['placeholder', 'title', 'aria-label'].indexOf(attribute) > -1 ||
|
|
311
|
+
(tagName === 'input' &&
|
|
312
|
+
attribute === 'value' &&
|
|
313
|
+
element.hasAttribute('type') &&
|
|
314
|
+
['submit', 'button'].indexOf(element.getAttribute('type').toLowerCase()) > -1));
|
|
315
|
+
}
|
|
300
316
|
function _isBlockedElement(element, blockClass, blockSelector, unblockSelector) {
|
|
301
317
|
if (unblockSelector && element.matches(unblockSelector)) {
|
|
302
318
|
return false;
|
|
@@ -403,7 +419,7 @@ function serializeNode(n, options) {
|
|
|
403
419
|
case n.DOCUMENT_NODE:
|
|
404
420
|
if (n.compatMode !== 'CSS1Compat') {
|
|
405
421
|
return {
|
|
406
|
-
type: NodeType.Document,
|
|
422
|
+
type: NodeType$1.Document,
|
|
407
423
|
childNodes: [],
|
|
408
424
|
compatMode: n.compatMode,
|
|
409
425
|
rootId,
|
|
@@ -411,14 +427,14 @@ function serializeNode(n, options) {
|
|
|
411
427
|
}
|
|
412
428
|
else {
|
|
413
429
|
return {
|
|
414
|
-
type: NodeType.Document,
|
|
430
|
+
type: NodeType$1.Document,
|
|
415
431
|
childNodes: [],
|
|
416
432
|
rootId,
|
|
417
433
|
};
|
|
418
434
|
}
|
|
419
435
|
case n.DOCUMENT_TYPE_NODE:
|
|
420
436
|
return {
|
|
421
|
-
type: NodeType.DocumentType,
|
|
437
|
+
type: NodeType$1.DocumentType,
|
|
422
438
|
name: n.name,
|
|
423
439
|
publicId: n.publicId,
|
|
424
440
|
systemId: n.systemId,
|
|
@@ -430,7 +446,7 @@ function serializeNode(n, options) {
|
|
|
430
446
|
let attributes = {};
|
|
431
447
|
for (const { name, value } of Array.from(n.attributes)) {
|
|
432
448
|
if (!skipAttribute(tagName, name)) {
|
|
433
|
-
attributes[name] = transformAttribute(doc, n, tagName, name, value, maskAllText, maskTextFn);
|
|
449
|
+
attributes[name] = transformAttribute(doc, n, tagName, name, value, maskAllText, unmaskTextSelector, maskTextFn);
|
|
434
450
|
}
|
|
435
451
|
}
|
|
436
452
|
if (tagName === 'link' && inlineStylesheet) {
|
|
@@ -459,15 +475,16 @@ function serializeNode(n, options) {
|
|
|
459
475
|
}
|
|
460
476
|
if (tagName === 'input' ||
|
|
461
477
|
tagName === 'textarea' ||
|
|
462
|
-
tagName === 'select'
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
478
|
+
tagName === 'select' ||
|
|
479
|
+
tagName === 'option') {
|
|
480
|
+
const el = n;
|
|
481
|
+
const value = getInputValue(tagName, el, attributes);
|
|
482
|
+
const checked = n.checked;
|
|
483
|
+
if (attributes.type !== 'submit' &&
|
|
467
484
|
attributes.type !== 'button' &&
|
|
468
485
|
value) {
|
|
469
486
|
attributes.value = maskInputValue({
|
|
470
|
-
input:
|
|
487
|
+
input: el,
|
|
471
488
|
type: attributes.type,
|
|
472
489
|
tagName,
|
|
473
490
|
value,
|
|
@@ -477,8 +494,8 @@ function serializeNode(n, options) {
|
|
|
477
494
|
maskInputFn,
|
|
478
495
|
});
|
|
479
496
|
}
|
|
480
|
-
|
|
481
|
-
attributes.checked =
|
|
497
|
+
if (checked) {
|
|
498
|
+
attributes.checked = checked;
|
|
482
499
|
}
|
|
483
500
|
}
|
|
484
501
|
if (tagName === 'option') {
|
|
@@ -560,7 +577,7 @@ function serializeNode(n, options) {
|
|
|
560
577
|
delete attributes.src;
|
|
561
578
|
}
|
|
562
579
|
return {
|
|
563
|
-
type: NodeType.Element,
|
|
580
|
+
type: NodeType$1.Element,
|
|
564
581
|
tagName,
|
|
565
582
|
attributes,
|
|
566
583
|
childNodes: [],
|
|
@@ -592,6 +609,19 @@ function serializeNode(n, options) {
|
|
|
592
609
|
if (parentTagName === 'TEXTAREA' && textContent) {
|
|
593
610
|
textContent = '';
|
|
594
611
|
}
|
|
612
|
+
else if (parentTagName === 'OPTION' && textContent) {
|
|
613
|
+
const option = n.parentNode;
|
|
614
|
+
textContent = maskInputValue({
|
|
615
|
+
input: option,
|
|
616
|
+
type: null,
|
|
617
|
+
tagName: parentTagName,
|
|
618
|
+
value: textContent,
|
|
619
|
+
maskInputSelector,
|
|
620
|
+
unmaskInputSelector,
|
|
621
|
+
maskInputOptions,
|
|
622
|
+
maskInputFn,
|
|
623
|
+
});
|
|
624
|
+
}
|
|
595
625
|
else if (!isStyle &&
|
|
596
626
|
!isScript &&
|
|
597
627
|
needMaskingText(n, maskTextClass, maskTextSelector, unmaskTextSelector, maskAllText) &&
|
|
@@ -601,20 +631,20 @@ function serializeNode(n, options) {
|
|
|
601
631
|
: defaultMaskFn(textContent);
|
|
602
632
|
}
|
|
603
633
|
return {
|
|
604
|
-
type: NodeType.Text,
|
|
634
|
+
type: NodeType$1.Text,
|
|
605
635
|
textContent: textContent || '',
|
|
606
636
|
isStyle,
|
|
607
637
|
rootId,
|
|
608
638
|
};
|
|
609
639
|
case n.CDATA_SECTION_NODE:
|
|
610
640
|
return {
|
|
611
|
-
type: NodeType.CDATA,
|
|
641
|
+
type: NodeType$1.CDATA,
|
|
612
642
|
textContent: '',
|
|
613
643
|
rootId,
|
|
614
644
|
};
|
|
615
645
|
case n.COMMENT_NODE:
|
|
616
646
|
return {
|
|
617
|
-
type: NodeType.Comment,
|
|
647
|
+
type: NodeType$1.Comment,
|
|
618
648
|
textContent: n.textContent || '',
|
|
619
649
|
rootId,
|
|
620
650
|
};
|
|
@@ -631,10 +661,10 @@ function lowerIfExists(maybeAttr) {
|
|
|
631
661
|
}
|
|
632
662
|
}
|
|
633
663
|
function slimDOMExcluded(sn, slimDOMOptions) {
|
|
634
|
-
if (slimDOMOptions.comment && sn.type === NodeType.Comment) {
|
|
664
|
+
if (slimDOMOptions.comment && sn.type === NodeType$1.Comment) {
|
|
635
665
|
return true;
|
|
636
666
|
}
|
|
637
|
-
else if (sn.type === NodeType.Element) {
|
|
667
|
+
else if (sn.type === NodeType$1.Element) {
|
|
638
668
|
if (slimDOMOptions.script &&
|
|
639
669
|
(sn.tagName === 'script' ||
|
|
640
670
|
(sn.tagName === 'link' &&
|
|
@@ -735,7 +765,7 @@ function serializeNodeWithId(n, options) {
|
|
|
735
765
|
}
|
|
736
766
|
else if (slimDOMExcluded(_serializedNode, slimDOMOptions) ||
|
|
737
767
|
(!preserveWhiteSpace &&
|
|
738
|
-
_serializedNode.type === NodeType.Text &&
|
|
768
|
+
_serializedNode.type === NodeType$1.Text &&
|
|
739
769
|
!_serializedNode.isStyle &&
|
|
740
770
|
!_serializedNode.textContent.replace(/^\s+|\s+$/gm, '').length)) {
|
|
741
771
|
id = IGNORED_NODE;
|
|
@@ -753,17 +783,17 @@ function serializeNodeWithId(n, options) {
|
|
|
753
783
|
onSerialize(n);
|
|
754
784
|
}
|
|
755
785
|
let recordChild = !skipChild;
|
|
756
|
-
if (serializedNode.type === NodeType.Element) {
|
|
786
|
+
if (serializedNode.type === NodeType$1.Element) {
|
|
757
787
|
recordChild = recordChild && !serializedNode.needBlock;
|
|
758
788
|
delete serializedNode.needBlock;
|
|
759
789
|
if (n.shadowRoot)
|
|
760
790
|
serializedNode.isShadowHost = true;
|
|
761
791
|
}
|
|
762
|
-
if ((serializedNode.type === NodeType.Document ||
|
|
763
|
-
serializedNode.type === NodeType.Element) &&
|
|
792
|
+
if ((serializedNode.type === NodeType$1.Document ||
|
|
793
|
+
serializedNode.type === NodeType$1.Element) &&
|
|
764
794
|
recordChild) {
|
|
765
795
|
if (slimDOMOptions.headWhitespace &&
|
|
766
|
-
_serializedNode.type === NodeType.Element &&
|
|
796
|
+
_serializedNode.type === NodeType$1.Element &&
|
|
767
797
|
_serializedNode.tagName === 'head') {
|
|
768
798
|
preserveWhiteSpace = false;
|
|
769
799
|
}
|
|
@@ -813,7 +843,7 @@ function serializeNodeWithId(n, options) {
|
|
|
813
843
|
if (n.parentNode && isShadowRoot(n.parentNode)) {
|
|
814
844
|
serializedNode.isShadow = true;
|
|
815
845
|
}
|
|
816
|
-
if (serializedNode.type === NodeType.Element &&
|
|
846
|
+
if (serializedNode.type === NodeType$1.Element &&
|
|
817
847
|
serializedNode.tagName === 'iframe') {
|
|
818
848
|
onceIframeLoaded(n, () => {
|
|
819
849
|
const iframeDoc = n.contentDocument;
|
|
@@ -873,12 +903,9 @@ function snapshot(n, options) {
|
|
|
873
903
|
week: true,
|
|
874
904
|
textarea: true,
|
|
875
905
|
select: true,
|
|
876
|
-
password: true,
|
|
877
906
|
}
|
|
878
907
|
: maskAllInputs === false
|
|
879
|
-
? {
|
|
880
|
-
password: true,
|
|
881
|
-
}
|
|
908
|
+
? {}
|
|
882
909
|
: maskAllInputs;
|
|
883
910
|
const slimDOMOptions = slimDOM === true || slimDOM === 'all'
|
|
884
911
|
?
|
|
@@ -931,6 +958,13 @@ function snapshot(n, options) {
|
|
|
931
958
|
function skipAttribute(tagName, attributeName, value) {
|
|
932
959
|
return ((tagName === 'video' || tagName === 'audio') && attributeName === 'autoplay');
|
|
933
960
|
}
|
|
961
|
+
function getInputValue(tagName, el, attributes) {
|
|
962
|
+
if (tagName === 'input' &&
|
|
963
|
+
(attributes.type === 'radio' || attributes.type === 'checkbox')) {
|
|
964
|
+
return el.getAttribute('value') || '';
|
|
965
|
+
}
|
|
966
|
+
return el.value;
|
|
967
|
+
}
|
|
934
968
|
|
|
935
969
|
var EventType;
|
|
936
970
|
(function (EventType) {
|
|
@@ -1241,7 +1275,7 @@ function polyfill(win = window) {
|
|
|
1241
1275
|
}
|
|
1242
1276
|
function isIframeINode(node) {
|
|
1243
1277
|
if ('__sn' in node) {
|
|
1244
|
-
return (node.__sn.type === NodeType.Element && node.__sn.tagName === 'iframe');
|
|
1278
|
+
return (node.__sn.type === NodeType$1.Element && node.__sn.tagName === 'iframe');
|
|
1245
1279
|
}
|
|
1246
1280
|
return false;
|
|
1247
1281
|
}
|
|
@@ -1531,15 +1565,15 @@ class MutationBuffer {
|
|
|
1531
1565
|
}
|
|
1532
1566
|
case 'attributes': {
|
|
1533
1567
|
const target = m.target;
|
|
1534
|
-
let value =
|
|
1568
|
+
let value = target.getAttribute(m.attributeName);
|
|
1535
1569
|
if (m.attributeName === 'value') {
|
|
1536
1570
|
value = maskInputValue({
|
|
1537
1571
|
input: target,
|
|
1538
1572
|
maskInputSelector: this.maskInputSelector,
|
|
1539
1573
|
unmaskInputSelector: this.unmaskInputSelector,
|
|
1540
1574
|
maskInputOptions: this.maskInputOptions,
|
|
1541
|
-
tagName:
|
|
1542
|
-
type:
|
|
1575
|
+
tagName: target.tagName,
|
|
1576
|
+
type: target.getAttribute('type'),
|
|
1543
1577
|
value,
|
|
1544
1578
|
maskInputFn: this.maskInputFn,
|
|
1545
1579
|
});
|
|
@@ -1555,6 +1589,11 @@ class MutationBuffer {
|
|
|
1555
1589
|
};
|
|
1556
1590
|
this.attributes.push(item);
|
|
1557
1591
|
}
|
|
1592
|
+
if (m.attributeName === 'type' &&
|
|
1593
|
+
m.target.tagName === 'INPUT' &&
|
|
1594
|
+
(m.oldValue || '').toLowerCase() === 'password') {
|
|
1595
|
+
m.target.setAttribute('rr_is_password', 'true');
|
|
1596
|
+
}
|
|
1558
1597
|
if (m.attributeName === 'style') {
|
|
1559
1598
|
const old = this.doc.createElement('span');
|
|
1560
1599
|
if (m.oldValue) {
|
|
@@ -1591,7 +1630,7 @@ class MutationBuffer {
|
|
|
1591
1630
|
}
|
|
1592
1631
|
else {
|
|
1593
1632
|
const element = m.target;
|
|
1594
|
-
item.attributes[m.attributeName] = transformAttribute(this.doc, element, element.tagName, m.attributeName, value, this.maskAllText, this.maskTextFn);
|
|
1633
|
+
item.attributes[m.attributeName] = transformAttribute(this.doc, element, element.tagName, m.attributeName, value, this.maskAllText, this.unmaskTextSelector, this.maskTextFn);
|
|
1595
1634
|
}
|
|
1596
1635
|
break;
|
|
1597
1636
|
}
|
|
@@ -1889,7 +1928,8 @@ function initMouseInteractionObserver({ mouseInteractionCb, doc, mirror, blockCl
|
|
|
1889
1928
|
function initScrollObserver({ scrollCb, doc, mirror, blockClass, blockSelector, unblockSelector, sampling, }) {
|
|
1890
1929
|
const updatePosition = throttle((evt) => {
|
|
1891
1930
|
const target = getEventTarget(evt);
|
|
1892
|
-
if (!target ||
|
|
1931
|
+
if (!target ||
|
|
1932
|
+
isBlocked(target, blockClass, blockSelector, unblockSelector)) {
|
|
1893
1933
|
return;
|
|
1894
1934
|
}
|
|
1895
1935
|
const id = mirror.getId(target);
|
|
@@ -1939,29 +1979,33 @@ const lastInputValueMap = new WeakMap();
|
|
|
1939
1979
|
function initInputObserver({ inputCb, doc, mirror, blockClass, blockSelector, unblockSelector, ignoreClass, ignoreSelector, maskInputSelector, unmaskInputSelector, maskInputOptions, maskInputFn, sampling, userTriggeredOnInput, }) {
|
|
1940
1980
|
function eventHandler(event) {
|
|
1941
1981
|
let target = getEventTarget(event);
|
|
1982
|
+
const tagName = target && target.tagName;
|
|
1942
1983
|
const userTriggered = event.isTrusted;
|
|
1943
|
-
if (
|
|
1984
|
+
if (tagName === 'OPTION')
|
|
1944
1985
|
target = target.parentElement;
|
|
1945
1986
|
if (!target ||
|
|
1946
|
-
!
|
|
1947
|
-
INPUT_TAGS.indexOf(
|
|
1987
|
+
!tagName ||
|
|
1988
|
+
INPUT_TAGS.indexOf(tagName) < 0 ||
|
|
1948
1989
|
isBlocked(target, blockClass, blockSelector, unblockSelector)) {
|
|
1949
1990
|
return;
|
|
1950
1991
|
}
|
|
1951
|
-
|
|
1992
|
+
let type = target.type;
|
|
1952
1993
|
if (target.classList.contains(ignoreClass) ||
|
|
1953
1994
|
(ignoreSelector && target.matches(ignoreSelector))) {
|
|
1954
1995
|
return;
|
|
1955
1996
|
}
|
|
1956
1997
|
let text = target.value;
|
|
1957
1998
|
let isChecked = false;
|
|
1999
|
+
if (target.hasAttribute('rr_is_password')) {
|
|
2000
|
+
type = 'password';
|
|
2001
|
+
}
|
|
1958
2002
|
if (type === 'radio' || type === 'checkbox') {
|
|
1959
2003
|
isChecked = target.checked;
|
|
1960
2004
|
}
|
|
1961
2005
|
else if (hasInputMaskOptions({
|
|
1962
2006
|
maskInputOptions,
|
|
1963
2007
|
maskInputSelector,
|
|
1964
|
-
tagName
|
|
2008
|
+
tagName,
|
|
1965
2009
|
type,
|
|
1966
2010
|
})) {
|
|
1967
2011
|
text = maskInputValue({
|
|
@@ -1969,7 +2013,7 @@ function initInputObserver({ inputCb, doc, mirror, blockClass, blockSelector, un
|
|
|
1969
2013
|
maskInputOptions,
|
|
1970
2014
|
maskInputSelector,
|
|
1971
2015
|
unmaskInputSelector,
|
|
1972
|
-
tagName
|
|
2016
|
+
tagName,
|
|
1973
2017
|
type,
|
|
1974
2018
|
value: text,
|
|
1975
2019
|
maskInputFn,
|
|
@@ -2193,7 +2237,8 @@ function initStyleDeclarationObserver({ styleDeclarationCb, mirror }, { win }) {
|
|
|
2193
2237
|
function initMediaInteractionObserver({ mediaInteractionCb, blockClass, blockSelector, unblockSelector, mirror, sampling, }) {
|
|
2194
2238
|
const handler = (type) => throttle(callbackWrapper((event) => {
|
|
2195
2239
|
const target = getEventTarget(event);
|
|
2196
|
-
if (!target ||
|
|
2240
|
+
if (!target ||
|
|
2241
|
+
isBlocked(target, blockClass, blockSelector, unblockSelector)) {
|
|
2197
2242
|
return;
|
|
2198
2243
|
}
|
|
2199
2244
|
const { currentTime, volume, muted } = target;
|
|
@@ -2856,11 +2901,12 @@ function record(options = {}) {
|
|
|
2856
2901
|
week: true,
|
|
2857
2902
|
textarea: true,
|
|
2858
2903
|
select: true,
|
|
2859
|
-
|
|
2904
|
+
radio: true,
|
|
2905
|
+
checkbox: true,
|
|
2860
2906
|
}
|
|
2861
2907
|
: _maskInputOptions !== undefined
|
|
2862
2908
|
? _maskInputOptions
|
|
2863
|
-
: {
|
|
2909
|
+
: {};
|
|
2864
2910
|
const slimDOMOptions = _slimDOMOptions === true || _slimDOMOptions === 'all'
|
|
2865
2911
|
? {
|
|
2866
2912
|
script: true,
|
|
@@ -3717,7 +3763,7 @@ function isSampled(sampleRate) {
|
|
|
3717
3763
|
* Get a session with defaults & applied sampling.
|
|
3718
3764
|
*/
|
|
3719
3765
|
function makeSession(session) {
|
|
3720
|
-
const now =
|
|
3766
|
+
const now = Date.now();
|
|
3721
3767
|
const id = session.id || uuid4();
|
|
3722
3768
|
// Note that this means we cannot set a started/lastActivity of `0`, but this should not be relevant outside of tests.
|
|
3723
3769
|
const started = session.started || now;
|
|
@@ -3855,7 +3901,7 @@ async function addEvent(
|
|
|
3855
3901
|
// page has been left open and idle for a long period of time and user
|
|
3856
3902
|
// comes back to trigger a new session. The performance entries rely on
|
|
3857
3903
|
// `performance.timeOrigin`, which is when the page first opened.
|
|
3858
|
-
if (timestampInMs + replay.timeouts.sessionIdle <
|
|
3904
|
+
if (timestampInMs + replay.timeouts.sessionIdle < Date.now()) {
|
|
3859
3905
|
return null;
|
|
3860
3906
|
}
|
|
3861
3907
|
|
|
@@ -3880,6 +3926,111 @@ async function addEvent(
|
|
|
3880
3926
|
}
|
|
3881
3927
|
}
|
|
3882
3928
|
|
|
3929
|
+
/** If the event is an error event */
|
|
3930
|
+
function isErrorEvent(event) {
|
|
3931
|
+
return !event.type;
|
|
3932
|
+
}
|
|
3933
|
+
|
|
3934
|
+
/** If the event is a transaction event */
|
|
3935
|
+
function isTransactionEvent(event) {
|
|
3936
|
+
return event.type === 'transaction';
|
|
3937
|
+
}
|
|
3938
|
+
|
|
3939
|
+
/** If the event is an replay event */
|
|
3940
|
+
function isReplayEvent(event) {
|
|
3941
|
+
return event.type === 'replay_event';
|
|
3942
|
+
}
|
|
3943
|
+
|
|
3944
|
+
/**
|
|
3945
|
+
* Returns a listener to be added to `client.on('afterSendErrorEvent, listener)`.
|
|
3946
|
+
*/
|
|
3947
|
+
function handleAfterSendEvent(replay) {
|
|
3948
|
+
// Custom transports may still be returning `Promise<void>`, which means we cannot expect the status code to be available there
|
|
3949
|
+
// TODO (v8): remove this check as it will no longer be necessary
|
|
3950
|
+
const enforceStatusCode = isBaseTransportSend();
|
|
3951
|
+
|
|
3952
|
+
return (event, sendResponse) => {
|
|
3953
|
+
if (!isErrorEvent(event) && !isTransactionEvent(event)) {
|
|
3954
|
+
return;
|
|
3955
|
+
}
|
|
3956
|
+
|
|
3957
|
+
const statusCode = sendResponse && sendResponse.statusCode;
|
|
3958
|
+
|
|
3959
|
+
// We only want to do stuff on successful error sending, otherwise you get error replays without errors attached
|
|
3960
|
+
// If not using the base transport, we allow `undefined` response (as a custom transport may not implement this correctly yet)
|
|
3961
|
+
// If we do use the base transport, we skip if we encountered an non-OK status code
|
|
3962
|
+
if (enforceStatusCode && (!statusCode || statusCode < 200 || statusCode >= 300)) {
|
|
3963
|
+
return;
|
|
3964
|
+
}
|
|
3965
|
+
|
|
3966
|
+
// Collect traceIds in _context regardless of `recordingMode`
|
|
3967
|
+
// In error mode, _context gets cleared on every checkout
|
|
3968
|
+
if (isTransactionEvent(event) && event.contexts && event.contexts.trace && event.contexts.trace.trace_id) {
|
|
3969
|
+
replay.getContext().traceIds.add(event.contexts.trace.trace_id );
|
|
3970
|
+
return;
|
|
3971
|
+
}
|
|
3972
|
+
|
|
3973
|
+
// Everything below is just for error events
|
|
3974
|
+
if (!isErrorEvent(event)) {
|
|
3975
|
+
return;
|
|
3976
|
+
}
|
|
3977
|
+
|
|
3978
|
+
// Add error to list of errorIds of replay
|
|
3979
|
+
if (event.event_id) {
|
|
3980
|
+
replay.getContext().errorIds.add(event.event_id);
|
|
3981
|
+
}
|
|
3982
|
+
|
|
3983
|
+
// Trigger error recording
|
|
3984
|
+
// Need to be very careful that this does not cause an infinite loop
|
|
3985
|
+
if (
|
|
3986
|
+
replay.recordingMode === 'error' &&
|
|
3987
|
+
event.exception &&
|
|
3988
|
+
event.message !== UNABLE_TO_SEND_REPLAY // ignore this error because otherwise we could loop indefinitely with trying to capture replay and failing
|
|
3989
|
+
) {
|
|
3990
|
+
setTimeout(async () => {
|
|
3991
|
+
// Allow flush to complete before resuming as a session recording, otherwise
|
|
3992
|
+
// the checkout from `startRecording` may be included in the payload.
|
|
3993
|
+
// Prefer to keep the error replay as a separate (and smaller) segment
|
|
3994
|
+
// than the session replay.
|
|
3995
|
+
await replay.flushImmediate();
|
|
3996
|
+
|
|
3997
|
+
if (replay.stopRecording()) {
|
|
3998
|
+
// Reset all "capture on error" configuration before
|
|
3999
|
+
// starting a new recording
|
|
4000
|
+
replay.recordingMode = 'session';
|
|
4001
|
+
replay.startRecording();
|
|
4002
|
+
}
|
|
4003
|
+
});
|
|
4004
|
+
}
|
|
4005
|
+
};
|
|
4006
|
+
}
|
|
4007
|
+
|
|
4008
|
+
function isBaseTransportSend() {
|
|
4009
|
+
const client = getCurrentHub().getClient();
|
|
4010
|
+
if (!client) {
|
|
4011
|
+
return false;
|
|
4012
|
+
}
|
|
4013
|
+
|
|
4014
|
+
const transport = client.getTransport();
|
|
4015
|
+
if (!transport) {
|
|
4016
|
+
return false;
|
|
4017
|
+
}
|
|
4018
|
+
|
|
4019
|
+
return (
|
|
4020
|
+
(transport.send ).__sentry__baseTransport__ || false
|
|
4021
|
+
);
|
|
4022
|
+
}
|
|
4023
|
+
|
|
4024
|
+
var NodeType;
|
|
4025
|
+
(function (NodeType) {
|
|
4026
|
+
NodeType[NodeType["Document"] = 0] = "Document";
|
|
4027
|
+
NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
|
|
4028
|
+
NodeType[NodeType["Element"] = 2] = "Element";
|
|
4029
|
+
NodeType[NodeType["Text"] = 3] = "Text";
|
|
4030
|
+
NodeType[NodeType["CDATA"] = 4] = "CDATA";
|
|
4031
|
+
NodeType[NodeType["Comment"] = 5] = "Comment";
|
|
4032
|
+
})(NodeType || (NodeType = {}));
|
|
4033
|
+
|
|
3883
4034
|
/**
|
|
3884
4035
|
* Create a breadcrumb for a replay.
|
|
3885
4036
|
*/
|
|
@@ -3887,7 +4038,7 @@ function createBreadcrumb(
|
|
|
3887
4038
|
breadcrumb,
|
|
3888
4039
|
) {
|
|
3889
4040
|
return {
|
|
3890
|
-
timestamp:
|
|
4041
|
+
timestamp: Date.now() / 1000,
|
|
3891
4042
|
type: 'default',
|
|
3892
4043
|
...breadcrumb,
|
|
3893
4044
|
};
|
|
@@ -3924,6 +4075,40 @@ function addBreadcrumbEvent(replay, breadcrumb) {
|
|
|
3924
4075
|
});
|
|
3925
4076
|
}
|
|
3926
4077
|
|
|
4078
|
+
// Note that these are the serialized attributes and not attributes directly on
|
|
4079
|
+
// the DOM Node. Attributes we are interested in:
|
|
4080
|
+
const ATTRIBUTES_TO_RECORD = new Set([
|
|
4081
|
+
'id',
|
|
4082
|
+
'class',
|
|
4083
|
+
'aria-label',
|
|
4084
|
+
'role',
|
|
4085
|
+
'name',
|
|
4086
|
+
'alt',
|
|
4087
|
+
'title',
|
|
4088
|
+
'data-test-id',
|
|
4089
|
+
'data-testid',
|
|
4090
|
+
]);
|
|
4091
|
+
|
|
4092
|
+
/**
|
|
4093
|
+
* Inclusion list of attributes that we want to record from the DOM element
|
|
4094
|
+
*/
|
|
4095
|
+
function getAttributesToRecord(attributes) {
|
|
4096
|
+
const obj = {};
|
|
4097
|
+
for (const key in attributes) {
|
|
4098
|
+
if (ATTRIBUTES_TO_RECORD.has(key)) {
|
|
4099
|
+
let normalizedKey = key;
|
|
4100
|
+
|
|
4101
|
+
if (key === 'data-testid' || key === 'data-test-id') {
|
|
4102
|
+
normalizedKey = 'testId';
|
|
4103
|
+
}
|
|
4104
|
+
|
|
4105
|
+
obj[normalizedKey] = attributes[key];
|
|
4106
|
+
}
|
|
4107
|
+
}
|
|
4108
|
+
|
|
4109
|
+
return obj;
|
|
4110
|
+
}
|
|
4111
|
+
|
|
3927
4112
|
const handleDomListener =
|
|
3928
4113
|
(replay) =>
|
|
3929
4114
|
(handlerData) => {
|
|
@@ -3944,7 +4129,6 @@ const handleDomListener =
|
|
|
3944
4129
|
* An event handler to react to DOM events.
|
|
3945
4130
|
*/
|
|
3946
4131
|
function handleDom(handlerData) {
|
|
3947
|
-
// Taken from https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/integrations/breadcrumbs.ts#L112
|
|
3948
4132
|
let target;
|
|
3949
4133
|
let targetNode;
|
|
3950
4134
|
|
|
@@ -3956,18 +4140,32 @@ function handleDom(handlerData) {
|
|
|
3956
4140
|
target = '<unknown>';
|
|
3957
4141
|
}
|
|
3958
4142
|
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
4143
|
+
// `__sn` property is the serialized node created by rrweb
|
|
4144
|
+
const serializedNode =
|
|
4145
|
+
targetNode && '__sn' in targetNode && targetNode.__sn.type === NodeType.Element ? targetNode.__sn : null;
|
|
3962
4146
|
|
|
3963
4147
|
return createBreadcrumb({
|
|
3964
4148
|
category: `ui.${handlerData.name}`,
|
|
3965
4149
|
message: target,
|
|
3966
|
-
data:
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
4150
|
+
data: serializedNode
|
|
4151
|
+
? {
|
|
4152
|
+
nodeId: serializedNode.id,
|
|
4153
|
+
node: {
|
|
4154
|
+
id: serializedNode.id,
|
|
4155
|
+
tagName: serializedNode.tagName,
|
|
4156
|
+
textContent: targetNode
|
|
4157
|
+
? Array.from(targetNode.childNodes)
|
|
4158
|
+
.map(
|
|
4159
|
+
(node) => '__sn' in node && node.__sn.type === NodeType.Text && node.__sn.textContent,
|
|
4160
|
+
)
|
|
4161
|
+
.filter(Boolean) // filter out empty values
|
|
4162
|
+
.map(text => (text ).trim())
|
|
4163
|
+
.join('')
|
|
4164
|
+
: '',
|
|
4165
|
+
attributes: getAttributesToRecord(serializedNode.attributes),
|
|
4166
|
+
},
|
|
4167
|
+
}
|
|
4168
|
+
: {},
|
|
3971
4169
|
});
|
|
3972
4170
|
}
|
|
3973
4171
|
|
|
@@ -3983,102 +4181,6 @@ function isEventWithTarget(event) {
|
|
|
3983
4181
|
return !!(event ).target;
|
|
3984
4182
|
}
|
|
3985
4183
|
|
|
3986
|
-
/**
|
|
3987
|
-
* Create a "span" for each performance entry. The parent transaction is `this.replayEvent`.
|
|
3988
|
-
*/
|
|
3989
|
-
function createPerformanceSpans(
|
|
3990
|
-
replay,
|
|
3991
|
-
entries,
|
|
3992
|
-
) {
|
|
3993
|
-
return entries.map(({ type, start, end, name, data }) =>
|
|
3994
|
-
addEvent(replay, {
|
|
3995
|
-
type: EventType.Custom,
|
|
3996
|
-
timestamp: start,
|
|
3997
|
-
data: {
|
|
3998
|
-
tag: 'performanceSpan',
|
|
3999
|
-
payload: {
|
|
4000
|
-
op: type,
|
|
4001
|
-
description: name,
|
|
4002
|
-
startTimestamp: start,
|
|
4003
|
-
endTimestamp: end,
|
|
4004
|
-
data,
|
|
4005
|
-
},
|
|
4006
|
-
},
|
|
4007
|
-
}),
|
|
4008
|
-
);
|
|
4009
|
-
}
|
|
4010
|
-
|
|
4011
|
-
/**
|
|
4012
|
-
* Check whether a given request URL should be filtered out. This is so we
|
|
4013
|
-
* don't log Sentry ingest requests.
|
|
4014
|
-
*/
|
|
4015
|
-
function shouldFilterRequest(replay, url) {
|
|
4016
|
-
// If we enabled the `traceInternals` experiment, we want to trace everything
|
|
4017
|
-
if ((typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && replay.getOptions()._experiments.traceInternals) {
|
|
4018
|
-
return false;
|
|
4019
|
-
}
|
|
4020
|
-
|
|
4021
|
-
return _isSentryRequest(url);
|
|
4022
|
-
}
|
|
4023
|
-
|
|
4024
|
-
/**
|
|
4025
|
-
* Checks wether a given URL belongs to the configured Sentry DSN.
|
|
4026
|
-
*/
|
|
4027
|
-
function _isSentryRequest(url) {
|
|
4028
|
-
const client = getCurrentHub().getClient();
|
|
4029
|
-
const dsn = client && client.getDsn();
|
|
4030
|
-
return dsn ? url.includes(dsn.host) : false;
|
|
4031
|
-
}
|
|
4032
|
-
|
|
4033
|
-
/** only exported for tests */
|
|
4034
|
-
function handleFetch(handlerData) {
|
|
4035
|
-
if (!handlerData.endTimestamp) {
|
|
4036
|
-
return null;
|
|
4037
|
-
}
|
|
4038
|
-
|
|
4039
|
-
const { startTimestamp, endTimestamp, fetchData, response } = handlerData;
|
|
4040
|
-
|
|
4041
|
-
return {
|
|
4042
|
-
type: 'resource.fetch',
|
|
4043
|
-
start: startTimestamp / 1000,
|
|
4044
|
-
end: endTimestamp / 1000,
|
|
4045
|
-
name: fetchData.url,
|
|
4046
|
-
data: {
|
|
4047
|
-
method: fetchData.method,
|
|
4048
|
-
statusCode: response.status,
|
|
4049
|
-
},
|
|
4050
|
-
};
|
|
4051
|
-
}
|
|
4052
|
-
|
|
4053
|
-
/**
|
|
4054
|
-
* Returns a listener to be added to `addInstrumentationHandler('fetch', listener)`.
|
|
4055
|
-
*/
|
|
4056
|
-
function handleFetchSpanListener(replay) {
|
|
4057
|
-
return (handlerData) => {
|
|
4058
|
-
if (!replay.isEnabled()) {
|
|
4059
|
-
return;
|
|
4060
|
-
}
|
|
4061
|
-
|
|
4062
|
-
const result = handleFetch(handlerData);
|
|
4063
|
-
|
|
4064
|
-
if (result === null) {
|
|
4065
|
-
return;
|
|
4066
|
-
}
|
|
4067
|
-
|
|
4068
|
-
if (shouldFilterRequest(replay, result.name)) {
|
|
4069
|
-
return;
|
|
4070
|
-
}
|
|
4071
|
-
|
|
4072
|
-
replay.addUpdate(() => {
|
|
4073
|
-
createPerformanceSpans(replay, [result]);
|
|
4074
|
-
// Returning true will cause `addUpdate` to not flush
|
|
4075
|
-
// We do not want network requests to cause a flush. This will prevent
|
|
4076
|
-
// recurring/polling requests from keeping the replay session alive.
|
|
4077
|
-
return true;
|
|
4078
|
-
});
|
|
4079
|
-
};
|
|
4080
|
-
}
|
|
4081
|
-
|
|
4082
4184
|
/**
|
|
4083
4185
|
* Returns true if we think the given event is an error originating inside of rrweb.
|
|
4084
4186
|
*/
|
|
@@ -4105,16 +4207,25 @@ function isRrwebError(event, hint) {
|
|
|
4105
4207
|
/**
|
|
4106
4208
|
* Returns a listener to be added to `addGlobalEventProcessor(listener)`.
|
|
4107
4209
|
*/
|
|
4108
|
-
function handleGlobalEventListener(
|
|
4210
|
+
function handleGlobalEventListener(
|
|
4211
|
+
replay,
|
|
4212
|
+
includeAfterSendEventHandling = false,
|
|
4213
|
+
) {
|
|
4214
|
+
const afterSendHandler = includeAfterSendEventHandling ? handleAfterSendEvent(replay) : undefined;
|
|
4215
|
+
|
|
4109
4216
|
return (event, hint) => {
|
|
4110
|
-
|
|
4111
|
-
if (event.type === REPLAY_EVENT_NAME) {
|
|
4217
|
+
if (isReplayEvent(event)) {
|
|
4112
4218
|
// Replays have separate set of breadcrumbs, do not include breadcrumbs
|
|
4113
4219
|
// from core SDK
|
|
4114
4220
|
delete event.breadcrumbs;
|
|
4115
4221
|
return event;
|
|
4116
4222
|
}
|
|
4117
4223
|
|
|
4224
|
+
// We only want to handle errors & transactions, nothing else
|
|
4225
|
+
if (!isErrorEvent(event) && !isTransactionEvent(event)) {
|
|
4226
|
+
return event;
|
|
4227
|
+
}
|
|
4228
|
+
|
|
4118
4229
|
// Unless `captureExceptions` is enabled, we want to ignore errors coming from rrweb
|
|
4119
4230
|
// As there can be a bunch of stuff going wrong in internals there, that we don't want to bubble up to users
|
|
4120
4231
|
if (isRrwebError(event, hint) && !replay.getOptions()._experiments.captureExceptions) {
|
|
@@ -4123,50 +4234,22 @@ function handleGlobalEventListener(replay) {
|
|
|
4123
4234
|
}
|
|
4124
4235
|
|
|
4125
4236
|
// Only tag transactions with replayId if not waiting for an error
|
|
4126
|
-
|
|
4127
|
-
if (!event.type || replay.recordingMode === 'session') {
|
|
4237
|
+
if (isErrorEvent(event) || (isTransactionEvent(event) && replay.recordingMode === 'session')) {
|
|
4128
4238
|
event.tags = { ...event.tags, replayId: replay.getSessionId() };
|
|
4129
4239
|
}
|
|
4130
4240
|
|
|
4131
|
-
|
|
4132
|
-
// _context gets cleared on every checkout
|
|
4133
|
-
if (event.type === 'transaction' && event.contexts && event.contexts.trace && event.contexts.trace.trace_id) {
|
|
4134
|
-
replay.getContext().traceIds.add(event.contexts.trace.trace_id );
|
|
4135
|
-
return event;
|
|
4136
|
-
}
|
|
4137
|
-
|
|
4138
|
-
// no event type means error
|
|
4139
|
-
if (!event.type) {
|
|
4140
|
-
replay.getContext().errorIds.add(event.event_id );
|
|
4141
|
-
}
|
|
4142
|
-
|
|
4143
|
-
if ((typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && replay.getOptions()._experiments.traceInternals) {
|
|
4241
|
+
if ((typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && replay.getOptions()._experiments.traceInternals && isErrorEvent(event)) {
|
|
4144
4242
|
const exc = getEventExceptionValues(event);
|
|
4145
4243
|
addInternalBreadcrumb({
|
|
4146
4244
|
message: `Tagging event (${event.event_id}) - ${event.message} - ${exc.type}: ${exc.value}`,
|
|
4147
4245
|
});
|
|
4148
4246
|
}
|
|
4149
4247
|
|
|
4150
|
-
//
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
event
|
|
4155
|
-
) {
|
|
4156
|
-
setTimeout(async () => {
|
|
4157
|
-
// Allow flush to complete before resuming as a session recording, otherwise
|
|
4158
|
-
// the checkout from `startRecording` may be included in the payload.
|
|
4159
|
-
// Prefer to keep the error replay as a separate (and smaller) segment
|
|
4160
|
-
// than the session replay.
|
|
4161
|
-
await replay.flushImmediate();
|
|
4162
|
-
|
|
4163
|
-
if (replay.stopRecording()) {
|
|
4164
|
-
// Reset all "capture on error" configuration before
|
|
4165
|
-
// starting a new recording
|
|
4166
|
-
replay.recordingMode = 'session';
|
|
4167
|
-
replay.startRecording();
|
|
4168
|
-
}
|
|
4169
|
-
});
|
|
4248
|
+
// In cases where a custom client is used that does not support the new hooks (yet),
|
|
4249
|
+
// we manually call this hook method here
|
|
4250
|
+
if (afterSendHandler) {
|
|
4251
|
+
// Pretend the error had a 200 response so we always capture it
|
|
4252
|
+
afterSendHandler(event, { statusCode: 200 });
|
|
4170
4253
|
}
|
|
4171
4254
|
|
|
4172
4255
|
return event;
|
|
@@ -4192,29 +4275,54 @@ function getEventExceptionValues(event) {
|
|
|
4192
4275
|
};
|
|
4193
4276
|
}
|
|
4194
4277
|
|
|
4195
|
-
function handleHistory(handlerData) {
|
|
4196
|
-
const { from, to } = handlerData;
|
|
4197
|
-
|
|
4198
|
-
const now = new Date().getTime() / 1000;
|
|
4199
|
-
|
|
4200
|
-
return {
|
|
4201
|
-
type: 'navigation.push',
|
|
4202
|
-
start: now,
|
|
4203
|
-
end: now,
|
|
4204
|
-
name: to,
|
|
4205
|
-
data: {
|
|
4206
|
-
previous: from,
|
|
4207
|
-
},
|
|
4208
|
-
};
|
|
4209
|
-
}
|
|
4210
|
-
|
|
4211
4278
|
/**
|
|
4212
|
-
*
|
|
4279
|
+
* Create a "span" for each performance entry. The parent transaction is `this.replayEvent`.
|
|
4213
4280
|
*/
|
|
4214
|
-
function
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4281
|
+
function createPerformanceSpans(
|
|
4282
|
+
replay,
|
|
4283
|
+
entries,
|
|
4284
|
+
) {
|
|
4285
|
+
return entries.map(({ type, start, end, name, data }) =>
|
|
4286
|
+
addEvent(replay, {
|
|
4287
|
+
type: EventType.Custom,
|
|
4288
|
+
timestamp: start,
|
|
4289
|
+
data: {
|
|
4290
|
+
tag: 'performanceSpan',
|
|
4291
|
+
payload: {
|
|
4292
|
+
op: type,
|
|
4293
|
+
description: name,
|
|
4294
|
+
startTimestamp: start,
|
|
4295
|
+
endTimestamp: end,
|
|
4296
|
+
data,
|
|
4297
|
+
},
|
|
4298
|
+
},
|
|
4299
|
+
}),
|
|
4300
|
+
);
|
|
4301
|
+
}
|
|
4302
|
+
|
|
4303
|
+
function handleHistory(handlerData) {
|
|
4304
|
+
const { from, to } = handlerData;
|
|
4305
|
+
|
|
4306
|
+
const now = Date.now() / 1000;
|
|
4307
|
+
|
|
4308
|
+
return {
|
|
4309
|
+
type: 'navigation.push',
|
|
4310
|
+
start: now,
|
|
4311
|
+
end: now,
|
|
4312
|
+
name: to,
|
|
4313
|
+
data: {
|
|
4314
|
+
previous: from,
|
|
4315
|
+
},
|
|
4316
|
+
};
|
|
4317
|
+
}
|
|
4318
|
+
|
|
4319
|
+
/**
|
|
4320
|
+
* Returns a listener to be added to `addInstrumentationHandler('history', listener)`.
|
|
4321
|
+
*/
|
|
4322
|
+
function handleHistorySpanListener(replay) {
|
|
4323
|
+
return (handlerData) => {
|
|
4324
|
+
if (!replay.isEnabled()) {
|
|
4325
|
+
return;
|
|
4218
4326
|
}
|
|
4219
4327
|
|
|
4220
4328
|
const result = handleHistory(handlerData);
|
|
@@ -4235,91 +4343,120 @@ function handleHistorySpanListener(replay) {
|
|
|
4235
4343
|
};
|
|
4236
4344
|
}
|
|
4237
4345
|
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
const result = handleScope(scope);
|
|
4248
|
-
|
|
4249
|
-
if (!result) {
|
|
4250
|
-
return;
|
|
4251
|
-
}
|
|
4346
|
+
/**
|
|
4347
|
+
* Check whether a given request URL should be filtered out. This is so we
|
|
4348
|
+
* don't log Sentry ingest requests.
|
|
4349
|
+
*/
|
|
4350
|
+
function shouldFilterRequest(replay, url) {
|
|
4351
|
+
// If we enabled the `traceInternals` experiment, we want to trace everything
|
|
4352
|
+
if ((typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && replay.getOptions()._experiments.traceInternals) {
|
|
4353
|
+
return false;
|
|
4354
|
+
}
|
|
4252
4355
|
|
|
4253
|
-
|
|
4254
|
-
|
|
4356
|
+
return _isSentryRequest(url);
|
|
4357
|
+
}
|
|
4255
4358
|
|
|
4256
4359
|
/**
|
|
4257
|
-
*
|
|
4360
|
+
* Checks wether a given URL belongs to the configured Sentry DSN.
|
|
4258
4361
|
*/
|
|
4259
|
-
function
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
const newBreadcrumb = scope.getLastBreadcrumb && scope.getLastBreadcrumb();
|
|
4362
|
+
function _isSentryRequest(url) {
|
|
4363
|
+
const client = getCurrentHub().getClient();
|
|
4364
|
+
const dsn = client && client.getDsn();
|
|
4365
|
+
return dsn ? url.includes(dsn.host) : false;
|
|
4366
|
+
}
|
|
4265
4367
|
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
if (
|
|
4269
|
-
return
|
|
4368
|
+
/** Add a performance entry breadcrumb */
|
|
4369
|
+
function addNetworkBreadcrumb(replay, result) {
|
|
4370
|
+
if (!replay.isEnabled()) {
|
|
4371
|
+
return;
|
|
4270
4372
|
}
|
|
4271
4373
|
|
|
4272
|
-
|
|
4374
|
+
if (result === null) {
|
|
4375
|
+
return;
|
|
4376
|
+
}
|
|
4273
4377
|
|
|
4274
|
-
if (
|
|
4275
|
-
|
|
4276
|
-
(['fetch', 'xhr', 'sentry.event', 'sentry.transaction'].includes(newBreadcrumb.category) ||
|
|
4277
|
-
newBreadcrumb.category.startsWith('ui.'))
|
|
4278
|
-
) {
|
|
4279
|
-
return null;
|
|
4378
|
+
if (shouldFilterRequest(replay, result.name)) {
|
|
4379
|
+
return;
|
|
4280
4380
|
}
|
|
4281
4381
|
|
|
4282
|
-
|
|
4382
|
+
replay.addUpdate(() => {
|
|
4383
|
+
createPerformanceSpans(replay, [result]);
|
|
4384
|
+
// Returning true will cause `addUpdate` to not flush
|
|
4385
|
+
// We do not want network requests to cause a flush. This will prevent
|
|
4386
|
+
// recurring/polling requests from keeping the replay session alive.
|
|
4387
|
+
return true;
|
|
4388
|
+
});
|
|
4283
4389
|
}
|
|
4284
4390
|
|
|
4285
|
-
|
|
4286
|
-
|
|
4391
|
+
/** only exported for tests */
|
|
4392
|
+
function handleFetch(handlerData) {
|
|
4393
|
+
const { startTimestamp, endTimestamp, fetchData, response } = handlerData;
|
|
4287
4394
|
|
|
4288
|
-
|
|
4289
|
-
if (handlerData.xhr.__sentry_own_request__) {
|
|
4290
|
-
// Taken from sentry-javascript
|
|
4291
|
-
// Only capture non-sentry requests
|
|
4395
|
+
if (!endTimestamp) {
|
|
4292
4396
|
return null;
|
|
4293
4397
|
}
|
|
4294
4398
|
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4399
|
+
const { method, request_body_size: requestBodySize, response_body_size: responseBodySize } = fetchData;
|
|
4400
|
+
|
|
4401
|
+
return {
|
|
4402
|
+
type: 'resource.fetch',
|
|
4403
|
+
start: startTimestamp / 1000,
|
|
4404
|
+
end: endTimestamp / 1000,
|
|
4405
|
+
name: fetchData.url,
|
|
4406
|
+
data: {
|
|
4407
|
+
method,
|
|
4408
|
+
statusCode: response && (response ).status,
|
|
4409
|
+
requestBodySize,
|
|
4410
|
+
responseBodySize,
|
|
4411
|
+
},
|
|
4412
|
+
};
|
|
4413
|
+
}
|
|
4414
|
+
|
|
4415
|
+
/**
|
|
4416
|
+
* Returns a listener to be added to `addInstrumentationHandler('fetch', listener)`.
|
|
4417
|
+
*/
|
|
4418
|
+
function handleFetchSpanListener(replay) {
|
|
4419
|
+
return (handlerData) => {
|
|
4420
|
+
if (!replay.isEnabled()) {
|
|
4421
|
+
return;
|
|
4422
|
+
}
|
|
4423
|
+
|
|
4424
|
+
const result = handleFetch(handlerData);
|
|
4300
4425
|
|
|
4301
|
-
|
|
4426
|
+
addNetworkBreadcrumb(replay, result);
|
|
4427
|
+
};
|
|
4428
|
+
}
|
|
4429
|
+
|
|
4430
|
+
/** only exported for tests */
|
|
4431
|
+
function handleXhr(handlerData) {
|
|
4432
|
+
const { startTimestamp, endTimestamp, xhr } = handlerData;
|
|
4433
|
+
|
|
4434
|
+
if (!startTimestamp || !endTimestamp || !xhr.__sentry_xhr__) {
|
|
4302
4435
|
return null;
|
|
4303
4436
|
}
|
|
4304
4437
|
|
|
4305
|
-
const {
|
|
4438
|
+
const {
|
|
4439
|
+
method,
|
|
4440
|
+
url,
|
|
4441
|
+
status_code: statusCode,
|
|
4442
|
+
request_body_size: requestBodySize,
|
|
4443
|
+
response_body_size: responseBodySize,
|
|
4444
|
+
} = xhr.__sentry_xhr__;
|
|
4306
4445
|
|
|
4307
4446
|
if (url === undefined) {
|
|
4308
4447
|
return null;
|
|
4309
4448
|
}
|
|
4310
4449
|
|
|
4311
|
-
const timestamp = handlerData.xhr.__sentry_xhr__
|
|
4312
|
-
? handlerData.xhr.__sentry_xhr__.startTimestamp || 0
|
|
4313
|
-
: handlerData.endTimestamp;
|
|
4314
|
-
|
|
4315
4450
|
return {
|
|
4316
4451
|
type: 'resource.xhr',
|
|
4317
4452
|
name: url,
|
|
4318
|
-
start:
|
|
4319
|
-
end:
|
|
4453
|
+
start: startTimestamp / 1000,
|
|
4454
|
+
end: endTimestamp / 1000,
|
|
4320
4455
|
data: {
|
|
4321
4456
|
method,
|
|
4322
4457
|
statusCode,
|
|
4458
|
+
requestBodySize,
|
|
4459
|
+
responseBodySize,
|
|
4323
4460
|
},
|
|
4324
4461
|
};
|
|
4325
4462
|
}
|
|
@@ -4335,22 +4472,280 @@ function handleXhrSpanListener(replay) {
|
|
|
4335
4472
|
|
|
4336
4473
|
const result = handleXhr(handlerData);
|
|
4337
4474
|
|
|
4338
|
-
|
|
4475
|
+
addNetworkBreadcrumb(replay, result);
|
|
4476
|
+
};
|
|
4477
|
+
}
|
|
4478
|
+
|
|
4479
|
+
/**
|
|
4480
|
+
* This will enrich the xhr/fetch breadcrumbs with additional information.
|
|
4481
|
+
*
|
|
4482
|
+
* This adds:
|
|
4483
|
+
* * request_body_size
|
|
4484
|
+
* * response_body_size
|
|
4485
|
+
*
|
|
4486
|
+
* to the breadcrumb data.
|
|
4487
|
+
*/
|
|
4488
|
+
function handleNetworkBreadcrumbs(replay) {
|
|
4489
|
+
const client = getCurrentHub().getClient();
|
|
4490
|
+
|
|
4491
|
+
try {
|
|
4492
|
+
const textEncoder = new TextEncoder();
|
|
4493
|
+
|
|
4494
|
+
const options = {
|
|
4495
|
+
replay,
|
|
4496
|
+
textEncoder,
|
|
4497
|
+
};
|
|
4498
|
+
|
|
4499
|
+
if (client && client.on) {
|
|
4500
|
+
client.on('beforeAddBreadcrumb', (breadcrumb, hint) => handleNetworkBreadcrumb(options, breadcrumb, hint));
|
|
4501
|
+
} else {
|
|
4502
|
+
// Fallback behavior
|
|
4503
|
+
addInstrumentationHandler('fetch', handleFetchSpanListener(replay));
|
|
4504
|
+
addInstrumentationHandler('xhr', handleXhrSpanListener(replay));
|
|
4505
|
+
}
|
|
4506
|
+
} catch (e2) {
|
|
4507
|
+
// Do nothing
|
|
4508
|
+
}
|
|
4509
|
+
}
|
|
4510
|
+
|
|
4511
|
+
/** just exported for tests */
|
|
4512
|
+
function handleNetworkBreadcrumb(
|
|
4513
|
+
options,
|
|
4514
|
+
breadcrumb,
|
|
4515
|
+
hint,
|
|
4516
|
+
) {
|
|
4517
|
+
if (!breadcrumb.data) {
|
|
4518
|
+
return;
|
|
4519
|
+
}
|
|
4520
|
+
|
|
4521
|
+
try {
|
|
4522
|
+
if (_isXhrBreadcrumb(breadcrumb) && _isXhrHint(hint)) {
|
|
4523
|
+
// Enriches the breadcrumb overall
|
|
4524
|
+
_enrichXhrBreadcrumb(breadcrumb, hint, options);
|
|
4525
|
+
|
|
4526
|
+
// Create a replay performance entry from this breadcrumb
|
|
4527
|
+
const result = _makeNetworkReplayBreadcrumb('resource.xhr', breadcrumb, hint);
|
|
4528
|
+
addNetworkBreadcrumb(options.replay, result);
|
|
4529
|
+
}
|
|
4530
|
+
|
|
4531
|
+
if (_isFetchBreadcrumb(breadcrumb) && _isFetchHint(hint)) {
|
|
4532
|
+
// Enriches the breadcrumb overall
|
|
4533
|
+
_enrichFetchBreadcrumb(breadcrumb, hint, options);
|
|
4534
|
+
|
|
4535
|
+
// Create a replay performance entry from this breadcrumb
|
|
4536
|
+
const result = _makeNetworkReplayBreadcrumb('resource.fetch', breadcrumb, hint);
|
|
4537
|
+
addNetworkBreadcrumb(options.replay, result);
|
|
4538
|
+
}
|
|
4539
|
+
} catch (e) {
|
|
4540
|
+
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.warn('Error when enriching network breadcrumb');
|
|
4541
|
+
}
|
|
4542
|
+
}
|
|
4543
|
+
|
|
4544
|
+
function _makeNetworkReplayBreadcrumb(
|
|
4545
|
+
type,
|
|
4546
|
+
breadcrumb,
|
|
4547
|
+
hint,
|
|
4548
|
+
) {
|
|
4549
|
+
const { startTimestamp, endTimestamp } = hint;
|
|
4550
|
+
|
|
4551
|
+
if (!endTimestamp) {
|
|
4552
|
+
return null;
|
|
4553
|
+
}
|
|
4554
|
+
|
|
4555
|
+
const {
|
|
4556
|
+
url,
|
|
4557
|
+
method,
|
|
4558
|
+
status_code: statusCode,
|
|
4559
|
+
request_body_size: requestBodySize,
|
|
4560
|
+
response_body_size: responseBodySize,
|
|
4561
|
+
} = breadcrumb.data;
|
|
4562
|
+
|
|
4563
|
+
if (url === undefined) {
|
|
4564
|
+
return null;
|
|
4565
|
+
}
|
|
4566
|
+
|
|
4567
|
+
const result = {
|
|
4568
|
+
type,
|
|
4569
|
+
start: startTimestamp / 1000,
|
|
4570
|
+
end: endTimestamp / 1000,
|
|
4571
|
+
name: url,
|
|
4572
|
+
data: {
|
|
4573
|
+
method,
|
|
4574
|
+
statusCode,
|
|
4575
|
+
},
|
|
4576
|
+
};
|
|
4577
|
+
|
|
4578
|
+
if (requestBodySize) {
|
|
4579
|
+
result.data.requestBodySize = requestBodySize;
|
|
4580
|
+
}
|
|
4581
|
+
if (responseBodySize) {
|
|
4582
|
+
result.data.responseBodySize = responseBodySize;
|
|
4583
|
+
}
|
|
4584
|
+
|
|
4585
|
+
return result;
|
|
4586
|
+
}
|
|
4587
|
+
|
|
4588
|
+
function _enrichXhrBreadcrumb(
|
|
4589
|
+
breadcrumb,
|
|
4590
|
+
hint,
|
|
4591
|
+
options,
|
|
4592
|
+
) {
|
|
4593
|
+
const { xhr, input } = hint;
|
|
4594
|
+
|
|
4595
|
+
const reqSize = getBodySize(input, options.textEncoder);
|
|
4596
|
+
const resSize = xhr.getResponseHeader('content-length')
|
|
4597
|
+
? parseContentSizeHeader(xhr.getResponseHeader('content-length'))
|
|
4598
|
+
: getBodySize(xhr.response, options.textEncoder);
|
|
4599
|
+
|
|
4600
|
+
if (reqSize !== undefined) {
|
|
4601
|
+
breadcrumb.data.request_body_size = reqSize;
|
|
4602
|
+
}
|
|
4603
|
+
if (resSize !== undefined) {
|
|
4604
|
+
breadcrumb.data.response_body_size = resSize;
|
|
4605
|
+
}
|
|
4606
|
+
}
|
|
4607
|
+
|
|
4608
|
+
function _enrichFetchBreadcrumb(
|
|
4609
|
+
breadcrumb,
|
|
4610
|
+
hint,
|
|
4611
|
+
options,
|
|
4612
|
+
) {
|
|
4613
|
+
const { input, response } = hint;
|
|
4614
|
+
|
|
4615
|
+
const body = getFetchBody(input);
|
|
4616
|
+
const reqSize = getBodySize(body, options.textEncoder);
|
|
4617
|
+
const resSize = response ? parseContentSizeHeader(response.headers.get('content-length')) : undefined;
|
|
4618
|
+
|
|
4619
|
+
if (reqSize !== undefined) {
|
|
4620
|
+
breadcrumb.data.request_body_size = reqSize;
|
|
4621
|
+
}
|
|
4622
|
+
if (resSize !== undefined) {
|
|
4623
|
+
breadcrumb.data.response_body_size = resSize;
|
|
4624
|
+
}
|
|
4625
|
+
}
|
|
4626
|
+
|
|
4627
|
+
/** only exported for tests */
|
|
4628
|
+
function getBodySize(
|
|
4629
|
+
body,
|
|
4630
|
+
textEncoder,
|
|
4631
|
+
) {
|
|
4632
|
+
if (!body) {
|
|
4633
|
+
return undefined;
|
|
4634
|
+
}
|
|
4635
|
+
|
|
4636
|
+
try {
|
|
4637
|
+
if (typeof body === 'string') {
|
|
4638
|
+
return textEncoder.encode(body).length;
|
|
4639
|
+
}
|
|
4640
|
+
|
|
4641
|
+
if (body instanceof URLSearchParams) {
|
|
4642
|
+
return textEncoder.encode(body.toString()).length;
|
|
4643
|
+
}
|
|
4644
|
+
|
|
4645
|
+
if (body instanceof FormData) {
|
|
4646
|
+
// This is a bit simplified, but gives us a decent estimate
|
|
4647
|
+
// This converts e.g. { name: 'Anne Smith', age: 13 } to 'name=Anne+Smith&age=13'
|
|
4648
|
+
// @ts-ignore passing FormData to URLSearchParams actually works
|
|
4649
|
+
const formDataStr = new URLSearchParams(body).toString();
|
|
4650
|
+
return textEncoder.encode(formDataStr).length;
|
|
4651
|
+
}
|
|
4652
|
+
|
|
4653
|
+
if (body instanceof Blob) {
|
|
4654
|
+
return body.size;
|
|
4655
|
+
}
|
|
4656
|
+
|
|
4657
|
+
if (body instanceof ArrayBuffer) {
|
|
4658
|
+
return body.byteLength;
|
|
4659
|
+
}
|
|
4660
|
+
|
|
4661
|
+
// Currently unhandled types: ArrayBufferView, ReadableStream
|
|
4662
|
+
} catch (e3) {
|
|
4663
|
+
// just return undefined
|
|
4664
|
+
}
|
|
4665
|
+
|
|
4666
|
+
return undefined;
|
|
4667
|
+
}
|
|
4668
|
+
|
|
4669
|
+
/** only exported for tests */
|
|
4670
|
+
function parseContentSizeHeader(header) {
|
|
4671
|
+
if (!header) {
|
|
4672
|
+
return undefined;
|
|
4673
|
+
}
|
|
4674
|
+
|
|
4675
|
+
const size = parseInt(header, 10);
|
|
4676
|
+
return isNaN(size) ? undefined : size;
|
|
4677
|
+
}
|
|
4678
|
+
|
|
4679
|
+
function getFetchBody(fetchArgs = []) {
|
|
4680
|
+
// We only support getting the body from the fetch options
|
|
4681
|
+
if (fetchArgs.length !== 2 || typeof fetchArgs[1] !== 'object') {
|
|
4682
|
+
return undefined;
|
|
4683
|
+
}
|
|
4684
|
+
|
|
4685
|
+
return (fetchArgs[1] ).body;
|
|
4686
|
+
}
|
|
4687
|
+
|
|
4688
|
+
function _isXhrBreadcrumb(breadcrumb) {
|
|
4689
|
+
return breadcrumb.category === 'xhr';
|
|
4690
|
+
}
|
|
4691
|
+
|
|
4692
|
+
function _isFetchBreadcrumb(breadcrumb) {
|
|
4693
|
+
return breadcrumb.category === 'fetch';
|
|
4694
|
+
}
|
|
4695
|
+
|
|
4696
|
+
function _isXhrHint(hint) {
|
|
4697
|
+
return hint && hint.xhr;
|
|
4698
|
+
}
|
|
4699
|
+
|
|
4700
|
+
function _isFetchHint(hint) {
|
|
4701
|
+
return hint && hint.response;
|
|
4702
|
+
}
|
|
4703
|
+
|
|
4704
|
+
let _LAST_BREADCRUMB = null;
|
|
4705
|
+
|
|
4706
|
+
const handleScopeListener =
|
|
4707
|
+
(replay) =>
|
|
4708
|
+
(scope) => {
|
|
4709
|
+
if (!replay.isEnabled()) {
|
|
4339
4710
|
return;
|
|
4340
4711
|
}
|
|
4341
4712
|
|
|
4342
|
-
|
|
4713
|
+
const result = handleScope(scope);
|
|
4714
|
+
|
|
4715
|
+
if (!result) {
|
|
4343
4716
|
return;
|
|
4344
4717
|
}
|
|
4345
4718
|
|
|
4346
|
-
replay
|
|
4347
|
-
createPerformanceSpans(replay, [result]);
|
|
4348
|
-
// Returning true will cause `addUpdate` to not flush
|
|
4349
|
-
// We do not want network requests to cause a flush. This will prevent
|
|
4350
|
-
// recurring/polling requests from keeping the replay session alive.
|
|
4351
|
-
return true;
|
|
4352
|
-
});
|
|
4719
|
+
addBreadcrumbEvent(replay, result);
|
|
4353
4720
|
};
|
|
4721
|
+
|
|
4722
|
+
/**
|
|
4723
|
+
* An event handler to handle scope changes.
|
|
4724
|
+
*/
|
|
4725
|
+
function handleScope(scope) {
|
|
4726
|
+
// TODO (v8): Remove this guard. This was put in place because we introduced
|
|
4727
|
+
// Scope.getLastBreadcrumb mid-v7 which caused incompatibilities with older SDKs.
|
|
4728
|
+
// For now, we'll just return null if the method doesn't exist but we should eventually
|
|
4729
|
+
// get rid of this guard.
|
|
4730
|
+
const newBreadcrumb = scope.getLastBreadcrumb && scope.getLastBreadcrumb();
|
|
4731
|
+
|
|
4732
|
+
// Listener can be called when breadcrumbs have not changed, so we store the
|
|
4733
|
+
// reference to the last crumb and only return a crumb if it has changed
|
|
4734
|
+
if (_LAST_BREADCRUMB === newBreadcrumb || !newBreadcrumb) {
|
|
4735
|
+
return null;
|
|
4736
|
+
}
|
|
4737
|
+
|
|
4738
|
+
_LAST_BREADCRUMB = newBreadcrumb;
|
|
4739
|
+
|
|
4740
|
+
if (
|
|
4741
|
+
newBreadcrumb.category &&
|
|
4742
|
+
(['fetch', 'xhr', 'sentry.event', 'sentry.transaction'].includes(newBreadcrumb.category) ||
|
|
4743
|
+
newBreadcrumb.category.startsWith('ui.'))
|
|
4744
|
+
) {
|
|
4745
|
+
return null;
|
|
4746
|
+
}
|
|
4747
|
+
|
|
4748
|
+
return createBreadcrumb(newBreadcrumb);
|
|
4354
4749
|
}
|
|
4355
4750
|
|
|
4356
4751
|
/**
|
|
@@ -4359,17 +4754,26 @@ function handleXhrSpanListener(replay) {
|
|
|
4359
4754
|
function addGlobalListeners(replay) {
|
|
4360
4755
|
// Listeners from core SDK //
|
|
4361
4756
|
const scope = getCurrentHub().getScope();
|
|
4757
|
+
const client = getCurrentHub().getClient();
|
|
4758
|
+
|
|
4362
4759
|
if (scope) {
|
|
4363
4760
|
scope.addScopeListener(handleScopeListener(replay));
|
|
4364
4761
|
}
|
|
4365
4762
|
addInstrumentationHandler('dom', handleDomListener(replay));
|
|
4366
|
-
addInstrumentationHandler('fetch', handleFetchSpanListener(replay));
|
|
4367
|
-
addInstrumentationHandler('xhr', handleXhrSpanListener(replay));
|
|
4368
4763
|
addInstrumentationHandler('history', handleHistorySpanListener(replay));
|
|
4764
|
+
handleNetworkBreadcrumbs(replay);
|
|
4765
|
+
|
|
4766
|
+
// If a custom client has no hooks yet, we continue to use the "old" implementation
|
|
4767
|
+
const hasHooks = !!(client && client.on);
|
|
4369
4768
|
|
|
4370
4769
|
// Tag all (non replay) events that get sent to Sentry with the current
|
|
4371
4770
|
// replay ID so that we can reference them later in the UI
|
|
4372
|
-
addGlobalEventProcessor(handleGlobalEventListener(replay));
|
|
4771
|
+
addGlobalEventProcessor(handleGlobalEventListener(replay, !hasHooks));
|
|
4772
|
+
|
|
4773
|
+
if (hasHooks) {
|
|
4774
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4775
|
+
(client ).on('afterSendEvent', handleAfterSendEvent(replay));
|
|
4776
|
+
}
|
|
4373
4777
|
}
|
|
4374
4778
|
|
|
4375
4779
|
/**
|
|
@@ -4395,7 +4799,7 @@ function createMemoryEntry(memoryEntry) {
|
|
|
4395
4799
|
const { jsHeapSizeLimit, totalJSHeapSize, usedJSHeapSize } = memoryEntry;
|
|
4396
4800
|
// we don't want to use `getAbsoluteTime` because it adds the event time to the
|
|
4397
4801
|
// time origin, so we get the current timestamp instead
|
|
4398
|
-
const time =
|
|
4802
|
+
const time = Date.now() / 1000;
|
|
4399
4803
|
return {
|
|
4400
4804
|
type: 'memory',
|
|
4401
4805
|
name: 'memory',
|
|
@@ -4682,49 +5086,6 @@ function getHandleRecordingEmit(replay) {
|
|
|
4682
5086
|
};
|
|
4683
5087
|
}
|
|
4684
5088
|
|
|
4685
|
-
let _originalRecordDroppedEvent;
|
|
4686
|
-
|
|
4687
|
-
/**
|
|
4688
|
-
* Overwrite the `recordDroppedEvent` method on the client, so we can find out which events were dropped.
|
|
4689
|
-
* */
|
|
4690
|
-
function overwriteRecordDroppedEvent(errorIds) {
|
|
4691
|
-
const client = getCurrentHub().getClient();
|
|
4692
|
-
|
|
4693
|
-
if (!client) {
|
|
4694
|
-
return;
|
|
4695
|
-
}
|
|
4696
|
-
|
|
4697
|
-
const _originalCallback = client.recordDroppedEvent.bind(client);
|
|
4698
|
-
|
|
4699
|
-
const recordDroppedEvent = (
|
|
4700
|
-
reason,
|
|
4701
|
-
category,
|
|
4702
|
-
event,
|
|
4703
|
-
) => {
|
|
4704
|
-
if (event && !event.type && event.event_id) {
|
|
4705
|
-
errorIds.delete(event.event_id);
|
|
4706
|
-
}
|
|
4707
|
-
|
|
4708
|
-
return _originalCallback(reason, category, event);
|
|
4709
|
-
};
|
|
4710
|
-
|
|
4711
|
-
client.recordDroppedEvent = recordDroppedEvent;
|
|
4712
|
-
_originalRecordDroppedEvent = _originalCallback;
|
|
4713
|
-
}
|
|
4714
|
-
|
|
4715
|
-
/**
|
|
4716
|
-
* Restore the original method.
|
|
4717
|
-
* */
|
|
4718
|
-
function restoreRecordDroppedEvent() {
|
|
4719
|
-
const client = getCurrentHub().getClient();
|
|
4720
|
-
|
|
4721
|
-
if (!client || !_originalRecordDroppedEvent) {
|
|
4722
|
-
return;
|
|
4723
|
-
}
|
|
4724
|
-
|
|
4725
|
-
client.recordDroppedEvent = _originalRecordDroppedEvent;
|
|
4726
|
-
}
|
|
4727
|
-
|
|
4728
5089
|
/**
|
|
4729
5090
|
* Create a replay envelope ready to be sent.
|
|
4730
5091
|
* This includes both the replay event, as well as the recording data.
|
|
@@ -5077,7 +5438,7 @@ class ReplayContainer {
|
|
|
5077
5438
|
/**
|
|
5078
5439
|
* Timestamp of the last user activity. This lives across sessions.
|
|
5079
5440
|
*/
|
|
5080
|
-
__init7() {this._lastActivity =
|
|
5441
|
+
__init7() {this._lastActivity = Date.now();}
|
|
5081
5442
|
|
|
5082
5443
|
/**
|
|
5083
5444
|
* Is the integration currently active?
|
|
@@ -5107,7 +5468,7 @@ class ReplayContainer {
|
|
|
5107
5468
|
traceIds: new Set(),
|
|
5108
5469
|
urls: [],
|
|
5109
5470
|
earliestEvent: null,
|
|
5110
|
-
initialTimestamp:
|
|
5471
|
+
initialTimestamp: Date.now(),
|
|
5111
5472
|
initialUrl: '',
|
|
5112
5473
|
};}
|
|
5113
5474
|
|
|
@@ -5389,11 +5750,19 @@ class ReplayContainer {
|
|
|
5389
5750
|
const oldSessionId = this.getSessionId();
|
|
5390
5751
|
|
|
5391
5752
|
// Prevent starting a new session if the last user activity is older than
|
|
5392
|
-
//
|
|
5753
|
+
// SESSION_IDLE_DURATION. Otherwise non-user activity can trigger a new
|
|
5393
5754
|
// session+recording. This creates noisy replays that do not have much
|
|
5394
5755
|
// content in them.
|
|
5395
|
-
if (
|
|
5396
|
-
|
|
5756
|
+
if (
|
|
5757
|
+
this._lastActivity &&
|
|
5758
|
+
isExpired(this._lastActivity, this.timeouts.sessionIdle) &&
|
|
5759
|
+
this.session &&
|
|
5760
|
+
this.session.sampled === 'session'
|
|
5761
|
+
) {
|
|
5762
|
+
// Pause recording only for session-based replays. Otherwise, resuming
|
|
5763
|
+
// will create a new replay and will conflict with users who only choose
|
|
5764
|
+
// to record error-based replays only. (e.g. the resumed replay will not
|
|
5765
|
+
// contain a reference to an error)
|
|
5397
5766
|
this.pause();
|
|
5398
5767
|
return;
|
|
5399
5768
|
}
|
|
@@ -5432,7 +5801,7 @@ class ReplayContainer {
|
|
|
5432
5801
|
this._clearContext();
|
|
5433
5802
|
|
|
5434
5803
|
this._context.initialUrl = url;
|
|
5435
|
-
this._context.initialTimestamp =
|
|
5804
|
+
this._context.initialTimestamp = Date.now();
|
|
5436
5805
|
this._context.urls.push(url);
|
|
5437
5806
|
}
|
|
5438
5807
|
|
|
@@ -5488,9 +5857,6 @@ class ReplayContainer {
|
|
|
5488
5857
|
WINDOW.addEventListener('blur', this._handleWindowBlur);
|
|
5489
5858
|
WINDOW.addEventListener('focus', this._handleWindowFocus);
|
|
5490
5859
|
|
|
5491
|
-
// We need to filter out dropped events captured by `addGlobalEventProcessor(this.handleGlobalEvent)` below
|
|
5492
|
-
overwriteRecordDroppedEvent(this._context.errorIds);
|
|
5493
|
-
|
|
5494
5860
|
// There is no way to remove these listeners, so ensure they are only added once
|
|
5495
5861
|
if (!this._hasInitializedCoreListeners) {
|
|
5496
5862
|
addGlobalListeners(this);
|
|
@@ -5519,8 +5885,6 @@ class ReplayContainer {
|
|
|
5519
5885
|
WINDOW.removeEventListener('blur', this._handleWindowBlur);
|
|
5520
5886
|
WINDOW.removeEventListener('focus', this._handleWindowFocus);
|
|
5521
5887
|
|
|
5522
|
-
restoreRecordDroppedEvent();
|
|
5523
|
-
|
|
5524
5888
|
if (this._performanceObserver) {
|
|
5525
5889
|
this._performanceObserver.disconnect();
|
|
5526
5890
|
this._performanceObserver = null;
|
|
@@ -5629,14 +5993,14 @@ class ReplayContainer {
|
|
|
5629
5993
|
/**
|
|
5630
5994
|
* Update user activity (across session lifespans)
|
|
5631
5995
|
*/
|
|
5632
|
-
_updateUserActivity(_lastActivity =
|
|
5996
|
+
_updateUserActivity(_lastActivity = Date.now()) {
|
|
5633
5997
|
this._lastActivity = _lastActivity;
|
|
5634
5998
|
}
|
|
5635
5999
|
|
|
5636
6000
|
/**
|
|
5637
6001
|
* Updates the session's last activity timestamp
|
|
5638
6002
|
*/
|
|
5639
|
-
_updateSessionActivity(_lastActivity =
|
|
6003
|
+
_updateSessionActivity(_lastActivity = Date.now()) {
|
|
5640
6004
|
if (this.session) {
|
|
5641
6005
|
this.session.lastActivity = _lastActivity;
|
|
5642
6006
|
this._maybeSaveSession();
|
|
@@ -5763,7 +6127,7 @@ class ReplayContainer {
|
|
|
5763
6127
|
eventContext,
|
|
5764
6128
|
session: this.session,
|
|
5765
6129
|
options: this.getOptions(),
|
|
5766
|
-
timestamp:
|
|
6130
|
+
timestamp: Date.now(),
|
|
5767
6131
|
});
|
|
5768
6132
|
} catch (err) {
|
|
5769
6133
|
this._handleException(err);
|
|
@@ -5909,7 +6273,7 @@ function getPrivacyOptions({
|
|
|
5909
6273
|
blockSelector,
|
|
5910
6274
|
),
|
|
5911
6275
|
unblockSelector: getOption(unblock, ['.sentry-unblock', '[data-sentry-unblock]']),
|
|
5912
|
-
ignoreSelector: getOption(ignore, ['.sentry-ignore', '[data-sentry-ignore]'], ignoreClass),
|
|
6276
|
+
ignoreSelector: getOption(ignore, ['.sentry-ignore', '[data-sentry-ignore]', 'input[type="file"]'], ignoreClass),
|
|
5913
6277
|
};
|
|
5914
6278
|
|
|
5915
6279
|
if (blockClass instanceof RegExp) {
|