@sentry/browser-utils 11.0.0-alpha.1 → 11.0.0-alpha.2
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/build/cjs/component-name.js +28 -0
- package/build/cjs/component-name.js.map +1 -0
- package/build/cjs/getLocationHref.js +14 -0
- package/build/cjs/getLocationHref.js.map +1 -0
- package/build/cjs/index.js +8 -1
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/instrumentation/dom.js.map +1 -1
- package/build/cjs/instrumentation/history.js +5 -1
- package/build/cjs/instrumentation/history.js.map +1 -1
- package/build/cjs/instrumentation/xhr.js.map +1 -1
- package/build/cjs/isBotUserAgent.js +15 -0
- package/build/cjs/isBotUserAgent.js.map +1 -0
- package/build/cjs/performance/entries.js +26 -48
- package/build/cjs/performance/entries.js.map +1 -1
- package/build/cjs/performance/interactions.js +123 -0
- package/build/cjs/performance/interactions.js.map +1 -0
- package/build/cjs/performance/utils.js +4 -4
- package/build/cjs/performance/utils.js.map +1 -1
- package/build/cjs/types.js.map +1 -1
- package/build/cjs/web-vitals/inp.js.map +1 -1
- package/build/cjs/web-vitals/spans.js +20 -12
- package/build/cjs/web-vitals/spans.js.map +1 -1
- package/build/esm/component-name.js +26 -0
- package/build/esm/component-name.js.map +1 -0
- package/build/esm/getLocationHref.js +12 -0
- package/build/esm/getLocationHref.js.map +1 -0
- package/build/esm/index.js +5 -1
- package/build/esm/index.js.map +1 -1
- package/build/esm/instrumentation/dom.js.map +1 -1
- package/build/esm/instrumentation/history.js +5 -2
- package/build/esm/instrumentation/history.js.map +1 -1
- package/build/esm/instrumentation/xhr.js.map +1 -1
- package/build/esm/isBotUserAgent.js +13 -0
- package/build/esm/isBotUserAgent.js.map +1 -0
- package/build/esm/package.json +1 -1
- package/build/esm/performance/entries.js +30 -51
- package/build/esm/performance/entries.js.map +1 -1
- package/build/esm/performance/interactions.js +121 -0
- package/build/esm/performance/interactions.js.map +1 -0
- package/build/esm/performance/utils.js +1 -1
- package/build/esm/performance/utils.js.map +1 -1
- package/build/esm/types.js.map +1 -1
- package/build/esm/web-vitals/inp.js.map +1 -1
- package/build/esm/web-vitals/spans.js +20 -12
- package/build/esm/web-vitals/spans.js.map +1 -1
- package/build/types/component-name.d.ts +9 -0
- package/build/types/component-name.d.ts.map +1 -0
- package/build/types/getLocationHref.d.ts +5 -0
- package/build/types/getLocationHref.d.ts.map +1 -0
- package/build/types/index.d.ts +6 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/instrumentation/dom.d.ts +1 -1
- package/build/types/instrumentation/dom.d.ts.map +1 -1
- package/build/types/instrumentation/history.d.ts +8 -1
- package/build/types/instrumentation/history.d.ts.map +1 -1
- package/build/types/instrumentation/xhr.d.ts +1 -1
- package/build/types/instrumentation/xhr.d.ts.map +1 -1
- package/build/types/isBotUserAgent.d.ts +5 -0
- package/build/types/isBotUserAgent.d.ts.map +1 -0
- package/build/types/performance/entries.d.ts +1 -5
- package/build/types/performance/entries.d.ts.map +1 -1
- package/build/types/performance/interactions.d.ts +48 -0
- package/build/types/performance/interactions.d.ts.map +1 -0
- package/build/types/types.d.ts +38 -1
- package/build/types/types.d.ts.map +1 -1
- package/build/types/web-vitals/inp.d.ts +2 -1
- package/build/types/web-vitals/inp.d.ts.map +1 -1
- package/build/types/web-vitals/spans.d.ts.map +1 -1
- package/package.json +4 -3
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const core = require('@sentry/core');
|
|
4
|
+
|
|
5
|
+
function getComponentName(elem, maxTraverseHeight = 5) {
|
|
6
|
+
if (!core.GLOBAL_OBJ.HTMLElement) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
let currentElem = elem;
|
|
10
|
+
for (let i = 0; i < maxTraverseHeight; i++) {
|
|
11
|
+
if (!currentElem) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
if (currentElem instanceof HTMLElement) {
|
|
15
|
+
if (currentElem.dataset["sentryComponent"]) {
|
|
16
|
+
return currentElem.dataset["sentryComponent"];
|
|
17
|
+
}
|
|
18
|
+
if (currentElem.dataset["sentryElement"]) {
|
|
19
|
+
return currentElem.dataset["sentryElement"];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
currentElem = currentElem.parentNode;
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.getComponentName = getComponentName;
|
|
28
|
+
//# sourceMappingURL=component-name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-name.js","sources":["../../src/component-name.ts"],"sourcesContent":["import { GLOBAL_OBJ } from '@sentry/core';\n\ntype SimpleNode = {\n parentNode: SimpleNode;\n} | null;\n\n/**\n * Given a DOM element, traverses up the tree until it finds the first ancestor node\n * that has the `data-sentry-component` or `data-sentry-element` attribute with `data-sentry-component` taking\n * precedence. This attribute is added at build-time by projects that have the component name annotation plugin installed.\n *\n * @returns a string representation of the component for the provided DOM element, or `null` if not found\n */\nexport function getComponentName(elem: unknown, maxTraverseHeight: number = 5): string | null {\n // @ts-expect-error WINDOW has HTMLElement\n if (!GLOBAL_OBJ.HTMLElement) {\n return null;\n }\n\n let currentElem = elem as SimpleNode;\n for (let i = 0; i < maxTraverseHeight; i++) {\n if (!currentElem) {\n return null;\n }\n\n if (currentElem instanceof HTMLElement) {\n if (currentElem.dataset['sentryComponent']) {\n return currentElem.dataset['sentryComponent'];\n }\n if (currentElem.dataset['sentryElement']) {\n return currentElem.dataset['sentryElement'];\n }\n }\n\n currentElem = currentElem.parentNode;\n }\n\n return null;\n}\n"],"names":["GLOBAL_OBJ"],"mappings":";;;;AAaO,SAAS,gBAAA,CAAiB,IAAA,EAAe,iBAAA,GAA4B,CAAA,EAAkB;AAE5F,EAAA,IAAI,CAACA,gBAAW,WAAA,EAAa;AAC3B,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,IAAI,WAAA,GAAc,IAAA;AAClB,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,iBAAA,EAAmB,CAAA,EAAA,EAAK;AAC1C,IAAA,IAAI,CAAC,WAAA,EAAa;AAChB,MAAA,OAAO,IAAA;AAAA,IACT;AAEA,IAAA,IAAI,uBAAuB,WAAA,EAAa;AACtC,MAAA,IAAI,WAAA,CAAY,OAAA,CAAQ,iBAAiB,CAAA,EAAG;AAC1C,QAAA,OAAO,WAAA,CAAY,QAAQ,iBAAiB,CAAA;AAAA,MAC9C;AACA,MAAA,IAAI,WAAA,CAAY,OAAA,CAAQ,eAAe,CAAA,EAAG;AACxC,QAAA,OAAO,WAAA,CAAY,QAAQ,eAAe,CAAA;AAAA,MAC5C;AAAA,IACF;AAEA,IAAA,WAAA,GAAc,WAAA,CAAY,UAAA;AAAA,EAC5B;AAEA,EAAA,OAAO,IAAA;AACT;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const types = require('./types.js');
|
|
4
|
+
|
|
5
|
+
function getLocationHref() {
|
|
6
|
+
try {
|
|
7
|
+
return types.WINDOW.document?.location.href ?? "";
|
|
8
|
+
} catch {
|
|
9
|
+
return "";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.getLocationHref = getLocationHref;
|
|
14
|
+
//# sourceMappingURL=getLocationHref.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLocationHref.js","sources":["../../src/getLocationHref.ts"],"sourcesContent":["import { WINDOW } from './types';\n\n/**\n * A safe form of location.href.\n */\nexport function getLocationHref(): string {\n try {\n return WINDOW.document?.location.href ?? '';\n } catch {\n return '';\n }\n}\n"],"names":["WINDOW"],"mappings":";;;;AAKO,SAAS,eAAA,GAA0B;AACxC,EAAA,IAAI;AACF,IAAA,OAAOA,YAAA,CAAO,QAAA,EAAU,QAAA,CAAS,IAAA,IAAQ,EAAA;AAAA,EAC3C,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,EAAA;AAAA,EACT;AACF;;;;"}
|
package/build/cjs/index.js
CHANGED
|
@@ -4,6 +4,9 @@ const performanceObserver = require('./instrumentation/performanceObserver.js');
|
|
|
4
4
|
const entries = require('./performance/entries.js');
|
|
5
5
|
const tracking = require('./web-vitals/tracking.js');
|
|
6
6
|
const elementTiming = require('./performance/elementTiming.js');
|
|
7
|
+
const interactions = require('./performance/interactions.js');
|
|
8
|
+
const isBotUserAgent = require('./isBotUserAgent.js');
|
|
9
|
+
const getLocationHref = require('./getLocationHref.js');
|
|
7
10
|
const userTiming = require('./performance/userTiming.js');
|
|
8
11
|
const utils = require('./performance/utils.js');
|
|
9
12
|
const spans = require('./web-vitals/spans.js');
|
|
@@ -15,6 +18,7 @@ const xhr = require('./instrumentation/xhr.js');
|
|
|
15
18
|
const networkUtils = require('./networkUtils.js');
|
|
16
19
|
const resourceTiming = require('./performance/resourceTiming.js');
|
|
17
20
|
const htmlTreeAsString = require('./htmlTreeAsString.js');
|
|
21
|
+
const componentName = require('./component-name.js');
|
|
18
22
|
const is = require('./is.js');
|
|
19
23
|
const location = require('./instrumentation/location.js');
|
|
20
24
|
const inp = require('./web-vitals/inp.js');
|
|
@@ -27,13 +31,15 @@ exports.addLcpInstrumentationHandler = performanceObserver.addLcpInstrumentation
|
|
|
27
31
|
exports.addPerformanceInstrumentationHandler = performanceObserver.addPerformanceInstrumentationHandler;
|
|
28
32
|
exports.addTtfbInstrumentationHandler = performanceObserver.addTtfbInstrumentationHandler;
|
|
29
33
|
exports.addPerformanceEntries = entries.addPerformanceEntries;
|
|
30
|
-
exports.startTrackingInteractions = entries.startTrackingInteractions;
|
|
31
34
|
exports.startTrackingLongAnimationFrames = entries.startTrackingLongAnimationFrames;
|
|
32
35
|
exports.startTrackingLongTasks = entries.startTrackingLongTasks;
|
|
33
36
|
exports.addWebVitalsToSpan = tracking.addWebVitalsToSpan;
|
|
34
37
|
exports.startTrackingWebVitals = tracking.startTrackingWebVitals;
|
|
35
38
|
exports.elementTimingIntegration = elementTiming.elementTimingIntegration;
|
|
36
39
|
exports.startTrackingElementTiming = elementTiming.startTrackingElementTiming;
|
|
40
|
+
exports.interactionsIntegration = interactions.interactionsIntegration;
|
|
41
|
+
exports.isBotUserAgent = isBotUserAgent.isBotUserAgent;
|
|
42
|
+
exports.getLocationHref = getLocationHref.getLocationHref;
|
|
37
43
|
exports.userTimingIntegration = userTiming.userTimingIntegration;
|
|
38
44
|
exports.extractNetworkProtocol = utils.extractNetworkProtocol;
|
|
39
45
|
exports.trackClsAsSpan = spans.trackClsAsSpan;
|
|
@@ -54,6 +60,7 @@ exports.parseXhrResponseHeaders = networkUtils.parseXhrResponseHeaders;
|
|
|
54
60
|
exports.serializeFormData = networkUtils.serializeFormData;
|
|
55
61
|
exports.resourceTimingToSpanAttributes = resourceTiming.resourceTimingToSpanAttributes;
|
|
56
62
|
exports.htmlTreeAsString = htmlTreeAsString.htmlTreeAsString;
|
|
63
|
+
exports.getComponentName = componentName.getComponentName;
|
|
57
64
|
exports.isElement = is.isElement;
|
|
58
65
|
exports.getAbsoluteUrl = location.getAbsoluteUrl;
|
|
59
66
|
exports.registerInpInteractionListener = inp.registerInpInteractionListener;
|
package/build/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom.js","sources":["../../../src/instrumentation/dom.ts"],"sourcesContent":["import type { HandlerDataDom } from '@sentry/core';\nimport { addHandler, addNonEnumerableProperty, fill, maybeInstrument, triggerHandlers, uuid4 } from '@sentry/core';\nimport { WINDOW } from '../types';\n\ntype SentryWrappedTarget = HTMLElement & { _sentryId?: string };\n\ntype AddEventListener = (\n type: string,\n listener: EventListenerOrEventListenerObject,\n options?: boolean | AddEventListenerOptions,\n) => void;\ntype RemoveEventListener = (\n type: string,\n listener: EventListenerOrEventListenerObject,\n options?: boolean | EventListenerOptions,\n) => void;\n\ntype InstrumentedElement = Element & {\n __sentry_instrumentation_handlers__?: {\n [key in 'click' | 'keypress']?: {\n handler?: unknown;\n /** The number of custom listeners attached to this element */\n refCount: number;\n };\n };\n};\n\nconst DEBOUNCE_DURATION = 1000;\n\nlet debounceTimerID: number | undefined;\nlet lastCapturedEventType: string | undefined;\nlet lastCapturedEventTargetId: string | undefined;\n\n/**\n * Add an instrumentation handler for when a click or a keypress happens.\n *\n * Use at your own risk, this might break without changelog notice, only used internally.\n * @hidden\n */\nexport function addClickKeypressInstrumentationHandler(handler: (data: HandlerDataDom) => void): void {\n const type = 'dom';\n addHandler(type, handler);\n maybeInstrument(type, instrumentDOM);\n}\n\n/** Exported for tests only. */\nexport function instrumentDOM(): void {\n if (!WINDOW.document) {\n return;\n }\n\n // Make it so that any click or keypress that is unhandled / bubbled up all the way to the document triggers our dom\n // handlers. (Normally we have only one, which captures a breadcrumb for each click or keypress.) Do this before\n // we instrument `addEventListener` so that we don't end up attaching this handler twice.\n const triggerDOMHandler = triggerHandlers.bind(null, 'dom');\n const globalDOMEventHandler = makeDOMEventHandler(triggerDOMHandler, true);\n WINDOW.document.addEventListener('click', globalDOMEventHandler, false);\n WINDOW.document.addEventListener('keypress', globalDOMEventHandler, false);\n\n // After hooking into click and keypress events bubbled up to `document`, we also hook into user-handled\n // clicks & keypresses, by adding an event listener of our own to any element to which they add a listener. That\n // way, whenever one of their handlers is triggered, ours will be, too. (This is needed because their handler\n // could potentially prevent the event from bubbling up to our global listeners. This way, our handler are still\n // guaranteed to fire at least once.)\n ['EventTarget', 'Node'].forEach((target: string) => {\n const globalObject = WINDOW as unknown as Record<string, { prototype?: object }>;\n const proto = globalObject[target]?.prototype;\n\n // eslint-disable-next-line no-prototype-builtins\n if (!proto?.hasOwnProperty?.('addEventListener')) {\n return;\n }\n\n fill(proto, 'addEventListener', function (originalAddEventListener: AddEventListener): AddEventListener {\n return function (this: InstrumentedElement, type, listener, options): AddEventListener {\n if (type === 'click' || type == 'keypress') {\n try {\n const handlers = (this.__sentry_instrumentation_handlers__ =\n this.__sentry_instrumentation_handlers__ || {});\n const handlerForType = (handlers[type] = handlers[type] || { refCount: 0 });\n\n if (!handlerForType.handler) {\n const handler = makeDOMEventHandler(triggerDOMHandler);\n handlerForType.handler = handler;\n originalAddEventListener.call(this, type, handler, options);\n }\n\n handlerForType.refCount++;\n } catch {\n // Accessing dom properties is always fragile.\n // Also allows us to skip `addEventListeners` calls with no proper `this` context.\n }\n }\n\n return originalAddEventListener.call(this, type, listener, options);\n };\n });\n\n fill(\n proto,\n 'removeEventListener',\n function (originalRemoveEventListener: RemoveEventListener): RemoveEventListener {\n return function (this: InstrumentedElement, type, listener, options): () => void {\n if (type === 'click' || type == 'keypress') {\n try {\n const handlers = this.__sentry_instrumentation_handlers__ || {};\n const handlerForType = handlers[type];\n\n if (handlerForType) {\n handlerForType.refCount--;\n // If there are no longer any custom handlers of the current type on this element, we can remove ours, too.\n if (handlerForType.refCount <= 0) {\n originalRemoveEventListener.call(this, type, handlerForType.handler, options);\n handlerForType.handler = undefined;\n delete handlers[type]; // eslint-disable-line @typescript-eslint/no-dynamic-delete\n }\n\n // If there are no longer any custom handlers of any type on this element, cleanup everything.\n if (Object.keys(handlers).length === 0) {\n delete this.__sentry_instrumentation_handlers__;\n }\n }\n } catch {\n // Accessing dom properties is always fragile.\n // Also allows us to skip `addEventListeners` calls with no proper `this` context.\n }\n }\n\n return originalRemoveEventListener.call(this, type, listener, options);\n };\n },\n );\n });\n}\n\n/**\n * Check whether the event is similar to the last captured one. For example, two click events on the same button.\n */\nfunction isSimilarToLastCapturedEvent(event: Event): boolean {\n // If both events have different type, then user definitely performed two separate actions. e.g. click + keypress.\n if (event.type !== lastCapturedEventType) {\n return false;\n }\n\n try {\n // If both events have the same type, it's still possible that actions were performed on different targets.\n // e.g. 2 clicks on different buttons.\n if (!event.target || (event.target as SentryWrappedTarget)._sentryId !== lastCapturedEventTargetId) {\n return false;\n }\n } catch {\n // just accessing `target` property can throw an exception in some rare circumstances\n // see: https://github.com/getsentry/sentry-javascript/issues/838\n }\n\n // If both events have the same type _and_ same `target` (an element which triggered an event, _not necessarily_\n // to which an event listener was attached), we treat them as the same action, as we want to capture\n // only one breadcrumb. e.g. multiple clicks on the same button, or typing inside a user input box.\n return true;\n}\n\n/**\n * Decide whether an event should be captured.\n * @param event event to be captured\n */\nfunction shouldSkipDOMEvent(eventType: string, target: SentryWrappedTarget | null): boolean {\n // We are only interested in filtering `keypress` events for now.\n if (eventType !== 'keypress') {\n return false;\n }\n\n if (!target?.tagName) {\n return true;\n }\n\n // Only consider keypress events on actual input elements. This will disregard keypresses targeting body\n // e.g.tabbing through elements, hotkeys, etc.\n if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Wraps addEventListener to capture UI breadcrumbs\n */\nfunction makeDOMEventHandler(\n handler: (data: HandlerDataDom) => void,\n globalListener: boolean = false,\n): (event: Event) => void {\n return (event: Event & { _sentryCaptured?: true }): void => {\n // It's possible this handler might trigger multiple times for the same\n // event (e.g. event propagation through node ancestors).\n // Ignore if we've already captured that event.\n if (!event || event['_sentryCaptured']) {\n return;\n }\n\n const target = getEventTarget(event);\n\n // We always want to skip _some_ events.\n if (shouldSkipDOMEvent(event.type, target)) {\n return;\n }\n\n // Mark event as \"seen\"\n addNonEnumerableProperty(event, '_sentryCaptured', true);\n\n if (target && !target._sentryId) {\n // Add UUID to event target so we can identify if\n addNonEnumerableProperty(target, '_sentryId', uuid4());\n }\n\n const name = event.type === 'keypress' ? 'input' : event.type;\n\n // If there is no last captured event, it means that we can safely capture the new event and store it for future comparisons.\n // If there is a last captured event, see if the new event is different enough to treat it as a unique one.\n // If that's the case, emit the previous event and store locally the newly-captured DOM event.\n if (!isSimilarToLastCapturedEvent(event)) {\n const handlerData: HandlerDataDom = { event, name, global: globalListener };\n handler(handlerData);\n lastCapturedEventType = event.type;\n lastCapturedEventTargetId = target ? target._sentryId : undefined;\n }\n\n // Start a new debounce timer that will prevent us from capturing multiple events that should be grouped together.\n clearTimeout(debounceTimerID);\n debounceTimerID = WINDOW.setTimeout(() => {\n lastCapturedEventTargetId = undefined;\n lastCapturedEventType = undefined;\n }, DEBOUNCE_DURATION);\n };\n}\n\nfunction getEventTarget(event: Event): SentryWrappedTarget | null {\n try {\n return event.target as SentryWrappedTarget | null;\n } catch {\n // just accessing `target` property can throw an exception in some rare circumstances\n // see: https://github.com/getsentry/sentry-javascript/issues/838\n return null;\n }\n}\n"],"names":["addHandler","maybeInstrument","WINDOW","triggerHandlers","fill","addNonEnumerableProperty","uuid4"],"mappings":";;;;;AA2BA,MAAM,iBAAA,GAAoB,GAAA;AAE1B,IAAI,eAAA;AACJ,IAAI,qBAAA;AACJ,IAAI,yBAAA;AAQG,SAAS,uCAAuC,OAAA,EAA+C;AACpG,EAAA,MAAM,IAAA,GAAO,KAAA;AACb,EAAAA,eAAA,CAAW,MAAM,OAAO,CAAA;AACxB,EAAAC,oBAAA,CAAgB,MAAM,aAAa,CAAA;AACrC;AAGO,SAAS,aAAA,GAAsB;AACpC,EAAA,IAAI,CAACC,aAAO,QAAA,EAAU;AACpB,IAAA;AAAA,EACF;AAKA,EAAA,MAAM,iBAAA,GAAoBC,oBAAA,CAAgB,IAAA,CAAK,IAAA,EAAM,KAAK,CAAA;AAC1D,EAAA,MAAM,qBAAA,GAAwB,mBAAA,CAAoB,iBAAA,EAAmB,IAAI,CAAA;AACzE,EAAAD,YAAA,CAAO,QAAA,CAAS,gBAAA,CAAiB,OAAA,EAAS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AA8B,EAAE,KAAA,EAAO,IAAA,EAAM,QAAQ,cAAA,EAAe;AAC1E,MAAA,OAAA,CAAQ,WAAW,CAAA;AACnB,MAAA,qBAAA,GAAwB,KAAA,CAAM,IAAA;AAC9B,MAAA,yBAAA,GAA4B,MAAA,GAAS,OAAO,SAAA,GAAY,MAAA;AAAA,IAC1D;AAGA,IAAA,YAAA,CAAa,eAAe,CAAA;AAC5B,IAAA,eAAA,GAAkBJ,YAAA,CAAO,WAAW,MAAM;AACxC,MAAA,yBAAA,GAA4B,MAAA;AAC5B,MAAA,qBAAA,GAAwB,MAAA;AAAA,IAC1B,GAAG,iBAAiB,CAAA;AAAA,EACtB,CAAA;AACF;AAEA,SAAS,eAAe,KAAA,EAA0C;AAChE,EAAA,IAAI;AACF,IAAA,OAAO,KAAA,CAAM,MAAA;AAAA,EACf,CAAA,CAAA,MAAQ;AAGN,IAAA,OAAO,IAAA;AAAA,EACT;AACF;;;;;"}
|
|
1
|
+
{"version":3,"file":"dom.js","sources":["../../../src/instrumentation/dom.ts"],"sourcesContent":["import { addHandler, addNonEnumerableProperty, fill, maybeInstrument, triggerHandlers, uuid4 } from '@sentry/core';\nimport type { HandlerDataDom } from '../types';\nimport { WINDOW } from '../types';\n\ntype SentryWrappedTarget = HTMLElement & { _sentryId?: string };\n\ntype AddEventListener = (\n type: string,\n listener: EventListenerOrEventListenerObject,\n options?: boolean | AddEventListenerOptions,\n) => void;\ntype RemoveEventListener = (\n type: string,\n listener: EventListenerOrEventListenerObject,\n options?: boolean | EventListenerOptions,\n) => void;\n\ntype InstrumentedElement = Element & {\n __sentry_instrumentation_handlers__?: {\n [key in 'click' | 'keypress']?: {\n handler?: unknown;\n /** The number of custom listeners attached to this element */\n refCount: number;\n };\n };\n};\n\nconst DEBOUNCE_DURATION = 1000;\n\nlet debounceTimerID: number | undefined;\nlet lastCapturedEventType: string | undefined;\nlet lastCapturedEventTargetId: string | undefined;\n\n/**\n * Add an instrumentation handler for when a click or a keypress happens.\n *\n * Use at your own risk, this might break without changelog notice, only used internally.\n * @hidden\n */\nexport function addClickKeypressInstrumentationHandler(handler: (data: HandlerDataDom) => void): void {\n const type = 'dom';\n addHandler(type, handler);\n maybeInstrument(type, instrumentDOM);\n}\n\n/** Exported for tests only. */\nexport function instrumentDOM(): void {\n if (!WINDOW.document) {\n return;\n }\n\n // Make it so that any click or keypress that is unhandled / bubbled up all the way to the document triggers our dom\n // handlers. (Normally we have only one, which captures a breadcrumb for each click or keypress.) Do this before\n // we instrument `addEventListener` so that we don't end up attaching this handler twice.\n const triggerDOMHandler = triggerHandlers.bind(null, 'dom');\n const globalDOMEventHandler = makeDOMEventHandler(triggerDOMHandler, true);\n WINDOW.document.addEventListener('click', globalDOMEventHandler, false);\n WINDOW.document.addEventListener('keypress', globalDOMEventHandler, false);\n\n // After hooking into click and keypress events bubbled up to `document`, we also hook into user-handled\n // clicks & keypresses, by adding an event listener of our own to any element to which they add a listener. That\n // way, whenever one of their handlers is triggered, ours will be, too. (This is needed because their handler\n // could potentially prevent the event from bubbling up to our global listeners. This way, our handler are still\n // guaranteed to fire at least once.)\n ['EventTarget', 'Node'].forEach((target: string) => {\n const globalObject = WINDOW as unknown as Record<string, { prototype?: object }>;\n const proto = globalObject[target]?.prototype;\n\n // eslint-disable-next-line no-prototype-builtins\n if (!proto?.hasOwnProperty?.('addEventListener')) {\n return;\n }\n\n fill(proto, 'addEventListener', function (originalAddEventListener: AddEventListener): AddEventListener {\n return function (this: InstrumentedElement, type, listener, options): AddEventListener {\n if (type === 'click' || type == 'keypress') {\n try {\n const handlers = (this.__sentry_instrumentation_handlers__ =\n this.__sentry_instrumentation_handlers__ || {});\n const handlerForType = (handlers[type] = handlers[type] || { refCount: 0 });\n\n if (!handlerForType.handler) {\n const handler = makeDOMEventHandler(triggerDOMHandler);\n handlerForType.handler = handler;\n originalAddEventListener.call(this, type, handler, options);\n }\n\n handlerForType.refCount++;\n } catch {\n // Accessing dom properties is always fragile.\n // Also allows us to skip `addEventListeners` calls with no proper `this` context.\n }\n }\n\n return originalAddEventListener.call(this, type, listener, options);\n };\n });\n\n fill(\n proto,\n 'removeEventListener',\n function (originalRemoveEventListener: RemoveEventListener): RemoveEventListener {\n return function (this: InstrumentedElement, type, listener, options): () => void {\n if (type === 'click' || type == 'keypress') {\n try {\n const handlers = this.__sentry_instrumentation_handlers__ || {};\n const handlerForType = handlers[type];\n\n if (handlerForType) {\n handlerForType.refCount--;\n // If there are no longer any custom handlers of the current type on this element, we can remove ours, too.\n if (handlerForType.refCount <= 0) {\n originalRemoveEventListener.call(this, type, handlerForType.handler, options);\n handlerForType.handler = undefined;\n delete handlers[type]; // eslint-disable-line @typescript-eslint/no-dynamic-delete\n }\n\n // If there are no longer any custom handlers of any type on this element, cleanup everything.\n if (Object.keys(handlers).length === 0) {\n delete this.__sentry_instrumentation_handlers__;\n }\n }\n } catch {\n // Accessing dom properties is always fragile.\n // Also allows us to skip `addEventListeners` calls with no proper `this` context.\n }\n }\n\n return originalRemoveEventListener.call(this, type, listener, options);\n };\n },\n );\n });\n}\n\n/**\n * Check whether the event is similar to the last captured one. For example, two click events on the same button.\n */\nfunction isSimilarToLastCapturedEvent(event: Event): boolean {\n // If both events have different type, then user definitely performed two separate actions. e.g. click + keypress.\n if (event.type !== lastCapturedEventType) {\n return false;\n }\n\n try {\n // If both events have the same type, it's still possible that actions were performed on different targets.\n // e.g. 2 clicks on different buttons.\n if (!event.target || (event.target as SentryWrappedTarget)._sentryId !== lastCapturedEventTargetId) {\n return false;\n }\n } catch {\n // just accessing `target` property can throw an exception in some rare circumstances\n // see: https://github.com/getsentry/sentry-javascript/issues/838\n }\n\n // If both events have the same type _and_ same `target` (an element which triggered an event, _not necessarily_\n // to which an event listener was attached), we treat them as the same action, as we want to capture\n // only one breadcrumb. e.g. multiple clicks on the same button, or typing inside a user input box.\n return true;\n}\n\n/**\n * Decide whether an event should be captured.\n * @param event event to be captured\n */\nfunction shouldSkipDOMEvent(eventType: string, target: SentryWrappedTarget | null): boolean {\n // We are only interested in filtering `keypress` events for now.\n if (eventType !== 'keypress') {\n return false;\n }\n\n if (!target?.tagName) {\n return true;\n }\n\n // Only consider keypress events on actual input elements. This will disregard keypresses targeting body\n // e.g.tabbing through elements, hotkeys, etc.\n if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Wraps addEventListener to capture UI breadcrumbs\n */\nfunction makeDOMEventHandler(\n handler: (data: HandlerDataDom) => void,\n globalListener: boolean = false,\n): (event: Event) => void {\n return (event: Event & { _sentryCaptured?: true }): void => {\n // It's possible this handler might trigger multiple times for the same\n // event (e.g. event propagation through node ancestors).\n // Ignore if we've already captured that event.\n if (!event || event['_sentryCaptured']) {\n return;\n }\n\n const target = getEventTarget(event);\n\n // We always want to skip _some_ events.\n if (shouldSkipDOMEvent(event.type, target)) {\n return;\n }\n\n // Mark event as \"seen\"\n addNonEnumerableProperty(event, '_sentryCaptured', true);\n\n if (target && !target._sentryId) {\n // Add UUID to event target so we can identify if\n addNonEnumerableProperty(target, '_sentryId', uuid4());\n }\n\n const name = event.type === 'keypress' ? 'input' : event.type;\n\n // If there is no last captured event, it means that we can safely capture the new event and store it for future comparisons.\n // If there is a last captured event, see if the new event is different enough to treat it as a unique one.\n // If that's the case, emit the previous event and store locally the newly-captured DOM event.\n if (!isSimilarToLastCapturedEvent(event)) {\n const handlerData: HandlerDataDom = { event, name, global: globalListener };\n handler(handlerData);\n lastCapturedEventType = event.type;\n lastCapturedEventTargetId = target ? target._sentryId : undefined;\n }\n\n // Start a new debounce timer that will prevent us from capturing multiple events that should be grouped together.\n clearTimeout(debounceTimerID);\n debounceTimerID = WINDOW.setTimeout(() => {\n lastCapturedEventTargetId = undefined;\n lastCapturedEventType = undefined;\n }, DEBOUNCE_DURATION);\n };\n}\n\nfunction getEventTarget(event: Event): SentryWrappedTarget | null {\n try {\n return event.target as SentryWrappedTarget | null;\n } catch {\n // just accessing `target` property can throw an exception in some rare circumstances\n // see: https://github.com/getsentry/sentry-javascript/issues/838\n return null;\n }\n}\n"],"names":["addHandler","maybeInstrument","WINDOW","triggerHandlers","fill","addNonEnumerableProperty","uuid4"],"mappings":";;;;;AA2BA,MAAM,iBAAA,GAAoB,GAAA;AAE1B,IAAI,eAAA;AACJ,IAAI,qBAAA;AACJ,IAAI,yBAAA;AAQG,SAAS,uCAAuC,OAAA,EAA+C;AACpG,EAAA,MAAM,IAAA,GAAO,KAAA;AACb,EAAAA,eAAA,CAAW,MAAM,OAAO,CAAA;AACxB,EAAAC,oBAAA,CAAgB,MAAM,aAAa,CAAA;AACrC;AAGO,SAAS,aAAA,GAAsB;AACpC,EAAA,IAAI,CAACC,aAAO,QAAA,EAAU;AACpB,IAAA;AAAA,EACF;AAKA,EAAA,MAAM,iBAAA,GAAoBC,oBAAA,CAAgB,IAAA,CAAK,IAAA,EAAM,KAAK,CAAA;AAC1D,EAAA,MAAM,qBAAA,GAAwB,mBAAA,CAAoB,iBAAA,EAAmB,IAAI,CAAA;AACzE,EAAAD,YAAA,CAAO,QAAA,CAAS,gBAAA,CAAiB,OAAA,EAAS,qBAAA,EAAuB,KAAK,CAAA;AACtE,EAAAA,YAAA,CAAO,QAAA,CAAS,gBAAA,CAAiB,UAAA,EAAY,qBAAA,EAAuB,KAAK,CAAA;AAOzE,EAAA,CAAC,aAAA,EAAe,MAAM,CAAA,CAAE,OAAA,CAAQ,CAAC,MAAA,KAAmB;AAClD,IAAA,MAAM,YAAA,GAAeA,YAAA;AACrB,IAAA,MAAM,KAAA,GAAQ,YAAA,CAAa,MAAM,CAAA,EAAG,SAAA;AAGpC,IAAA,IAAI,CAAC,KAAA,EAAO,cAAA,GAAiB,kBAAkB,CAAA,EAAG;AAChD,MAAA;AAAA,IACF;AAEA,IAAAE,SAAA,CAAK,KAAA,EAAO,kBAAA,EAAoB,SAAU,wBAAA,EAA8D;AACtG,MAAA,OAAO,SAAqC,IAAA,EAAM,QAAA,EAAU,OAAA,EAA2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AA,MAAQ;AAGN,IAAA,OAAO,IAAA;AAAA,EACT;AACF;;;;;"}
|
|
@@ -4,6 +4,9 @@ const core = require('@sentry/core');
|
|
|
4
4
|
const types = require('../types.js');
|
|
5
5
|
|
|
6
6
|
let lastHref;
|
|
7
|
+
function supportsHistory() {
|
|
8
|
+
return "history" in types.WINDOW && !!types.WINDOW.history;
|
|
9
|
+
}
|
|
7
10
|
function addHistoryInstrumentationHandler(handler) {
|
|
8
11
|
const type = "history";
|
|
9
12
|
core.addHandler(type, handler);
|
|
@@ -20,7 +23,7 @@ function instrumentHistory() {
|
|
|
20
23
|
const handlerData = { from, to };
|
|
21
24
|
core.triggerHandlers("history", handlerData);
|
|
22
25
|
});
|
|
23
|
-
if (!
|
|
26
|
+
if (!supportsHistory()) {
|
|
24
27
|
return;
|
|
25
28
|
}
|
|
26
29
|
function historyReplacementFunction(originalHistoryFunction) {
|
|
@@ -53,4 +56,5 @@ function getAbsoluteUrl(urlOrPath) {
|
|
|
53
56
|
|
|
54
57
|
exports.addHistoryInstrumentationHandler = addHistoryInstrumentationHandler;
|
|
55
58
|
exports.instrumentHistory = instrumentHistory;
|
|
59
|
+
exports.supportsHistory = supportsHistory;
|
|
56
60
|
//# sourceMappingURL=history.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.js","sources":["../../../src/instrumentation/history.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"history.js","sources":["../../../src/instrumentation/history.ts"],"sourcesContent":["import { addHandler, fill, maybeInstrument, triggerHandlers } from '@sentry/core';\nimport type { HandlerDataHistory } from '../types';\nimport { WINDOW } from '../types';\n\nlet lastHref: string | undefined;\n\n/**\n * Tells whether current environment supports History API\n * {@link supportsHistory}.\n *\n * @returns Answer to the given question.\n */\nexport function supportsHistory(): boolean {\n return 'history' in WINDOW && !!WINDOW.history;\n}\n\n/**\n * Add an instrumentation handler for when a fetch request happens.\n * The handler function is called once when the request starts and once when it ends,\n * which can be identified by checking if it has an `endTimestamp`.\n *\n * Use at your own risk, this might break without changelog notice, only used internally.\n * @hidden\n */\nexport function addHistoryInstrumentationHandler(handler: (data: HandlerDataHistory) => void): void {\n const type = 'history';\n addHandler(type, handler);\n maybeInstrument(type, instrumentHistory);\n}\n\n/**\n * Exported just for testing\n */\nexport function instrumentHistory(): void {\n // The `popstate` event may also be triggered on `pushState`, but it may not always reliably be emitted by the browser\n // Which is why we also monkey-patch methods below, in addition to this\n WINDOW.addEventListener('popstate', () => {\n const to = WINDOW.location.href;\n // keep track of the current URL state, as we always receive only the updated state\n const from = lastHref;\n lastHref = to;\n\n if (from === to) {\n return;\n }\n\n const handlerData = { from, to } satisfies HandlerDataHistory;\n triggerHandlers('history', handlerData);\n });\n\n // Just guard against this not being available, in weird environments\n if (!supportsHistory()) {\n return;\n }\n\n function historyReplacementFunction(originalHistoryFunction: () => void): () => void {\n return function (this: History, ...args: unknown[]): void {\n const url = args.length > 2 ? args[2] : undefined;\n if (url) {\n const from = lastHref;\n\n // Ensure the URL is absolute\n // this can be either a path, then it is relative to the current origin\n // or a full URL of the current origin - other origins are not allowed\n // See: https://developer.mozilla.org/en-US/docs/Web/API/History/pushState#url\n // coerce to string (this is what pushState does)\n const to = getAbsoluteUrl(String(url));\n\n // keep track of the current URL state, as we always receive only the updated state\n lastHref = to;\n\n if (from === to) {\n return originalHistoryFunction.apply(this, args);\n }\n\n const handlerData = { from, to } satisfies HandlerDataHistory;\n triggerHandlers('history', handlerData);\n }\n return originalHistoryFunction.apply(this, args);\n };\n }\n\n fill(WINDOW.history, 'pushState', historyReplacementFunction);\n fill(WINDOW.history, 'replaceState', historyReplacementFunction);\n}\n\nfunction getAbsoluteUrl(urlOrPath: string): string {\n try {\n const url = new URL(urlOrPath, WINDOW.location.origin);\n return url.toString();\n } catch {\n // fallback, just do nothing\n return urlOrPath;\n }\n}\n"],"names":["WINDOW","addHandler","maybeInstrument","triggerHandlers","fill"],"mappings":";;;;;AAIA,IAAI,QAAA;AAQG,SAA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AAC/B,QAAAA,oBAAA,CAAgB,WAAW,WAAW,CAAA;AAAA,MACxC;AACA,MAAA,OAAO,uBAAA,CAAwB,KAAA,CAAM,IAAA,EAAM,IAAI,CAAA;AAAA,IACjD,CAAA;AAAA,EACF;AAEA,EAAAC,SAAA,CAAKJ,YAAA,CAAO,OAAA,EAAS,WAAA,EAAa,0BAA0B,CAAA;AAC5D,EAAAI,SAAA,CAAKJ,YAAA,CAAO,OAAA,EAAS,cAAA,EAAgB,0BAA0B,CAAA;AACjE;AAEA,SAAS,eAAe,SAAA,EAA2B;AACjD,EAAA,IAAI;AACF,IAAA,MAAM,MAAM,IAAI,GAAA,CAAI,SAAA,EAAWA,YAAA,CAAO,SAAS,MAAM,CAAA;AACrD,IAAA,OAAO,IAAI,QAAA,EAAS;AAAA,EACtB,CAAA,CAAA,MAAQ;AAEN,IAAA,OAAO,SAAA;AAAA,EACT;AACF;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xhr.js","sources":["../../../src/instrumentation/xhr.ts"],"sourcesContent":["import type { HandlerDataXhr, SentryWrappedXMLHttpRequest } from '@sentry/core';\nimport { addHandler, isString, maybeInstrument, timestampInSeconds, triggerHandlers } from '@sentry/core';\nimport { WINDOW } from '../types';\n\nexport const SENTRY_XHR_DATA_KEY = '__sentry_xhr_v3__';\n\ntype WindowWithXhr = Window & { XMLHttpRequest?: typeof XMLHttpRequest };\n\n/**\n * Add an instrumentation handler for when an XHR request happens.\n * The handler function is called once when the request starts and once when it ends,\n * which can be identified by checking if it has an `endTimestamp`.\n *\n * Use at your own risk, this might break without changelog notice, only used internally.\n * @hidden\n */\nexport function addXhrInstrumentationHandler(handler: (data: HandlerDataXhr) => void): void {\n const type = 'xhr';\n addHandler(type, handler);\n maybeInstrument(type, instrumentXHR);\n}\n\n/** Exported only for tests. */\nexport function instrumentXHR(): void {\n if (!(WINDOW as WindowWithXhr).XMLHttpRequest) {\n return;\n }\n\n const xhrproto = XMLHttpRequest.prototype;\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n xhrproto.open = new Proxy(xhrproto.open, {\n apply(\n originalOpen,\n xhrOpenThisArg: XMLHttpRequest & SentryWrappedXMLHttpRequest,\n xhrOpenArgArray:\n | [method: string, url: string | URL]\n | [method: string, url: string | URL, async: boolean, username?: string | null, password?: string | null],\n ) {\n // NOTE: If you are a Sentry user, and you are seeing this stack frame,\n // it means the error, that was caused by your XHR call did not\n // have a stack trace. If you are using HttpClient integration,\n // this is the expected behavior, as we are using this virtual error to capture\n // the location of your XHR call, and group your HttpClient events accordingly.\n const virtualError = new Error();\n\n const startTimestamp = timestampInSeconds() * 1000;\n\n // open() should always be called with two or more arguments\n // But to be on the safe side, we actually validate this and bail out if we don't have a method & url\n const method = isString(xhrOpenArgArray[0]) ? xhrOpenArgArray[0].toUpperCase() : undefined;\n const url = parseXhrUrlArg(xhrOpenArgArray[1]);\n\n if (!method || !url) {\n return originalOpen.apply(xhrOpenThisArg, xhrOpenArgArray);\n }\n\n xhrOpenThisArg[SENTRY_XHR_DATA_KEY] = {\n method,\n url,\n request_headers: {},\n };\n\n // if Sentry key appears in URL, don't capture it as a request\n if (method === 'POST' && url.match(/sentry_key/)) {\n xhrOpenThisArg.__sentry_own_request__ = true;\n }\n\n const onreadystatechangeHandler: () => void = () => {\n // For whatever reason, this is not the same instance here as from the outer method\n const xhrInfo = xhrOpenThisArg[SENTRY_XHR_DATA_KEY];\n\n if (!xhrInfo) {\n return;\n }\n\n if (xhrOpenThisArg.readyState === 4) {\n try {\n // touching statusCode in some platforms throws\n // an exception\n xhrInfo.status_code = xhrOpenThisArg.status;\n } catch {\n /* do nothing */\n }\n\n const handlerData: HandlerDataXhr = {\n endTimestamp: timestampInSeconds() * 1000,\n startTimestamp,\n xhr: xhrOpenThisArg,\n virtualError,\n };\n triggerHandlers('xhr', handlerData);\n\n // In the `addEventListener` branch below, this handler is the only\n // `readystatechange` listener we add, so detach it once the request is\n // done to avoid pinning the XMLHttpRequest and its captured\n // `virtualError` per HTTP call on long-lived pages. In the\n // `onreadystatechange` proxy branch the handler isn't registered via\n // `addEventListener`, so this is a harmless no-op there.\n xhrOpenThisArg.removeEventListener('readystatechange', onreadystatechangeHandler);\n }\n };\n\n if ('onreadystatechange' in xhrOpenThisArg && typeof xhrOpenThisArg.onreadystatechange === 'function') {\n xhrOpenThisArg.onreadystatechange = new Proxy(xhrOpenThisArg.onreadystatechange, {\n apply(originalOnreadystatechange, onreadystatechangeThisArg, onreadystatechangeArgArray: unknown[]) {\n onreadystatechangeHandler();\n return originalOnreadystatechange.apply(onreadystatechangeThisArg, onreadystatechangeArgArray);\n },\n });\n } else {\n xhrOpenThisArg.addEventListener('readystatechange', onreadystatechangeHandler);\n }\n\n // Intercepting `setRequestHeader` to access the request headers of XHR instance.\n // This will only work for user/library defined headers, not for the default/browser-assigned headers.\n // Request cookies are also unavailable for XHR, as `Cookie` header can't be defined by `setRequestHeader`.\n xhrOpenThisArg.setRequestHeader = new Proxy(xhrOpenThisArg.setRequestHeader, {\n apply(\n originalSetRequestHeader,\n setRequestHeaderThisArg: SentryWrappedXMLHttpRequest,\n setRequestHeaderArgArray: unknown[],\n ) {\n const [header, value] = setRequestHeaderArgArray;\n\n const xhrInfo = setRequestHeaderThisArg[SENTRY_XHR_DATA_KEY];\n\n if (xhrInfo && isString(header) && isString(value)) {\n xhrInfo.request_headers[header.toLowerCase()] = value;\n }\n\n return originalSetRequestHeader.apply(setRequestHeaderThisArg, setRequestHeaderArgArray);\n },\n });\n\n return originalOpen.apply(xhrOpenThisArg, xhrOpenArgArray);\n },\n });\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n xhrproto.send = new Proxy(xhrproto.send, {\n apply(originalSend, sendThisArg: XMLHttpRequest & SentryWrappedXMLHttpRequest, sendArgArray: unknown[]) {\n const sentryXhrData = sendThisArg[SENTRY_XHR_DATA_KEY];\n\n if (!sentryXhrData) {\n return originalSend.apply(sendThisArg, sendArgArray);\n }\n\n if (sendArgArray[0] !== undefined) {\n sentryXhrData.body = sendArgArray[0];\n }\n\n const handlerData: HandlerDataXhr = {\n startTimestamp: timestampInSeconds() * 1000,\n xhr: sendThisArg,\n };\n triggerHandlers('xhr', handlerData);\n\n return originalSend.apply(sendThisArg, sendArgArray);\n },\n });\n}\n\n/**\n * Parses the URL argument of a XHR method to a string.\n *\n * See: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/open#url\n * url: A string or any other object with a stringifier — including a URL object — that provides the URL of the resource to send the request to.\n *\n * @param url - The URL argument of an XHR method\n * @returns The parsed URL string or undefined if the URL is invalid\n */\nfunction parseXhrUrlArg(url: unknown): string | undefined {\n if (isString(url)) {\n return url;\n }\n\n try {\n // If the passed in argument is not a string, it should have a `toString` method as a stringifier.\n // If that fails, we just return undefined (like in IE11 where URL is not available)\n return (url as URL).toString();\n } catch {} // eslint-disable-line no-empty\n\n return undefined;\n}\n"],"names":["addHandler","maybeInstrument","WINDOW","timestampInSeconds","isString","triggerHandlers"],"mappings":";;;;;AAIO,MAAM,mBAAA,GAAsB;AAY5B,SAAS,6BAA6B,OAAA,EAA+C;AAC1F,EAAA,MAAM,IAAA,GAAO,KAAA;AACb,EAAAA,eAAA,CAAW,MAAM,OAAO,CAAA;AACxB,EAAAC,oBAAA,CAAgB,MAAM,aAAa,CAAA;AACrC;AAGO,SAAS,aAAA,GAAsB;AACpC,EAAA,IAAI,CAAEC,aAAyB,cAAA,EAAgB;AAC7C,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,WAAW,cAAA,CAAe,SAAA;AAGhC,EAAA,QAAA,CAAS,IAAA,GAAO,IAAI,KAAA,CAAM,QAAA,CAAS,IAAA,EAAM;AAAA,IACvC,KAAA,CACE,YAAA,EACA,cAAA,EACA,eAAA,EAGA;AAMA,MAAA,MAAM,YAAA,GAAe,IAAI,KAAA,EAAM;AAE/B,MAAA,MAAM,cAAA,GAAiBC,yBAAmB,GAAI,GAAA;AAI9C,MAAA,MAAM,MAAA,GAASC,a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AAe;AAClB,QAAA,OAAO,YAAA,CAAa,KAAA,CAAM,WAAA,EAAa,YAAY,CAAA;AAAA,MACrD;AAEA,MAAA,IAAI,YAAA,CAAa,CAAC,CAAA,KAAM,MAAA,EAAW;AACjC,QAAA,aAAA,CAAc,IAAA,GAAO,aAAa,CAAC,CAAA;AAAA,MACrC;AAEA,MAAA,MAAM,WAAA,GAA8B;AAAA,QAClC,cAAA,EAAgBD,yBAAmB,GAAI,GAAA;AAAA,QACvC,GAAA,EAAK;AAAA,OACP;AACA,MAAAE,oBAAA,CAAgB,OAAO,WAAW,CAAA;AAElC,MAAA,OAAO,YAAA,CAAa,KAAA,CAAM,WAAA,EAAa,YAAY,CAAA;AAAA,IACrD;AAAA,GACD,CAAA;AACH;AAWA,SAAS,eAAe,GAAA,EAAkC;AACxD,EAAA,IAAID,aAAA,CAAS,GAAG,CAAA,EAAG;AACjB,IAAA,OAAO,GAAA;AAAA,EACT;AAEA,EAAA,IAAI;AAGF,IAAA,OAAQ,IAAY,QAAA,EAAS;AAAA,EAC/B,CAAA,CAAA,MAAQ;AAAA,EAAC;AAET,EAAA,OAAO,MAAA;AACT;;;;;;"}
|
|
1
|
+
{"version":3,"file":"xhr.js","sources":["../../../src/instrumentation/xhr.ts"],"sourcesContent":["import { addHandler, isString, maybeInstrument, timestampInSeconds, triggerHandlers } from '@sentry/core';\nimport type { HandlerDataXhr, SentryWrappedXMLHttpRequest } from '../types';\nimport { WINDOW } from '../types';\n\nexport const SENTRY_XHR_DATA_KEY = '__sentry_xhr_v3__';\n\ntype WindowWithXhr = Window & { XMLHttpRequest?: typeof XMLHttpRequest };\n\n/**\n * Add an instrumentation handler for when an XHR request happens.\n * The handler function is called once when the request starts and once when it ends,\n * which can be identified by checking if it has an `endTimestamp`.\n *\n * Use at your own risk, this might break without changelog notice, only used internally.\n * @hidden\n */\nexport function addXhrInstrumentationHandler(handler: (data: HandlerDataXhr) => void): void {\n const type = 'xhr';\n addHandler(type, handler);\n maybeInstrument(type, instrumentXHR);\n}\n\n/** Exported only for tests. */\nexport function instrumentXHR(): void {\n if (!(WINDOW as WindowWithXhr).XMLHttpRequest) {\n return;\n }\n\n const xhrproto = XMLHttpRequest.prototype;\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n xhrproto.open = new Proxy(xhrproto.open, {\n apply(\n originalOpen,\n xhrOpenThisArg: XMLHttpRequest & SentryWrappedXMLHttpRequest,\n xhrOpenArgArray:\n | [method: string, url: string | URL]\n | [method: string, url: string | URL, async: boolean, username?: string | null, password?: string | null],\n ) {\n // NOTE: If you are a Sentry user, and you are seeing this stack frame,\n // it means the error, that was caused by your XHR call did not\n // have a stack trace. If you are using HttpClient integration,\n // this is the expected behavior, as we are using this virtual error to capture\n // the location of your XHR call, and group your HttpClient events accordingly.\n const virtualError = new Error();\n\n const startTimestamp = timestampInSeconds() * 1000;\n\n // open() should always be called with two or more arguments\n // But to be on the safe side, we actually validate this and bail out if we don't have a method & url\n const method = isString(xhrOpenArgArray[0]) ? xhrOpenArgArray[0].toUpperCase() : undefined;\n const url = parseXhrUrlArg(xhrOpenArgArray[1]);\n\n if (!method || !url) {\n return originalOpen.apply(xhrOpenThisArg, xhrOpenArgArray);\n }\n\n xhrOpenThisArg[SENTRY_XHR_DATA_KEY] = {\n method,\n url,\n request_headers: {},\n };\n\n // if Sentry key appears in URL, don't capture it as a request\n if (method === 'POST' && url.match(/sentry_key/)) {\n xhrOpenThisArg.__sentry_own_request__ = true;\n }\n\n const onreadystatechangeHandler: () => void = () => {\n // For whatever reason, this is not the same instance here as from the outer method\n const xhrInfo = xhrOpenThisArg[SENTRY_XHR_DATA_KEY];\n\n if (!xhrInfo) {\n return;\n }\n\n if (xhrOpenThisArg.readyState === 4) {\n try {\n // touching statusCode in some platforms throws\n // an exception\n xhrInfo.status_code = xhrOpenThisArg.status;\n } catch {\n /* do nothing */\n }\n\n const handlerData: HandlerDataXhr = {\n endTimestamp: timestampInSeconds() * 1000,\n startTimestamp,\n xhr: xhrOpenThisArg,\n virtualError,\n };\n triggerHandlers('xhr', handlerData);\n\n // In the `addEventListener` branch below, this handler is the only\n // `readystatechange` listener we add, so detach it once the request is\n // done to avoid pinning the XMLHttpRequest and its captured\n // `virtualError` per HTTP call on long-lived pages. In the\n // `onreadystatechange` proxy branch the handler isn't registered via\n // `addEventListener`, so this is a harmless no-op there.\n xhrOpenThisArg.removeEventListener('readystatechange', onreadystatechangeHandler);\n }\n };\n\n if ('onreadystatechange' in xhrOpenThisArg && typeof xhrOpenThisArg.onreadystatechange === 'function') {\n xhrOpenThisArg.onreadystatechange = new Proxy(xhrOpenThisArg.onreadystatechange, {\n apply(originalOnreadystatechange, onreadystatechangeThisArg, onreadystatechangeArgArray: unknown[]) {\n onreadystatechangeHandler();\n return originalOnreadystatechange.apply(onreadystatechangeThisArg, onreadystatechangeArgArray);\n },\n });\n } else {\n xhrOpenThisArg.addEventListener('readystatechange', onreadystatechangeHandler);\n }\n\n // Intercepting `setRequestHeader` to access the request headers of XHR instance.\n // This will only work for user/library defined headers, not for the default/browser-assigned headers.\n // Request cookies are also unavailable for XHR, as `Cookie` header can't be defined by `setRequestHeader`.\n xhrOpenThisArg.setRequestHeader = new Proxy(xhrOpenThisArg.setRequestHeader, {\n apply(\n originalSetRequestHeader,\n setRequestHeaderThisArg: SentryWrappedXMLHttpRequest,\n setRequestHeaderArgArray: unknown[],\n ) {\n const [header, value] = setRequestHeaderArgArray;\n\n const xhrInfo = setRequestHeaderThisArg[SENTRY_XHR_DATA_KEY];\n\n if (xhrInfo && isString(header) && isString(value)) {\n xhrInfo.request_headers[header.toLowerCase()] = value;\n }\n\n return originalSetRequestHeader.apply(setRequestHeaderThisArg, setRequestHeaderArgArray);\n },\n });\n\n return originalOpen.apply(xhrOpenThisArg, xhrOpenArgArray);\n },\n });\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n xhrproto.send = new Proxy(xhrproto.send, {\n apply(originalSend, sendThisArg: XMLHttpRequest & SentryWrappedXMLHttpRequest, sendArgArray: unknown[]) {\n const sentryXhrData = sendThisArg[SENTRY_XHR_DATA_KEY];\n\n if (!sentryXhrData) {\n return originalSend.apply(sendThisArg, sendArgArray);\n }\n\n if (sendArgArray[0] !== undefined) {\n sentryXhrData.body = sendArgArray[0];\n }\n\n const handlerData: HandlerDataXhr = {\n startTimestamp: timestampInSeconds() * 1000,\n xhr: sendThisArg,\n };\n triggerHandlers('xhr', handlerData);\n\n return originalSend.apply(sendThisArg, sendArgArray);\n },\n });\n}\n\n/**\n * Parses the URL argument of a XHR method to a string.\n *\n * See: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/open#url\n * url: A string or any other object with a stringifier — including a URL object — that provides the URL of the resource to send the request to.\n *\n * @param url - The URL argument of an XHR method\n * @returns The parsed URL string or undefined if the URL is invalid\n */\nfunction parseXhrUrlArg(url: unknown): string | undefined {\n if (isString(url)) {\n return url;\n }\n\n try {\n // If the passed in argument is not a string, it should have a `toString` method as a stringifier.\n // If that fails, we just return undefined (like in IE11 where URL is not available)\n return (url as URL).toString();\n } catch {} // eslint-disable-line no-empty\n\n return undefined;\n}\n"],"names":["addHandler","maybeInstrument","WINDOW","timestampInSeconds","isString","triggerHandlers"],"mappings":";;;;;AAIO,MAAM,mBAAA,GAAsB;AAY5B,SAAS,6BAA6B,OAAA,EAA+C;AAC1F,EAAA,MAAM,IAAA,GAAO,KAAA;AACb,EAAAA,eAAA,CAAW,MAAM,OAAO,CAAA;AACxB,EAAAC,oBAAA,CAAgB,MAAM,aAAa,CAAA;AACrC;AAGO,SAAS,aAAA,GAAsB;AACpC,EAAA,IAAI,CAAEC,aAAyB,cAAA,EAAgB;AAC7C,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,WAAW,cAAA,CAAe,SAAA;AAGhC,EAAA,QAAA,CAAS,IAAA,GAAO,IAAI,KAAA,CAAM,QAAA,CAAS,IAAA,EAAM;AAAA,IACvC,KAAA,CACE,YAAA,EACA,cAAA,EACA,eAAA,EAGA;AAMA,MAAA,M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YAAA,EAAc,WAAA,EAA2D,YAAA,EAAyB;AACtG,MAAA,MAAM,aAAA,GAAgB,YAAY,mBAAmB,CAAA;AAErD,MAAA,IAAI,CAAC,aAAA,EAAe;AAClB,QAAA,OAAO,YAAA,CAAa,KAAA,CAAM,WAAA,EAAa,YAAY,CAAA;AAAA,MACrD;AAEA,MAAA,IAAI,YAAA,CAAa,CAAC,CAAA,KAAM,MAAA,EAAW;AACjC,QAAA,aAAA,CAAc,IAAA,GAAO,aAAa,CAAC,CAAA;AAAA,MACrC;AAEA,MAAA,MAAM,WAAA,GAA8B;AAAA,QAClC,cAAA,EAAgBD,yBAAmB,GAAI,GAAA;AAAA,QACvC,GAAA,EAAK;AAAA,OACP;AACA,MAAAE,oBAAA,CAAgB,OAAO,WAAW,CAAA;AAElC,MAAA,OAAO,YAAA,CAAa,KAAA,CAAM,WAAA,EAAa,YAAY,CAAA;AAAA,IACrD;AAAA,GACD,CAAA;AACH;AAWA,SAAS,eAAe,GAAA,EAAkC;AACxD,EAAA,IAAID,aAAA,CAAS,GAAG,CAAA,EAAG;AACjB,IAAA,OAAO,GAAA;AAAA,EACT;AAEA,EAAA,IAAI;AAGF,IAAA,OAAQ,IAAY,QAAA,EAAS;AAAA,EAC/B,CAAA,CAAA,MAAQ;AAAA,EAAC;AAET,EAAA,OAAO,MAAA;AACT;;;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const types = require('./types.js');
|
|
4
|
+
|
|
5
|
+
const BOT_USER_AGENT_RE = /Googlebot|Google-InspectionTool|Storebot-Google|Bingbot|Slurp|DuckDuckBot|Baiduspider|YandexBot|Facebot|facebookexternalhit|LinkedInBot|Twitterbot|Applebot/i;
|
|
6
|
+
function isBotUserAgent() {
|
|
7
|
+
const nav = types.WINDOW.navigator;
|
|
8
|
+
if (!nav?.userAgent) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
return BOT_USER_AGENT_RE.test(nav.userAgent);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.isBotUserAgent = isBotUserAgent;
|
|
15
|
+
//# sourceMappingURL=isBotUserAgent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isBotUserAgent.js","sources":["../../src/isBotUserAgent.ts"],"sourcesContent":["import { WINDOW } from './types';\n\n/**\n * We don't want to start a bunch of idle timers and PerformanceObservers\n * for web crawlers, as they may prevent the page from being seen as \"idle\"\n * by the crawler's rendering engine (e.g. Googlebot's headless Chromium).\n */\nconst BOT_USER_AGENT_RE =\n /Googlebot|Google-InspectionTool|Storebot-Google|Bingbot|Slurp|DuckDuckBot|Baiduspider|YandexBot|Facebot|facebookexternalhit|LinkedInBot|Twitterbot|Applebot/i;\n\n/**\n * Whether the current user agent looks like a web crawler.\n */\nexport function isBotUserAgent(): boolean {\n const nav = WINDOW.navigator as Navigator | undefined;\n if (!nav?.userAgent) {\n return false;\n }\n return BOT_USER_AGENT_RE.test(nav.userAgent);\n}\n"],"names":["WINDOW"],"mappings":";;;;AAOA,MAAM,iBAAA,GACJ,8JAAA;AAKK,SAAS,cAAA,GAA0B;AACxC,EAAA,MAAM,MAAMA,YAAA,CAAO,SAAA;AACnB,EAAA,IAAI,CAAC,KAAK,SAAA,EAAW;AACnB,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,iBAAA,CAAkB,IAAA,CAAK,GAAA,CAAI,SAAS,CAAA;AAC7C;;;;"}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3
3
|
const core = require('@sentry/core');
|
|
4
4
|
const attributes = require('@sentry/conventions/attributes');
|
|
5
5
|
const op = require('@sentry/conventions/op');
|
|
6
|
-
const htmlTreeAsString = require('../htmlTreeAsString.js');
|
|
7
6
|
const performanceObserver = require('../instrumentation/performanceObserver.js');
|
|
8
7
|
const types = require('../types.js');
|
|
9
8
|
const resourceTiming = require('./resourceTiming.js');
|
|
@@ -26,7 +25,7 @@ function startTrackingLongTasks() {
|
|
|
26
25
|
}
|
|
27
26
|
utils.startAndEndSpan(parent, startTime, startTime + duration, {
|
|
28
27
|
name: "Main UI thread blocked",
|
|
29
|
-
op:
|
|
28
|
+
op: op.UI_LONG_TASK,
|
|
30
29
|
attributes: {
|
|
31
30
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.ui.browser.metrics"
|
|
32
31
|
}
|
|
@@ -61,50 +60,23 @@ function startTrackingLongAnimationFrames() {
|
|
|
61
60
|
attributes$1["browser.script.invoker"] = invoker;
|
|
62
61
|
attributes$1["browser.script.invoker_type"] = invokerType;
|
|
63
62
|
if (sourceURL) {
|
|
64
|
-
attributes$1[
|
|
63
|
+
attributes$1[attributes.CODE_FILE_PATH] = sourceURL;
|
|
65
64
|
}
|
|
66
65
|
if (sourceFunctionName) {
|
|
67
|
-
attributes$1[
|
|
66
|
+
attributes$1[attributes.CODE_FUNCTION_NAME] = sourceFunctionName;
|
|
68
67
|
}
|
|
69
68
|
if (sourceCharPosition !== -1) {
|
|
70
69
|
attributes$1["browser.script.source_char_position"] = sourceCharPosition;
|
|
71
70
|
}
|
|
72
71
|
utils.startAndEndSpan(parent, startTime, startTime + duration, {
|
|
73
72
|
name: "Main UI thread blocked",
|
|
74
|
-
op:
|
|
73
|
+
op: op.UI_LONG_ANIMATION_FRAME,
|
|
75
74
|
attributes: attributes$1
|
|
76
75
|
});
|
|
77
76
|
}
|
|
78
77
|
});
|
|
79
78
|
observer.observe({ type: "long-animation-frame", buffered: true });
|
|
80
79
|
}
|
|
81
|
-
function startTrackingInteractions() {
|
|
82
|
-
performanceObserver.addPerformanceInstrumentationHandler("event", ({ entries }) => {
|
|
83
|
-
const parent = core.getActiveSpan();
|
|
84
|
-
if (!parent) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
for (const entry of entries) {
|
|
88
|
-
if (entry.name === "click") {
|
|
89
|
-
const startTime = utils.msToSec(core.browserPerformanceTimeOrigin() + entry.startTime);
|
|
90
|
-
const duration = utils.msToSec(entry.duration);
|
|
91
|
-
const spanOptions = {
|
|
92
|
-
name: htmlTreeAsString.htmlTreeAsString(entry.target),
|
|
93
|
-
op: `ui.interaction.${entry.name}`,
|
|
94
|
-
startTime,
|
|
95
|
-
attributes: {
|
|
96
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.ui.browser.metrics"
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
const componentName = core.getComponentName(entry.target);
|
|
100
|
-
if (componentName) {
|
|
101
|
-
spanOptions.attributes["ui.component_name"] = componentName;
|
|
102
|
-
}
|
|
103
|
-
utils.startAndEndSpan(parent, startTime, startTime + duration, spanOptions);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
80
|
function addPerformanceEntries(span, options) {
|
|
109
81
|
const performance = utils.getBrowserPerformanceAPI();
|
|
110
82
|
const origin = core.browserPerformanceTimeOrigin();
|
|
@@ -144,7 +116,8 @@ function addPerformanceEntries(span, options) {
|
|
|
144
116
|
startTime,
|
|
145
117
|
duration,
|
|
146
118
|
timeOrigin,
|
|
147
|
-
ignoreResourceSpans
|
|
119
|
+
ignoreResourceSpans,
|
|
120
|
+
spanStreamingEnabled
|
|
148
121
|
);
|
|
149
122
|
break;
|
|
150
123
|
}
|
|
@@ -158,7 +131,7 @@ function _addPaintSpan(span, entry, startTime, duration, timeOrigin) {
|
|
|
158
131
|
utils.startAndEndSpan(span, startTimestamp, startTimestamp + duration, {
|
|
159
132
|
name: entry.name,
|
|
160
133
|
attributes: {
|
|
161
|
-
[attributes.SENTRY_OP]: op.
|
|
134
|
+
[attributes.SENTRY_OP]: op.BROWSER_PAINT,
|
|
162
135
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.resource.browser.metrics"
|
|
163
136
|
}
|
|
164
137
|
});
|
|
@@ -220,7 +193,7 @@ function _addRequest(span, entry, timeOrigin) {
|
|
|
220
193
|
});
|
|
221
194
|
}
|
|
222
195
|
}
|
|
223
|
-
function _addResourceSpans(span, entry, resourceUrl, startTime, duration, timeOrigin, ignoredResourceSpanOps) {
|
|
196
|
+
function _addResourceSpans(span, entry, resourceUrl, startTime, duration, timeOrigin, ignoredResourceSpanOps, spanStreamingEnabled) {
|
|
224
197
|
if (entry.initiatorType === "xmlhttprequest" || entry.initiatorType === "fetch") {
|
|
225
198
|
return;
|
|
226
199
|
}
|
|
@@ -233,19 +206,24 @@ function _addResourceSpans(span, entry, resourceUrl, startTime, duration, timeOr
|
|
|
233
206
|
};
|
|
234
207
|
const parsedUrl = core.parseUrl(resourceUrl);
|
|
235
208
|
if (parsedUrl.protocol) {
|
|
236
|
-
attributes$1[
|
|
209
|
+
attributes$1[attributes.URL_SCHEME] = parsedUrl.protocol.split(":").pop();
|
|
210
|
+
}
|
|
211
|
+
const host = parsedUrl.host?.replace(/^.*@/, "");
|
|
212
|
+
if (host) {
|
|
213
|
+
attributes$1[attributes.SERVER_ADDRESS] = host;
|
|
237
214
|
}
|
|
238
|
-
|
|
239
|
-
|
|
215
|
+
const domain = host?.replace(/:\d+$/, "");
|
|
216
|
+
if (domain) {
|
|
217
|
+
attributes$1[attributes.URL_DOMAIN] = domain;
|
|
240
218
|
}
|
|
241
|
-
attributes$1[
|
|
219
|
+
attributes$1[attributes.HTTP_REQUEST_SAME_ORIGIN] = resourceUrl.includes(types.WINDOW.location.origin);
|
|
242
220
|
attributes$1[attributes.URL_FULL] = core.filterCollectedUrl(resourceUrl);
|
|
243
221
|
_setResourceRequestAttributes(entry, attributes$1, [
|
|
244
222
|
// https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStatus
|
|
245
|
-
["responseStatus",
|
|
246
|
-
["transferSize",
|
|
247
|
-
["encodedBodySize",
|
|
248
|
-
["decodedBodySize", "http.
|
|
223
|
+
["responseStatus", attributes.HTTP_RESPONSE_STATUS_CODE],
|
|
224
|
+
["transferSize", attributes.HTTP_RESPONSE_SIZE],
|
|
225
|
+
["encodedBodySize", attributes.HTTP_RESPONSE_BODY_SIZE],
|
|
226
|
+
["decodedBodySize", "http.response.body.decoded_size"],
|
|
249
227
|
// https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/renderBlockingStatus
|
|
250
228
|
["renderBlockingStatus", "resource.render_blocking_status"],
|
|
251
229
|
// https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/deliveryType
|
|
@@ -255,7 +233,8 @@ function _addResourceSpans(span, entry, resourceUrl, startTime, duration, timeOr
|
|
|
255
233
|
const startTimestamp = timeOrigin + startTime;
|
|
256
234
|
const endTimestamp = startTimestamp + duration;
|
|
257
235
|
utils.startAndEndSpan(span, startTimestamp, endTimestamp, {
|
|
258
|
-
|
|
236
|
+
// With span streaming, span names have to be low cardinality, so we can't fall back to the URL.
|
|
237
|
+
name: spanStreamingEnabled ? domain || core.RESOURCE_SPAN_NAME_FALLBACK : resourceUrl.replace(types.WINDOW.location.origin, ""),
|
|
259
238
|
op,
|
|
260
239
|
attributes: attributesWithResourceTiming
|
|
261
240
|
});
|
|
@@ -269,16 +248,16 @@ function _trackNavigator(span, spanStreamingEnabled) {
|
|
|
269
248
|
if (connection) {
|
|
270
249
|
if (connection.effectiveType) {
|
|
271
250
|
span.setAttribute(
|
|
272
|
-
spanStreamingEnabled ?
|
|
251
|
+
spanStreamingEnabled ? attributes.NETWORK_CONNECTION_EFFECTIVE_TYPE : "effectiveConnectionType",
|
|
273
252
|
connection.effectiveType
|
|
274
253
|
);
|
|
275
254
|
}
|
|
276
255
|
if (connection.type) {
|
|
277
|
-
span.setAttribute(spanStreamingEnabled ?
|
|
256
|
+
span.setAttribute(spanStreamingEnabled ? attributes.NETWORK_CONNECTION_TYPE : "connectionType", connection.type);
|
|
278
257
|
}
|
|
279
258
|
if (utils.isMeasurementValue(connection.rtt)) {
|
|
280
259
|
if (spanStreamingEnabled) {
|
|
281
|
-
span.setAttribute(
|
|
260
|
+
span.setAttribute(attributes.NETWORK_CONNECTION_RTT, connection.rtt);
|
|
282
261
|
} else if (core.spanToJSON(span).attributes[attributes.SENTRY_OP] === "pageload") {
|
|
283
262
|
core.setMeasurement("connection.rtt", connection.rtt, "millisecond");
|
|
284
263
|
}
|
|
@@ -312,7 +291,6 @@ exports._addNavigationSpans = _addNavigationSpans;
|
|
|
312
291
|
exports._addResourceSpans = _addResourceSpans;
|
|
313
292
|
exports._setResourceRequestAttributes = _setResourceRequestAttributes;
|
|
314
293
|
exports.addPerformanceEntries = addPerformanceEntries;
|
|
315
|
-
exports.startTrackingInteractions = startTrackingInteractions;
|
|
316
294
|
exports.startTrackingLongAnimationFrames = startTrackingLongAnimationFrames;
|
|
317
295
|
exports.startTrackingLongTasks = startTrackingLongTasks;
|
|
318
296
|
//# sourceMappingURL=entries.js.map
|