@sentry/browser-utils 11.0.0-beta.2 → 11.0.0-rc.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/build/cjs/index.js +5 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/instrumentation/performanceObserver.js +29 -16
- package/build/cjs/instrumentation/performanceObserver.js.map +1 -1
- package/build/cjs/instrumentation/xhr.js +2 -1
- package/build/cjs/instrumentation/xhr.js.map +1 -1
- package/build/cjs/performance/entries.js.map +1 -1
- package/build/cjs/web-vitals/emitSpan.js +89 -0
- package/build/cjs/web-vitals/emitSpan.js.map +1 -0
- package/build/cjs/web-vitals/inp.js +8 -1
- package/build/cjs/web-vitals/inp.js.map +1 -1
- package/build/cjs/web-vitals/softNavs.js +84 -0
- package/build/cjs/web-vitals/softNavs.js.map +1 -0
- package/build/cjs/web-vitals/spans.js +118 -104
- package/build/cjs/web-vitals/spans.js.map +1 -1
- package/build/esm/index.js +2 -1
- package/build/esm/index.js.map +1 -1
- package/build/esm/instrumentation/performanceObserver.js +28 -17
- package/build/esm/instrumentation/performanceObserver.js.map +1 -1
- package/build/esm/instrumentation/xhr.js +2 -1
- package/build/esm/instrumentation/xhr.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/performance/entries.js.map +1 -1
- package/build/esm/web-vitals/emitSpan.js +87 -0
- package/build/esm/web-vitals/emitSpan.js.map +1 -0
- package/build/esm/web-vitals/inp.js +8 -1
- package/build/esm/web-vitals/inp.js.map +1 -1
- package/build/esm/web-vitals/softNavs.js +80 -0
- package/build/esm/web-vitals/softNavs.js.map +1 -0
- package/build/esm/web-vitals/spans.js +118 -103
- package/build/esm/web-vitals/spans.js.map +1 -1
- package/build/types/index.d.ts +2 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/instrumentation/performanceObserver.d.ts +65 -2
- package/build/types/instrumentation/performanceObserver.d.ts.map +1 -1
- package/build/types/instrumentation/xhr.d.ts.map +1 -1
- package/build/types/web-vitals/emitSpan.d.ts +49 -0
- package/build/types/web-vitals/emitSpan.d.ts.map +1 -0
- package/build/types/web-vitals/inp.d.ts.map +1 -1
- package/build/types/web-vitals/softNavs.d.ts +39 -0
- package/build/types/web-vitals/softNavs.d.ts.map +1 -0
- package/build/types/web-vitals/spans.d.ts +10 -47
- package/build/types/web-vitals/spans.d.ts.map +1 -1
- package/package.json +4 -4
package/build/cjs/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
3
|
const performanceObserver = require('./instrumentation/performanceObserver.js');
|
|
4
|
+
const softNavs = require('./web-vitals/softNavs.js');
|
|
4
5
|
const entries = require('./performance/entries.js');
|
|
5
6
|
const tracking = require('./web-vitals/tracking.js');
|
|
6
7
|
const elementTiming = require('./performance/elementTiming.js');
|
|
@@ -31,6 +32,10 @@ exports.addInpInstrumentationHandler = performanceObserver.addInpInstrumentation
|
|
|
31
32
|
exports.addLcpInstrumentationHandler = performanceObserver.addLcpInstrumentationHandler;
|
|
32
33
|
exports.addPerformanceInstrumentationHandler = performanceObserver.addPerformanceInstrumentationHandler;
|
|
33
34
|
exports.addTtfbInstrumentationHandler = performanceObserver.addTtfbInstrumentationHandler;
|
|
35
|
+
exports.enableBfcacheReporting = performanceObserver.enableBfcacheReporting;
|
|
36
|
+
exports.enableSoftNavigationReporting = performanceObserver.enableSoftNavigationReporting;
|
|
37
|
+
exports.startSoftNavigationCorrelation = softNavs.startSoftNavigationCorrelation;
|
|
38
|
+
exports.supportsSoftNavigations = softNavs.supportsSoftNavigations;
|
|
34
39
|
exports.addPerformanceEntries = entries.addPerformanceEntries;
|
|
35
40
|
exports.startTrackingLongAnimationFrames = entries.startTrackingLongAnimationFrames;
|
|
36
41
|
exports.startTrackingLongTasks = entries.startTrackingLongTasks;
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -11,6 +11,15 @@ let _previousLcp;
|
|
|
11
11
|
let _previousTtfb;
|
|
12
12
|
let _previousInp;
|
|
13
13
|
let _previousFcp;
|
|
14
|
+
const stopListeners = {};
|
|
15
|
+
let _reportSoftNavs = false;
|
|
16
|
+
let _reportBfcache = false;
|
|
17
|
+
function enableSoftNavigationReporting() {
|
|
18
|
+
_reportSoftNavs = true;
|
|
19
|
+
}
|
|
20
|
+
function enableBfcacheReporting() {
|
|
21
|
+
_reportBfcache = true;
|
|
22
|
+
}
|
|
14
23
|
function addClsInstrumentationHandler(callback, stopOnCallback = false) {
|
|
15
24
|
return addMetricObserver("cls", callback, instrumentCls, _previousCls, stopOnCallback);
|
|
16
25
|
}
|
|
@@ -53,9 +62,9 @@ Error:`,
|
|
|
53
62
|
}
|
|
54
63
|
}
|
|
55
64
|
}
|
|
56
|
-
function
|
|
65
|
+
function unlessBfcacheDisabled(callback) {
|
|
57
66
|
return (metric) => {
|
|
58
|
-
if (metric.navigationType === "back-forward-cache") {
|
|
67
|
+
if (!_reportBfcache && metric.navigationType === "back-forward-cache") {
|
|
59
68
|
return;
|
|
60
69
|
}
|
|
61
70
|
callback(metric);
|
|
@@ -63,7 +72,7 @@ function withoutBfcache(callback) {
|
|
|
63
72
|
}
|
|
64
73
|
function instrumentCls() {
|
|
65
74
|
return webVitals.onCLS(
|
|
66
|
-
|
|
75
|
+
unlessBfcacheDisabled((metric) => {
|
|
67
76
|
triggerHandlers("cls", {
|
|
68
77
|
metric
|
|
69
78
|
});
|
|
@@ -71,12 +80,12 @@ function instrumentCls() {
|
|
|
71
80
|
}),
|
|
72
81
|
// We want the callback to be called whenever the CLS value updates.
|
|
73
82
|
// By default, the callback is only called when the tab goes to the background.
|
|
74
|
-
{ reportAllChanges:
|
|
83
|
+
{ reportAllChanges: !_reportSoftNavs && !_reportBfcache, reportSoftNavs: _reportSoftNavs }
|
|
75
84
|
);
|
|
76
85
|
}
|
|
77
86
|
function instrumentLcp() {
|
|
78
87
|
return webVitals.onLCP(
|
|
79
|
-
|
|
88
|
+
unlessBfcacheDisabled((metric) => {
|
|
80
89
|
triggerHandlers("lcp", {
|
|
81
90
|
metric
|
|
82
91
|
});
|
|
@@ -84,12 +93,12 @@ function instrumentLcp() {
|
|
|
84
93
|
}),
|
|
85
94
|
// We want the callback to be called whenever the LCP value updates.
|
|
86
95
|
// By default, the callback is only called when the tab goes to the background.
|
|
87
|
-
{ reportAllChanges:
|
|
96
|
+
{ reportAllChanges: !_reportSoftNavs && !_reportBfcache, reportSoftNavs: _reportSoftNavs }
|
|
88
97
|
);
|
|
89
98
|
}
|
|
90
99
|
function instrumentTtfb() {
|
|
91
100
|
return webVitals.onTTFB(
|
|
92
|
-
|
|
101
|
+
unlessBfcacheDisabled((metric) => {
|
|
93
102
|
triggerHandlers("ttfb", {
|
|
94
103
|
metric
|
|
95
104
|
});
|
|
@@ -99,7 +108,7 @@ function instrumentTtfb() {
|
|
|
99
108
|
}
|
|
100
109
|
function instrumentFcp() {
|
|
101
110
|
return webVitals.onFCP(
|
|
102
|
-
|
|
111
|
+
unlessBfcacheDisabled((metric) => {
|
|
103
112
|
triggerHandlers("fcp", {
|
|
104
113
|
metric
|
|
105
114
|
});
|
|
@@ -109,25 +118,27 @@ function instrumentFcp() {
|
|
|
109
118
|
}
|
|
110
119
|
function instrumentInp() {
|
|
111
120
|
return webVitals.onINP(
|
|
112
|
-
|
|
121
|
+
unlessBfcacheDisabled((metric) => {
|
|
113
122
|
triggerHandlers("inp", {
|
|
114
123
|
metric
|
|
115
124
|
});
|
|
116
125
|
_previousInp = metric;
|
|
117
|
-
})
|
|
126
|
+
}),
|
|
127
|
+
{ reportSoftNavs: _reportSoftNavs }
|
|
118
128
|
);
|
|
119
129
|
}
|
|
120
130
|
function addMetricObserver(type, callback, instrumentFn, previousValue, stopOnCallback = false) {
|
|
121
131
|
addHandler(type, callback);
|
|
122
|
-
let stopListening;
|
|
123
132
|
if (!instrumented[type]) {
|
|
124
|
-
stopListening = instrumentFn();
|
|
125
133
|
instrumented[type] = true;
|
|
134
|
+
void Promise.resolve().then(() => {
|
|
135
|
+
stopListeners[type] = instrumentFn();
|
|
136
|
+
});
|
|
126
137
|
}
|
|
127
138
|
if (previousValue) {
|
|
128
139
|
callback({ metric: previousValue });
|
|
129
140
|
}
|
|
130
|
-
return getCleanupCallback(type, callback, stopOnCallback
|
|
141
|
+
return getCleanupCallback(type, callback, stopOnCallback);
|
|
131
142
|
}
|
|
132
143
|
function instrumentPerformanceObserver(type) {
|
|
133
144
|
const options = { type, buffered: true };
|
|
@@ -150,10 +161,10 @@ function addHandler(type, handler) {
|
|
|
150
161
|
handlers[type] = handlers[type] || [];
|
|
151
162
|
handlers[type].push(handler);
|
|
152
163
|
}
|
|
153
|
-
function getCleanupCallback(type, callback,
|
|
164
|
+
function getCleanupCallback(type, callback, stopOnCleanup = false) {
|
|
154
165
|
return () => {
|
|
155
|
-
if (
|
|
156
|
-
|
|
166
|
+
if (stopOnCleanup) {
|
|
167
|
+
stopListeners[type]?.();
|
|
157
168
|
}
|
|
158
169
|
const typeHandlers = handlers[type];
|
|
159
170
|
if (!typeHandlers) {
|
|
@@ -175,5 +186,7 @@ exports.addInpInstrumentationHandler = addInpInstrumentationHandler;
|
|
|
175
186
|
exports.addLcpInstrumentationHandler = addLcpInstrumentationHandler;
|
|
176
187
|
exports.addPerformanceInstrumentationHandler = addPerformanceInstrumentationHandler;
|
|
177
188
|
exports.addTtfbInstrumentationHandler = addTtfbInstrumentationHandler;
|
|
189
|
+
exports.enableBfcacheReporting = enableBfcacheReporting;
|
|
190
|
+
exports.enableSoftNavigationReporting = enableSoftNavigationReporting;
|
|
178
191
|
exports.isPerformanceEventTiming = isPerformanceEventTiming;
|
|
179
192
|
//# sourceMappingURL=performanceObserver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performanceObserver.js","sources":["../../../src/instrumentation/performanceObserver.ts"],"sourcesContent":["import { debug, getFunctionName } from '@sentry/core';\nimport { onCLS, onFCP, onINP, onLCP, onTTFB } from 'web-vitals';\nimport { DEBUG_BUILD } from '../debug-build';\n\ntype InstrumentHandlerTypePerformanceObserver =\n | 'longtask'\n | 'event'\n | 'navigation'\n | 'paint'\n | 'resource'\n | 'element'\n // fist-input is still needed for INP\n | 'first-input';\n\ntype InstrumentHandlerTypeMetric = 'cls' | 'lcp' | 'ttfb' | 'inp' | 'fcp';\n\n// We provide this here manually instead of relying on a global, as this is not available in non-browser environements\n// And we do not want to expose such types\ninterface PerformanceEntry {\n readonly duration: number;\n readonly entryType: string;\n readonly name: string;\n readonly startTime: number;\n toJSON(): Record<string, unknown>;\n}\nexport interface PerformanceEventTiming extends PerformanceEntry {\n processingStart: number;\n processingEnd: number;\n duration: number;\n cancelable?: boolean;\n target?: unknown | null;\n interactionId?: number;\n}\n\ninterface PerformanceScriptTiming extends PerformanceEntry {\n sourceURL: string;\n sourceFunctionName: string;\n sourceCharPosition: number;\n invoker: string;\n invokerType: string;\n}\nexport interface PerformanceLongAnimationFrameTiming extends PerformanceEntry {\n scripts: PerformanceScriptTiming[];\n}\n\n// Locally-defined to match web-vitals' `Metric` shape without importing it: web-vitals' type\n// entrypoint carries a `declare global` block that references DOM globals not present in every\n// TypeScript lib version (e.g. `NavigationType`), which leaks into and breaks consumers on older\n// TS. Keeping this local keeps web-vitals' global augmentations out of our published types.\ninterface Metric {\n /**\n * The name of the metric (in acronym form).\n */\n name: 'CLS' | 'FCP' | 'INP' | 'LCP' | 'TTFB';\n\n /**\n * The current value of the metric.\n */\n value: number;\n\n /**\n * The rating as to whether the metric value is within the \"good\",\n * \"needs improvement\", or \"poor\" thresholds of the metric.\n */\n rating: 'good' | 'needs-improvement' | 'poor';\n\n /**\n * The delta between the current value and the last-reported value.\n * On the first report, `delta` and `value` will always be the same.\n */\n delta: number;\n\n /**\n * A unique ID representing this particular metric instance. This ID can\n * be used by an analytics tool to dedupe multiple values sent for the same\n * metric instance, or to group multiple deltas together and calculate a\n * total. It can also be used to differentiate multiple different metric\n * instances sent from the same page, which can happen if the page is\n * restored from the back/forward cache (in that case new metrics object\n * get created).\n */\n id: string;\n\n /**\n * Any performance entries relevant to the metric value calculation.\n * The array may also be empty if the metric value was not based on any\n * entries (e.g. a CLS value of 0 given no layout shifts).\n */\n entries: PerformanceEntry[];\n\n /**\n * The type of navigation.\n *\n * Navigation Timing API (or `undefined` if the browser doesn't\n * support that API). For pages that are restored from the bfcache, this\n * value will be 'back-forward-cache'.\n */\n navigationType:\n | 'navigate'\n | 'reload'\n | 'back-forward'\n | 'back-forward-cache'\n | 'prerender'\n | 'restore'\n | 'soft-navigation';\n}\n\ntype InstrumentHandlerType = InstrumentHandlerTypeMetric | InstrumentHandlerTypePerformanceObserver;\n\ntype StopListening = undefined | void | (() => void);\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype InstrumentHandlerCallback = (data: any) => void;\n\ntype CleanupHandlerCallback = () => void;\n\nconst handlers: { [key in InstrumentHandlerType]?: InstrumentHandlerCallback[] } = {};\nconst instrumented: { [key in InstrumentHandlerType]?: boolean } = {};\n\nlet _previousCls: Metric | undefined;\nlet _previousLcp: Metric | undefined;\nlet _previousTtfb: Metric | undefined;\nlet _previousInp: Metric | undefined;\nlet _previousFcp: Metric | undefined;\n\n/**\n * Add a callback that will be triggered when a CLS metric is available.\n * Returns a cleanup callback which can be called to remove the instrumentation handler.\n *\n * Pass `stopOnCallback = true` to stop listening for CLS when the cleanup callback is called.\n * This will lead to the CLS being finalized and frozen.\n */\nexport function addClsInstrumentationHandler(\n callback: (data: { metric: Metric }) => void,\n stopOnCallback = false,\n): CleanupHandlerCallback {\n return addMetricObserver('cls', callback, instrumentCls, _previousCls, stopOnCallback);\n}\n\n/**\n * Add a callback that will be triggered when a LCP metric is available.\n * Returns a cleanup callback which can be called to remove the instrumentation handler.\n *\n * Pass `stopOnCallback = true` to stop listening for LCP when the cleanup callback is called.\n * This will lead to the LCP being finalized and frozen.\n */\nexport function addLcpInstrumentationHandler(\n callback: (data: { metric: Metric }) => void,\n stopOnCallback = false,\n): CleanupHandlerCallback {\n return addMetricObserver('lcp', callback, instrumentLcp, _previousLcp, stopOnCallback);\n}\n\n/**\n * Add a callback that will be triggered when a TTFD metric is available.\n */\nexport function addTtfbInstrumentationHandler(callback: (data: { metric: Metric }) => void): CleanupHandlerCallback {\n return addMetricObserver('ttfb', callback, instrumentTtfb, _previousTtfb);\n}\n\n/**\n * Add a callback that will be triggered when a FCP metric is available.\n */\nexport function addFcpInstrumentationHandler(callback: (data: { metric: Metric }) => void): CleanupHandlerCallback {\n return addMetricObserver('fcp', callback, instrumentFcp, _previousFcp);\n}\n\nexport type InstrumentationHandlerCallback = (data: {\n metric: Omit<Metric, 'entries'> & {\n entries: PerformanceEventTiming[];\n };\n}) => void;\n\n/**\n * Add a callback that will be triggered when a INP metric is available.\n * Returns a cleanup callback which can be called to remove the instrumentation handler.\n */\nexport function addInpInstrumentationHandler(callback: InstrumentationHandlerCallback): CleanupHandlerCallback {\n return addMetricObserver('inp', callback, instrumentInp, _previousInp);\n}\n\nexport function addPerformanceInstrumentationHandler(\n type: 'event',\n callback: (data: { entries: ((PerformanceEntry & { target?: unknown | null }) | PerformanceEventTiming)[] }) => void,\n): CleanupHandlerCallback;\nexport function addPerformanceInstrumentationHandler(\n type: InstrumentHandlerTypePerformanceObserver,\n callback: (data: { entries: PerformanceEntry[] }) => void,\n): CleanupHandlerCallback;\n\n/**\n * Add a callback that will be triggered when a performance observer is triggered,\n * and receives the entries of the observer.\n * Returns a cleanup callback which can be called to remove the instrumentation handler.\n */\nexport function addPerformanceInstrumentationHandler(\n type: InstrumentHandlerTypePerformanceObserver,\n callback: (data: { entries: PerformanceEntry[] }) => void,\n): CleanupHandlerCallback {\n addHandler(type, callback);\n\n if (!instrumented[type]) {\n instrumentPerformanceObserver(type);\n instrumented[type] = true;\n }\n\n return getCleanupCallback(type, callback);\n}\n\n/** Trigger all handlers of a given type. */\nfunction triggerHandlers(type: InstrumentHandlerType, data: unknown): void {\n const typeHandlers = handlers[type];\n\n if (!typeHandlers?.length) {\n return;\n }\n\n for (const handler of typeHandlers) {\n try {\n handler(data);\n } catch (e) {\n DEBUG_BUILD &&\n debug.error(\n `Error while triggering instrumentation handler.\\nType: ${type}\\nName: ${getFunctionName(handler)}\\nError:`,\n e,\n );\n }\n }\n}\n\n/**\n * Wraps a metric callback so that metrics reported after a back/forward-cache restore are ignored.\n *\n * web-vitals re-reports each metric after a bfcache restore (tagged with a `back-forward-cache`\n * navigation type). We intentionally drop those for now: our reporting assumes one set of vitals\n * per page load, so surfacing bfcache re-reports would skew the data until we're ready to model\n * and communicate them.\n */\nfunction withoutBfcache(callback: (metric: Metric) => void): (metric: Metric) => void {\n return metric => {\n if (metric.navigationType === 'back-forward-cache') {\n return;\n }\n callback(metric);\n };\n}\n\nfunction instrumentCls(): StopListening {\n return onCLS(\n withoutBfcache(metric => {\n triggerHandlers('cls', {\n metric,\n });\n _previousCls = metric;\n }),\n // We want the callback to be called whenever the CLS value updates.\n // By default, the callback is only called when the tab goes to the background.\n { reportAllChanges: true },\n );\n}\n\nfunction instrumentLcp(): StopListening {\n return onLCP(\n withoutBfcache(metric => {\n triggerHandlers('lcp', {\n metric,\n });\n _previousLcp = metric;\n }),\n // We want the callback to be called whenever the LCP value updates.\n // By default, the callback is only called when the tab goes to the background.\n { reportAllChanges: true },\n );\n}\n\nfunction instrumentTtfb(): StopListening {\n return onTTFB(\n withoutBfcache(metric => {\n triggerHandlers('ttfb', {\n metric,\n });\n _previousTtfb = metric;\n }),\n );\n}\n\nfunction instrumentFcp(): StopListening {\n return onFCP(\n withoutBfcache(metric => {\n triggerHandlers('fcp', {\n metric,\n });\n _previousFcp = metric;\n }),\n );\n}\n\nfunction instrumentInp(): StopListening {\n return onINP(\n withoutBfcache(metric => {\n triggerHandlers('inp', {\n metric,\n });\n _previousInp = metric;\n }),\n );\n}\n\nfunction addMetricObserver(\n type: InstrumentHandlerTypeMetric,\n callback: InstrumentHandlerCallback,\n instrumentFn: () => StopListening,\n previousValue: Metric | undefined,\n stopOnCallback = false,\n): CleanupHandlerCallback {\n addHandler(type, callback);\n\n let stopListening: StopListening | undefined;\n\n if (!instrumented[type]) {\n stopListening = instrumentFn();\n instrumented[type] = true;\n }\n\n if (previousValue) {\n callback({ metric: previousValue });\n }\n\n return getCleanupCallback(type, callback, stopOnCallback ? stopListening : undefined);\n}\n\nfunction instrumentPerformanceObserver(type: InstrumentHandlerTypePerformanceObserver): void {\n const options: PerformanceObserverInit = { type, buffered: true };\n\n // Special per-type options we want to use\n if (type === 'event') {\n (options as PerformanceObserverInit & { durationThreshold?: number }).durationThreshold = 0;\n }\n\n try {\n if (PerformanceObserver.supportedEntryTypes.includes(type)) {\n const po = new PerformanceObserver(list => {\n // Delay by a microtask to work around a bug in Safari where the\n // callback is invoked synchronously rather than in a separate task.\n // See: https://github.com/GoogleChrome/web-vitals/issues/277\n void Promise.resolve().then(() => {\n triggerHandlers(type, { entries: list.getEntries() });\n });\n });\n po.observe(options);\n }\n } catch {\n // Unsupported entry type; nothing to observe.\n }\n}\n\nfunction addHandler(type: InstrumentHandlerType, handler: InstrumentHandlerCallback): void {\n handlers[type] = handlers[type] || [];\n handlers[type].push(handler);\n}\n\n// Get a callback which can be called to remove the instrumentation handler\nfunction getCleanupCallback(\n type: InstrumentHandlerType,\n callback: InstrumentHandlerCallback,\n stopListening: StopListening,\n): CleanupHandlerCallback {\n return () => {\n if (stopListening) {\n stopListening();\n }\n\n const typeHandlers = handlers[type];\n\n if (!typeHandlers) {\n return;\n }\n\n const index = typeHandlers.indexOf(callback);\n if (index !== -1) {\n typeHandlers.splice(index, 1);\n }\n };\n}\n\n/**\n * Check if a PerformanceEntry is a PerformanceEventTiming by checking for the `duration` property.\n */\nexport function isPerformanceEventTiming(entry: PerformanceEntry): entry is PerformanceEventTiming {\n return 'duration' in entry;\n}\n"],"names":["DEBUG_BUILD","debug","getFunctionName","onCLS","onLCP","onTTFB","onFCP","onINP"],"mappings":";;;;;;AAoHA,MAAM,WAA6E,EAAC;AACpF,MAAM,eAA6D,EAAC;AAEpE,IAAI,YAAA;AACJ,IAAI,YAAA;AACJ,IAAI,aAAA;AACJ,IAAI,YAAA;AACJ,IAAI,YAAA;AASG,SAAS,4BAAA,CACd,QAAA,EACA,cAAA,GAAiB,KAAA,EACO;AACxB,EAAA,OAAO,iBAAA,CAAkB,KAAA,EAAO,QAAA,EAAU,aAAA,EAAe,cAAc,cAAc,CAAA;AACvF;AASO,SAAS,4BAAA,CACd,QAAA,EACA,cAAA,GAAiB,KAAA,EACO;AACxB,EAAA,OAAO,iBAAA,CAAkB,KAAA,EAAO,QAAA,EAAU,aAAA,EAAe,cAAc,cAAc,CAAA;AACvF;AAKO,SAAS,8BAA8B,QAAA,EAAsE;AAClH,EAAA,OAAO,iBAAA,CAAkB,MAAA,EAAQ,QAAA,EAAU,cAAA,EAAgB,aAAa,CAAA;AAC1E;AAKO,SAAS,6BAA6B,QAAA,EAAsE;AACjH,EAAA,OAAO,iBAAA,CAAkB,KAAA,EAAO,QAAA,EAAU,aAAA,EAAe,YAAY,CAAA;AACvE;AAYO,SAAS,6BAA6B,QAAA,EAAkE;AAC7G,EAAA,OAAO,iBAAA,CAAkB,KAAA,EAAO,QAAA,EAAU,aAAA,EAAe,YAAY,CAAA;AACvE;AAgBO,SAAS,oCAAA,CACd,MACA,QAAA,EACwB;AACxB,EAAA,UAAA,CAAW,MAAM,QAAQ,CAAA;AAEzB,EAAA,IAAI,CAAC,YAAA,CAAa,IAAI,CAAA,EAAG;AACvB,IAAA,6BAAA,CAA8B,IAAI,CAAA;AAClC,IAAA,YAAA,CAAa,IAAI,CAAA,GAAI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AO,CAAC,CAAA;AAAA,IAC9B;AAAA,EACF,CAAA;AACF;AAKO,SAAS,yBAAyB,KAAA,EAA0D;AACjG,EAAA,OAAO,UAAA,IAAc,KAAA;AACvB;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"performanceObserver.js","sources":["../../../src/instrumentation/performanceObserver.ts"],"sourcesContent":["import { debug, getFunctionName } from '@sentry/core';\nimport { onCLS, onFCP, onINP, onLCP, onTTFB } from 'web-vitals';\nimport { DEBUG_BUILD } from '../debug-build';\n\ntype InstrumentHandlerTypePerformanceObserver =\n | 'longtask'\n | 'event'\n | 'navigation'\n | 'paint'\n | 'resource'\n | 'element'\n | 'soft-navigation'\n // fist-input is still needed for INP\n | 'first-input';\n\ntype InstrumentHandlerTypeMetric = 'cls' | 'lcp' | 'ttfb' | 'inp' | 'fcp';\n\n// We provide this here manually instead of relying on a global, as this is not available in non-browser environements\n// And we do not want to expose such types\ninterface PerformanceEntry {\n readonly duration: number;\n readonly entryType: string;\n readonly name: string;\n readonly startTime: number;\n toJSON(): Record<string, unknown>;\n}\nexport interface PerformanceEventTiming extends PerformanceEntry {\n processingStart: number;\n processingEnd: number;\n duration: number;\n cancelable?: boolean;\n target?: unknown | null;\n interactionId?: number;\n}\n\n/**\n * A `soft-navigation` entry, minted by the browser once a history change is followed by a\n * confirming paint. `interactionId` is the id of the `PerformanceEventTiming` entry for the\n * interaction that drove the navigation, which is how we join it back to a Sentry navigation span.\n */\nexport interface PerformanceSoftNavigation extends PerformanceEntry {\n readonly interactionId: number;\n readonly navigationId: number;\n}\n\ninterface PerformanceScriptTiming extends PerformanceEntry {\n sourceURL: string;\n sourceFunctionName: string;\n sourceCharPosition: number;\n invoker: string;\n invokerType: string;\n}\nexport interface PerformanceLongAnimationFrameTiming extends PerformanceEntry {\n scripts: PerformanceScriptTiming[];\n}\n\n// Locally-defined to match web-vitals' `Metric` shape without importing it: web-vitals' type\n// entrypoint carries a `declare global` block that references DOM globals not present in every\n// TypeScript lib version (e.g. `NavigationType`), which leaks into and breaks consumers on older\n// TS. Keeping this local keeps web-vitals' global augmentations out of our published types.\n/**\n * The navigation types web-vitals reports a metric for. Wider than the set the\n * `browser.navigation.type` attribute uses - see `toBrowserNavigationType`.\n */\nexport type MetricNavigationType =\n | 'navigate'\n | 'reload'\n | 'back-forward'\n | 'back-forward-cache'\n | 'prerender'\n | 'restore'\n | 'soft-navigation';\n\ninterface Metric {\n /**\n * The name of the metric (in acronym form).\n */\n name: 'CLS' | 'FCP' | 'INP' | 'LCP' | 'TTFB';\n\n /**\n * The current value of the metric.\n */\n value: number;\n\n /**\n * The rating as to whether the metric value is within the \"good\",\n * \"needs improvement\", or \"poor\" thresholds of the metric.\n */\n rating: 'good' | 'needs-improvement' | 'poor';\n\n /**\n * The delta between the current value and the last-reported value.\n * On the first report, `delta` and `value` will always be the same.\n */\n delta: number;\n\n /**\n * A unique ID representing this particular metric instance. This ID can\n * be used by an analytics tool to dedupe multiple values sent for the same\n * metric instance, or to group multiple deltas together and calculate a\n * total. It can also be used to differentiate multiple different metric\n * instances sent from the same page, which can happen if the page is\n * restored from the back/forward cache (in that case new metrics object\n * get created).\n */\n id: string;\n\n /**\n * Any performance entries relevant to the metric value calculation.\n * The array may also be empty if the metric value was not based on any\n * entries (e.g. a CLS value of 0 given no layout shifts).\n */\n entries: PerformanceEntry[];\n\n /**\n * The type of navigation.\n *\n * Navigation Timing API (or `undefined` if the browser doesn't\n * support that API). For pages that are restored from the bfcache, this\n * value will be 'back-forward-cache'.\n */\n navigationType: MetricNavigationType;\n\n /**\n * The id of the navigation the metric belongs to. For soft navigations this is the\n * `navigationId` of the `soft-navigation` entry, otherwise it's the id of the hard navigation.\n */\n navigationId: number;\n\n /**\n * For soft navigations, the `interactionId` of the interaction that triggered the navigation.\n */\n navigationInteractionId?: number;\n\n /**\n * The start time the metric value is relative to. Non-zero for soft navigations, where the\n * time origin is the triggering interaction rather than the start of the document.\n */\n navigationStartTime?: number;\n\n /**\n * The URL the metric was recorded for. Relevant for soft navigations, where a metric can be\n * reported long after the URL has moved on.\n */\n navigationURL?: string;\n}\n\ntype InstrumentHandlerType = InstrumentHandlerTypeMetric | InstrumentHandlerTypePerformanceObserver;\n\ntype StopListening = undefined | void | (() => void);\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype InstrumentHandlerCallback = (data: any) => void;\n\ntype CleanupHandlerCallback = () => void;\n\nconst handlers: { [key in InstrumentHandlerType]?: InstrumentHandlerCallback[] } = {};\nconst instrumented: { [key in InstrumentHandlerType]?: boolean } = {};\n\nlet _previousCls: Metric | undefined;\nlet _previousLcp: Metric | undefined;\nlet _previousTtfb: Metric | undefined;\nlet _previousInp: Metric | undefined;\nlet _previousFcp: Metric | undefined;\n\nconst stopListeners: Partial<Record<InstrumentHandlerType, StopListening>> = {};\n\nlet _reportSoftNavs = false;\nlet _reportBfcache = false;\n\n/**\n * Opt the CLS, LCP and INP observers into reporting metrics for soft navigations.\n *\n * This also turns `reportAllChanges` off for CLS and LCP. web-vitals force-reports a metric when\n * the navigation it belongs to is over, so without the intermediate updates every value a handler\n * receives is already the final one for its navigation. That only holds because soft navigations\n * are limited to span streaming, where CLS and LCP are sent as their own spans - the static\n * lifecycle instead writes them onto the pageload span as it ends, which is what `reportAllChanges`\n * was originally added for (#11934, #12360).\n *\n * Each observer is instrumented lazily, on its first handler, and web-vitals takes its options at\n * that point only. So this has to be called before any of the `add*InstrumentationHandler`\n * functions, otherwise it won't take effect for observers that are already running.\n *\n * On browsers without the Soft Navigation API this is a no-op: web-vitals feature-detects the API\n * and keeps reporting hard-navigation metrics as usual.\n */\nexport function enableSoftNavigationReporting(): void {\n _reportSoftNavs = true;\n}\n\n/**\n * Opt the CLS, LCP and INP observers into reporting metrics for back/forward-cache restores.\n *\n * web-vitals re-reports each metric after a restore, tagged with a `back-forward-cache` navigation\n * type. A restore is a new page view measured against a document that was never reloaded, so the\n * values only mean anything if there is a fresh root span for them to belong to. Without one they\n * would attach to the span the page had before it was frozen, which is why this is off by default.\n *\n * Like `enableSoftNavigationReporting`, this only affects observers instrumented after it is\n * called.\n */\nexport function enableBfcacheReporting(): void {\n _reportBfcache = true;\n}\n\n/**\n * Add a callback that will be triggered when a CLS metric is available.\n * Returns a cleanup callback which can be called to remove the instrumentation handler.\n *\n * Pass `stopOnCallback = true` to stop listening for CLS when the cleanup callback is called.\n * This will lead to the CLS being finalized and frozen.\n */\nexport function addClsInstrumentationHandler(\n callback: (data: { metric: Metric }) => void,\n stopOnCallback = false,\n): CleanupHandlerCallback {\n return addMetricObserver('cls', callback, instrumentCls, _previousCls, stopOnCallback);\n}\n\n/**\n * Add a callback that will be triggered when a LCP metric is available.\n * Returns a cleanup callback which can be called to remove the instrumentation handler.\n *\n * Pass `stopOnCallback = true` to stop listening for LCP when the cleanup callback is called.\n * This will lead to the LCP being finalized and frozen.\n */\nexport function addLcpInstrumentationHandler(\n callback: (data: { metric: Metric }) => void,\n stopOnCallback = false,\n): CleanupHandlerCallback {\n return addMetricObserver('lcp', callback, instrumentLcp, _previousLcp, stopOnCallback);\n}\n\n/**\n * Add a callback that will be triggered when a TTFD metric is available.\n */\nexport function addTtfbInstrumentationHandler(callback: (data: { metric: Metric }) => void): CleanupHandlerCallback {\n return addMetricObserver('ttfb', callback, instrumentTtfb, _previousTtfb);\n}\n\n/**\n * Add a callback that will be triggered when a FCP metric is available.\n */\nexport function addFcpInstrumentationHandler(callback: (data: { metric: Metric }) => void): CleanupHandlerCallback {\n return addMetricObserver('fcp', callback, instrumentFcp, _previousFcp);\n}\n\nexport type InstrumentationHandlerCallback = (data: {\n metric: Omit<Metric, 'entries'> & {\n entries: PerformanceEventTiming[];\n };\n}) => void;\n\n/**\n * Add a callback that will be triggered when a INP metric is available.\n * Returns a cleanup callback which can be called to remove the instrumentation handler.\n */\nexport function addInpInstrumentationHandler(callback: InstrumentationHandlerCallback): CleanupHandlerCallback {\n return addMetricObserver('inp', callback, instrumentInp, _previousInp);\n}\n\nexport function addPerformanceInstrumentationHandler(\n type: 'event',\n callback: (data: { entries: ((PerformanceEntry & { target?: unknown | null }) | PerformanceEventTiming)[] }) => void,\n): CleanupHandlerCallback;\nexport function addPerformanceInstrumentationHandler(\n type: InstrumentHandlerTypePerformanceObserver,\n callback: (data: { entries: PerformanceEntry[] }) => void,\n): CleanupHandlerCallback;\n\n/**\n * Add a callback that will be triggered when a performance observer is triggered,\n * and receives the entries of the observer.\n * Returns a cleanup callback which can be called to remove the instrumentation handler.\n */\nexport function addPerformanceInstrumentationHandler(\n type: InstrumentHandlerTypePerformanceObserver,\n callback: (data: { entries: PerformanceEntry[] }) => void,\n): CleanupHandlerCallback {\n addHandler(type, callback);\n\n if (!instrumented[type]) {\n instrumentPerformanceObserver(type);\n instrumented[type] = true;\n }\n\n return getCleanupCallback(type, callback);\n}\n\n/** Trigger all handlers of a given type. */\nfunction triggerHandlers(type: InstrumentHandlerType, data: unknown): void {\n const typeHandlers = handlers[type];\n\n if (!typeHandlers?.length) {\n return;\n }\n\n for (const handler of typeHandlers) {\n try {\n handler(data);\n } catch (e) {\n DEBUG_BUILD &&\n debug.error(\n `Error while triggering instrumentation handler.\\nType: ${type}\\nName: ${getFunctionName(handler)}\\nError:`,\n e,\n );\n }\n }\n}\n\n/**\n * Wraps a metric callback so that metrics reported after a back/forward-cache restore are dropped\n * unless `enableBfcacheReporting` was called. See there for why they are off by default.\n */\nfunction unlessBfcacheDisabled(callback: (metric: Metric) => void): (metric: Metric) => void {\n return metric => {\n if (!_reportBfcache && metric.navigationType === 'back-forward-cache') {\n return;\n }\n callback(metric);\n };\n}\n\nfunction instrumentCls(): StopListening {\n return onCLS(\n unlessBfcacheDisabled(metric => {\n triggerHandlers('cls', {\n metric,\n });\n _previousCls = metric;\n }),\n // We want the callback to be called whenever the CLS value updates.\n // By default, the callback is only called when the tab goes to the background.\n { reportAllChanges: !_reportSoftNavs && !_reportBfcache, reportSoftNavs: _reportSoftNavs },\n );\n}\n\nfunction instrumentLcp(): StopListening {\n return onLCP(\n unlessBfcacheDisabled(metric => {\n triggerHandlers('lcp', {\n metric,\n });\n _previousLcp = metric;\n }),\n // We want the callback to be called whenever the LCP value updates.\n // By default, the callback is only called when the tab goes to the background.\n { reportAllChanges: !_reportSoftNavs && !_reportBfcache, reportSoftNavs: _reportSoftNavs },\n );\n}\n\nfunction instrumentTtfb(): StopListening {\n return onTTFB(\n unlessBfcacheDisabled(metric => {\n triggerHandlers('ttfb', {\n metric,\n });\n _previousTtfb = metric;\n }),\n );\n}\n\nfunction instrumentFcp(): StopListening {\n return onFCP(\n unlessBfcacheDisabled(metric => {\n triggerHandlers('fcp', {\n metric,\n });\n _previousFcp = metric;\n }),\n );\n}\n\nfunction instrumentInp(): StopListening {\n return onINP(\n unlessBfcacheDisabled(metric => {\n triggerHandlers('inp', {\n metric,\n });\n _previousInp = metric;\n }),\n { reportSoftNavs: _reportSoftNavs },\n );\n}\n\nfunction addMetricObserver(\n type: InstrumentHandlerTypeMetric,\n callback: InstrumentHandlerCallback,\n instrumentFn: () => StopListening,\n previousValue: Metric | undefined,\n stopOnCallback = false,\n): CleanupHandlerCallback {\n addHandler(type, callback);\n\n if (!instrumented[type]) {\n instrumented[type] = true;\n // Deferred by a microtask rather than started here, because web-vitals reads its options once,\n // when the observer is created. Registering a handler would otherwise pin those options for\n // every other consumer of this observer, so whichever integration happened to run first would\n // decide whether soft navigations and bfcache restores are reported. Client setup is\n // synchronous, so every `enable*Reporting()` call has landed by the time this runs, and the\n // observers are buffered so no entries are missed in the meantime.\n void Promise.resolve().then(() => {\n stopListeners[type] = instrumentFn();\n });\n }\n\n if (previousValue) {\n callback({ metric: previousValue });\n }\n\n return getCleanupCallback(type, callback, stopOnCallback);\n}\n\nfunction instrumentPerformanceObserver(type: InstrumentHandlerTypePerformanceObserver): void {\n const options: PerformanceObserverInit = { type, buffered: true };\n\n // Special per-type options we want to use\n if (type === 'event') {\n (options as PerformanceObserverInit & { durationThreshold?: number }).durationThreshold = 0;\n }\n\n try {\n if (PerformanceObserver.supportedEntryTypes.includes(type)) {\n const po = new PerformanceObserver(list => {\n // Delay by a microtask to work around a bug in Safari where the\n // callback is invoked synchronously rather than in a separate task.\n // See: https://github.com/GoogleChrome/web-vitals/issues/277\n void Promise.resolve().then(() => {\n triggerHandlers(type, { entries: list.getEntries() });\n });\n });\n po.observe(options);\n }\n } catch {\n // Unsupported entry type; nothing to observe.\n }\n}\n\nfunction addHandler(type: InstrumentHandlerType, handler: InstrumentHandlerCallback): void {\n handlers[type] = handlers[type] || [];\n handlers[type].push(handler);\n}\n\n// Get a callback which can be called to remove the instrumentation handler\nfunction getCleanupCallback(\n type: InstrumentHandlerType,\n callback: InstrumentHandlerCallback,\n stopOnCleanup = false,\n): CleanupHandlerCallback {\n return () => {\n // Looked up rather than captured: the observer is started in a microtask, so its stop function\n // does not exist yet when this callback is built.\n if (stopOnCleanup) {\n stopListeners[type]?.();\n }\n\n const typeHandlers = handlers[type];\n\n if (!typeHandlers) {\n return;\n }\n\n const index = typeHandlers.indexOf(callback);\n if (index !== -1) {\n typeHandlers.splice(index, 1);\n }\n };\n}\n\n/**\n * Check if a PerformanceEntry is a PerformanceEventTiming by checking for the `duration` property.\n */\nexport function isPerformanceEventTiming(entry: PerformanceEntry): entry is PerformanceEventTiming {\n return 'duration' in entry;\n}\n"],"names":["DEBUG_BUILD","debug","getFunctionName","onCLS","onLCP","onTTFB","onFCP","onINP"],"mappings":";;;;;;AA4JA,MAAM,WAA6E,EAAC;AACpF,MAAM,eAA6D,EAAC;AAEpE,IAAI,YAAA;AACJ,IAAI,YAAA;AACJ,IAAI,aAAA;AACJ,IAAI,YAAA;AACJ,IAAI,YAAA;AAEJ,MAAM,gBAAuE,EAAC;AAE9E,IAAI,eAAA,GAAkB,KAAA;AACtB,IAAI,cAAA,GAAiB,KAAA;AAmBd,SAAS,6BAAA,GAAsC;AACpD,EAAA,eAAA,GAAkB,IAAA;AACpB;AAaO,SAAS,sBAAA,GAA+B;AAC7C,EAAA,cAAA,GAAiB,IAAA;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AyB,KAAA,EAA0D;AACjG,EAAA,OAAO,UAAA,IAAc,KAAA;AACvB;;;;;;;;;;;;"}
|
|
@@ -16,7 +16,7 @@ function instrumentXHR() {
|
|
|
16
16
|
const xhrproto = XMLHttpRequest.prototype;
|
|
17
17
|
xhrproto.open = new Proxy(xhrproto.open, {
|
|
18
18
|
apply(originalOpen, xhrOpenThisArg, xhrOpenArgArray) {
|
|
19
|
-
|
|
19
|
+
let virtualError = new Error();
|
|
20
20
|
const startTimestamp = core.timestampInSeconds() * 1e3;
|
|
21
21
|
const method = core.isString(xhrOpenArgArray[0]) ? xhrOpenArgArray[0].toUpperCase() : void 0;
|
|
22
22
|
const url = parseXhrUrlArg(xhrOpenArgArray[1]);
|
|
@@ -48,6 +48,7 @@ function instrumentXHR() {
|
|
|
48
48
|
virtualError
|
|
49
49
|
};
|
|
50
50
|
core.triggerHandlers("xhr", handlerData);
|
|
51
|
+
virtualError = void 0;
|
|
51
52
|
xhrOpenThisArg.removeEventListener("readystatechange", onreadystatechangeHandler);
|
|
52
53
|
}
|
|
53
54
|
};
|
|
@@ -1 +1 @@
|
|
|
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,MAAM,YAAA,GAAe,IAAI,KAAA,EA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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;;;;;;"}
|
|
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 let virtualError: Error | undefined = 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 // An unformatted stack keeps its raw frames, and each frame keeps its receiver alive. For a request\n // opened from the previous one's `readystatechange` callback that receiver is the previous\n // XMLHttpRequest, so holding on would chain every completed request to the one still in flight.\n virtualError = undefined;\n\n // In the `addEventListener` branch below this is the only `readystatechange` listener we add, so\n // detach it once the request is done. It's a no-op in the `onreadystatechange` proxy branch.\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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AAA,CAAM,cAAA,EAAgB,eAAe,CAAA;AAAA,IAC3D;AAAA,GACD,CAAA;AAGD,EAAA,QAAA,CAAS,IAAA,GAAO,IAAI,KAAA,CAAM,QAAA,CAAS,IAAA,EAAM;AAAA,IACvC,KAAA,CAAM,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;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entries.js","sources":["../../../src/performance/entries.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport type { Span, SpanAttributes } from '@sentry/core';\nimport {\n browserPerformanceTimeOrigin,\n getActiveSpan,\n parseUrl,\n RESOURCE_SPAN_NAME_FALLBACK,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n setMeasurement,\n spanToJSON,\n filterCollectedUrl,\n} from '@sentry/core';\nimport {\n CODE_FILE_PATH,\n CODE_FUNCTION_NAME,\n HTTP_REQUEST_SAME_ORIGIN,\n HTTP_RESPONSE_BODY_SIZE,\n HTTP_RESPONSE_SIZE,\n HTTP_RESPONSE_STATUS_CODE,\n NETWORK_CONNECTION_EFFECTIVE_TYPE,\n NETWORK_CONNECTION_RTT,\n NETWORK_CONNECTION_TYPE,\n SENTRY_OP,\n SERVER_ADDRESS,\n URL_DOMAIN,\n URL_FULL,\n URL_SCHEME,\n} from '@sentry/conventions/attributes';\nimport {\n BROWSER_CACHE,\n BROWSER_CONNECT,\n BROWSER_DNS,\n BROWSER_DOM_CONTENT_LOADED_EVENT,\n BROWSER_LOAD_EVENT,\n BROWSER_PAINT,\n BROWSER_REDIRECT,\n BROWSER_REQUEST,\n BROWSER_RESPONSE,\n BROWSER_TLS_SSL,\n BROWSER_UNLOAD_EVENT,\n RESOURCE_OTHER,\n UI_LONG_ANIMATION_FRAME,\n UI_LONG_TASK,\n} from '@sentry/conventions/op';\nimport {\n addPerformanceInstrumentationHandler,\n type PerformanceLongAnimationFrameTiming,\n} from '../instrumentation/performanceObserver';\nimport { WINDOW } from '../types';\nimport { resourceTimingToSpanAttributes } from './resourceTiming';\nimport { getBrowserPerformanceAPI, isMeasurementValue, msToSec, startAndEndSpan } from './utils';\n\ninterface NavigatorNetworkInformation {\n readonly connection?: NetworkInformation;\n}\n\n// http://wicg.github.io/netinfo/#connection-types\ntype ConnectionType = 'bluetooth' | 'cellular' | 'ethernet' | 'mixed' | 'none' | 'other' | 'unknown' | 'wifi' | 'wimax';\n\n// http://wicg.github.io/netinfo/#effectiveconnectiontype-enum\ntype EffectiveConnectionType = '2g' | '3g' | '4g' | 'slow-2g';\n\n// http://wicg.github.io/netinfo/#dom-megabit\ntype Megabit = number;\n// http://wicg.github.io/netinfo/#dom-millisecond\ntype Millisecond = number;\n\n// http://wicg.github.io/netinfo/#networkinformation-interface\ninterface NetworkInformation extends EventTarget {\n // http://wicg.github.io/netinfo/#type-attribute\n readonly type?: ConnectionType;\n // http://wicg.github.io/netinfo/#effectivetype-attribute\n readonly effectiveType?: EffectiveConnectionType;\n // http://wicg.github.io/netinfo/#downlinkmax-attribute\n readonly downlinkMax?: Megabit;\n // http://wicg.github.io/netinfo/#downlink-attribute\n readonly downlink?: Megabit;\n // http://wicg.github.io/netinfo/#rtt-attribute\n readonly rtt?: Millisecond;\n // http://wicg.github.io/netinfo/#savedata-attribute\n readonly saveData?: boolean;\n // http://wicg.github.io/netinfo/#handling-changes-to-the-underlying-connection\n onchange?: EventListener;\n}\n\n// https://w3c.github.io/device-memory/#sec-device-memory-js-api\ninterface NavigatorDeviceMemory {\n readonly deviceMemory?: number;\n}\n\nconst MAX_INT_AS_BYTES = 2147483647;\n\nlet _performanceCursor: number = 0;\n\n/**\n * Start tracking long tasks.\n */\nexport function startTrackingLongTasks(): void {\n addPerformanceInstrumentationHandler('longtask', ({ entries }) => {\n const parent = getActiveSpan();\n if (!parent) {\n return;\n }\n\n const { attributes: parentAttributes, start_timestamp: parentStartTimestamp } = spanToJSON(parent);\n\n for (const entry of entries) {\n const startTime = msToSec((browserPerformanceTimeOrigin() as number) + entry.startTime);\n const duration = msToSec(entry.duration);\n\n if (parentAttributes[SENTRY_OP] === 'navigation' && parentStartTimestamp && startTime < parentStartTimestamp) {\n // Skip adding a span if the long task started before the navigation started.\n // `startAndEndSpan` will otherwise adjust the parent's start time to the span's start\n // time, potentially skewing the duration of the actual navigation as reported via our\n // routing instrumentations\n continue;\n }\n\n startAndEndSpan(parent, startTime, startTime + duration, {\n name: 'Main UI thread blocked',\n op: UI_LONG_TASK,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',\n },\n });\n }\n });\n}\n\n/**\n * Start tracking long animation frames.\n */\nexport function startTrackingLongAnimationFrames(): void {\n // NOTE: the current web-vitals version (3.5.2) does not support long-animation-frame, so\n // we directly observe `long-animation-frame` events instead of through the web-vitals\n // `observe` helper function.\n const observer = new PerformanceObserver(list => {\n const parent = getActiveSpan();\n if (!parent) {\n return;\n }\n for (const entry of list.getEntries() as PerformanceLongAnimationFrameTiming[]) {\n if (!entry.scripts[0]) {\n continue;\n }\n\n const startTime = msToSec((browserPerformanceTimeOrigin() as number) + entry.startTime);\n\n const {\n start_timestamp: parentStartTimestamp,\n attributes: { [SENTRY_OP]: parentOp },\n } = spanToJSON(parent);\n\n if (parentOp === 'navigation' && parentStartTimestamp && startTime < parentStartTimestamp) {\n // Skip adding the span if the long animation frame started before the navigation started.\n // `startAndEndSpan` will otherwise adjust the parent's start time to the span's start\n // time, potentially skewing the duration of the actual navigation as reported via our\n // routing instrumentations\n continue;\n }\n const duration = msToSec(entry.duration);\n\n const attributes: SpanAttributes = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',\n };\n\n const initialScript = entry.scripts[0];\n const { invoker, invokerType, sourceURL, sourceFunctionName, sourceCharPosition } = initialScript;\n attributes['browser.script.invoker'] = invoker;\n attributes['browser.script.invoker_type'] = invokerType;\n if (sourceURL) {\n attributes[CODE_FILE_PATH] = sourceURL;\n }\n if (sourceFunctionName) {\n attributes[CODE_FUNCTION_NAME] = sourceFunctionName;\n }\n if (sourceCharPosition !== -1) {\n attributes['browser.script.source_char_position'] = sourceCharPosition;\n }\n\n startAndEndSpan(parent, startTime, startTime + duration, {\n name: 'Main UI thread blocked',\n op: UI_LONG_ANIMATION_FRAME,\n attributes,\n });\n }\n });\n\n observer.observe({ type: 'long-animation-frame', buffered: true });\n}\n\ninterface AddPerformanceEntriesOptions {\n /**\n * Resource spans with `op`s matching strings in the array will not be emitted.\n *\n * Default: []\n */\n ignoreResourceSpans: Array<'resource.script' | 'resource.css' | 'resource.img' | 'resource.other' | string>;\n\n /**\n * Whether span streaming is enabled.\n */\n spanStreamingEnabled?: boolean;\n}\n\n/** Add performance related spans to a transaction */\nexport function addPerformanceEntries(span: Span, options: AddPerformanceEntriesOptions): void {\n const performance = getBrowserPerformanceAPI();\n const origin = browserPerformanceTimeOrigin();\n if (!performance?.getEntries || !origin) {\n // Gatekeeper if performance API not available\n return;\n }\n\n const { spanStreamingEnabled, ignoreResourceSpans } = options;\n\n const timeOrigin = msToSec(origin);\n\n const performanceEntries = performance.getEntries();\n\n const { attributes, start_timestamp: transactionStartTime } = spanToJSON(span);\n\n performanceEntries.slice(_performanceCursor).forEach(entry => {\n const startTime = msToSec(entry.startTime);\n const duration = msToSec(\n // Inexplicably, Chrome sometimes emits a negative duration. We need to work around this.\n // There is a SO post attempting to explain this, but it leaves one with open questions: https://stackoverflow.com/questions/23191918/peformance-getentries-and-negative-duration-display\n // The way we clamp the value is probably not accurate, since we have observed this happen for things that may take a while to load, like for example the replay worker.\n // TODO: Investigate why this happens and how to properly mitigate. For now, this is a workaround to prevent transactions being dropped due to negative duration spans.\n Math.max(0, entry.duration),\n );\n\n if (\n attributes[SENTRY_OP] === 'navigation' &&\n transactionStartTime &&\n timeOrigin + startTime < transactionStartTime\n ) {\n return;\n }\n\n switch (entry.entryType) {\n case 'navigation': {\n _addNavigationSpans(span, entry as PerformanceNavigationTiming, timeOrigin);\n break;\n }\n case 'paint': {\n _addPaintSpan(span, entry, startTime, duration, timeOrigin);\n break;\n }\n case 'resource': {\n _addResourceSpans(\n span,\n entry as PerformanceResourceTiming,\n entry.name,\n startTime,\n duration,\n timeOrigin,\n ignoreResourceSpans,\n spanStreamingEnabled,\n );\n break;\n }\n // Ignore other entry types.\n }\n });\n\n _performanceCursor = Math.max(performanceEntries.length - 1, 0);\n\n _trackNavigator(span, spanStreamingEnabled);\n}\n\n/** Create a span for a browser paint performance entry. */\nfunction _addPaintSpan(\n span: Span,\n entry: PerformanceEntry,\n startTime: number,\n duration: number,\n timeOrigin: number,\n): void {\n const startTimestamp = timeOrigin + startTime;\n\n startAndEndSpan(span, startTimestamp, startTimestamp + duration, {\n name: entry.name,\n attributes: {\n [SENTRY_OP]: BROWSER_PAINT,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.resource.browser.metrics',\n },\n });\n}\n\n/**\n * Instrument navigation entries\n * exported only for tests\n */\nexport function _addNavigationSpans(span: Span, entry: PerformanceNavigationTiming, timeOrigin: number): void {\n _addPerformanceNavigationTiming(span, entry, 'unloadEvent', timeOrigin);\n _addPerformanceNavigationTiming(span, entry, 'redirect', timeOrigin);\n _addPerformanceNavigationTiming(span, entry, 'domContentLoadedEvent', timeOrigin);\n _addPerformanceNavigationTiming(span, entry, 'loadEvent', timeOrigin);\n _addPerformanceNavigationTiming(span, entry, 'connect', timeOrigin);\n _addPerformanceNavigationTiming(span, entry, 'secureConnection', timeOrigin);\n _addPerformanceNavigationTiming(span, entry, 'fetch', timeOrigin);\n _addPerformanceNavigationTiming(span, entry, 'domainLookup', timeOrigin);\n\n _addRequest(span, entry, timeOrigin);\n}\n\ntype StartEventName =\n | 'secureConnection'\n | 'fetch'\n | 'domainLookup'\n | 'unloadEvent'\n | 'redirect'\n | 'connect'\n | 'domContentLoadedEvent'\n | 'loadEvent';\n\nconst NAVIGATION_TIMING_SPAN_OPS: Record<StartEventName, string> = {\n secureConnection: BROWSER_TLS_SSL,\n fetch: BROWSER_CACHE,\n domainLookup: BROWSER_DNS,\n unloadEvent: BROWSER_UNLOAD_EVENT,\n redirect: BROWSER_REDIRECT,\n connect: BROWSER_CONNECT,\n domContentLoadedEvent: BROWSER_DOM_CONTENT_LOADED_EVENT,\n loadEvent: BROWSER_LOAD_EVENT,\n};\n\ntype EndEventName =\n | 'domainLookupStart'\n | 'domainLookupEnd'\n | 'unloadEventEnd'\n | 'redirectEnd'\n | 'connectEnd'\n | 'domContentLoadedEventEnd'\n | 'loadEventEnd';\n\n/** Create performance navigation related spans */\nfunction _addPerformanceNavigationTiming(\n span: Span,\n entry: PerformanceNavigationTiming,\n event: StartEventName,\n timeOrigin: number,\n): void {\n const eventEnd = _getEndPropertyNameForNavigationTiming(event) satisfies keyof PerformanceNavigationTiming;\n const end = entry[eventEnd];\n const start = entry[`${event}Start`];\n if (!start || !end) {\n return;\n }\n startAndEndSpan(span, timeOrigin + msToSec(start), timeOrigin + msToSec(end), {\n name: entry.name,\n attributes: {\n [SENTRY_OP]: NAVIGATION_TIMING_SPAN_OPS[event],\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',\n ...(event === 'redirect' && entry.redirectCount != null ? { 'http.redirect_count': entry.redirectCount } : {}),\n },\n });\n}\n\nfunction _getEndPropertyNameForNavigationTiming(event: StartEventName): EndEventName {\n if (event === 'secureConnection') {\n return 'connectEnd';\n }\n if (event === 'fetch') {\n return 'domainLookupStart';\n }\n return `${event}End`;\n}\n\n/** Create request and response related spans */\nfunction _addRequest(span: Span, entry: PerformanceNavigationTiming, timeOrigin: number): void {\n const requestStartTimestamp = timeOrigin + msToSec(entry.requestStart);\n const responseEndTimestamp = timeOrigin + msToSec(entry.responseEnd);\n const responseStartTimestamp = timeOrigin + msToSec(entry.responseStart);\n if (entry.responseEnd) {\n // It is possible that we are collecting these metrics when the page hasn't finished loading yet, for example when the HTML slowly streams in.\n // In this case, ie. when the document request hasn't finished yet, `entry.responseEnd` will be 0.\n // In order not to produce faulty spans, where the end timestamp is before the start timestamp, we will only collect\n // these spans when the responseEnd value is available. The backend (Relay) would drop the entire span if it contained faulty spans.\n startAndEndSpan(span, requestStartTimestamp, responseEndTimestamp, {\n name: entry.name,\n attributes: {\n [SENTRY_OP]: BROWSER_REQUEST,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',\n },\n });\n\n startAndEndSpan(span, responseStartTimestamp, responseEndTimestamp, {\n name: entry.name,\n attributes: {\n [SENTRY_OP]: BROWSER_RESPONSE,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',\n },\n });\n }\n}\n\n/**\n * Create resource-related spans.\n * Exported only for tests.\n */\nexport function _addResourceSpans(\n span: Span,\n entry: PerformanceResourceTiming,\n resourceUrl: string,\n startTime: number,\n duration: number,\n timeOrigin: number,\n ignoredResourceSpanOps?: Array<string>,\n spanStreamingEnabled?: boolean,\n): void {\n // we already instrument based on fetch and xhr, so we don't need to\n // duplicate spans here.\n if (entry.initiatorType === 'xmlhttprequest' || entry.initiatorType === 'fetch') {\n return;\n }\n\n const op = entry.initiatorType ? `resource.${entry.initiatorType}` : RESOURCE_OTHER;\n if (ignoredResourceSpanOps?.includes(op)) {\n return;\n }\n\n const attributes: SpanAttributes = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.resource.browser.metrics',\n };\n\n const parsedUrl = parseUrl(resourceUrl);\n\n if (parsedUrl.protocol) {\n attributes[URL_SCHEME] = parsedUrl.protocol.split(':').pop(); // the protocol returned by parseUrl includes a :, but OTEL spec does not, so we remove it.\n }\n\n // `host` is the URL authority, so it can carry userinfo, which doesn't belong on either attribute.\n const host = parsedUrl.host?.replace(/^.*@/, '');\n\n if (host) {\n attributes[SERVER_ADDRESS] = host;\n }\n\n // Unlike `server.address`, `url.domain` excludes the port.\n const domain = host?.replace(/:\\d+$/, '');\n\n if (domain) {\n attributes[URL_DOMAIN] = domain;\n }\n\n attributes[HTTP_REQUEST_SAME_ORIGIN] = resourceUrl.includes(WINDOW.location.origin);\n\n attributes[URL_FULL] = filterCollectedUrl(resourceUrl);\n\n _setResourceRequestAttributes(entry, attributes, [\n // https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStatus\n ['responseStatus', HTTP_RESPONSE_STATUS_CODE],\n\n ['transferSize', HTTP_RESPONSE_SIZE],\n ['encodedBodySize', HTTP_RESPONSE_BODY_SIZE],\n ['decodedBodySize', 'http.response.body.decoded_size'],\n\n // https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/renderBlockingStatus\n ['renderBlockingStatus', 'resource.render_blocking_status'],\n\n // https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/deliveryType\n ['deliveryType', 'http.response_delivery_type'],\n ]);\n\n const attributesWithResourceTiming: SpanAttributes = { ...attributes, ...resourceTimingToSpanAttributes(entry) };\n\n const startTimestamp = timeOrigin + startTime;\n const endTimestamp = startTimestamp + duration;\n\n startAndEndSpan(span, startTimestamp, endTimestamp, {\n // With span streaming, span names have to be low cardinality, so we can't fall back to the URL.\n name: spanStreamingEnabled\n ? domain || RESOURCE_SPAN_NAME_FALLBACK\n : resourceUrl.replace(WINDOW.location.origin, ''),\n op,\n attributes: attributesWithResourceTiming,\n });\n}\n\n/**\n * Capture the information of the user agent.\n * TODO v11: Remove non-span-streaming attributes and measurements once we removed transactions\n */\nfunction _trackNavigator(span: Span, spanStreamingEnabled: boolean | undefined): void {\n const navigator = WINDOW.navigator as null | (Navigator & NavigatorNetworkInformation & NavigatorDeviceMemory);\n if (!navigator) {\n return;\n }\n\n // track network connectivity\n const connection = navigator.connection;\n if (connection) {\n if (connection.effectiveType) {\n span.setAttribute(\n spanStreamingEnabled ? NETWORK_CONNECTION_EFFECTIVE_TYPE : 'effectiveConnectionType',\n connection.effectiveType,\n );\n }\n\n if (connection.type) {\n span.setAttribute(spanStreamingEnabled ? NETWORK_CONNECTION_TYPE : 'connectionType', connection.type);\n }\n\n if (isMeasurementValue(connection.rtt)) {\n if (spanStreamingEnabled) {\n span.setAttribute(NETWORK_CONNECTION_RTT, connection.rtt);\n } else if (spanToJSON(span).attributes[SENTRY_OP] === 'pageload') {\n // Measurements are only recorded on the pageload span, matching the historical\n // behavior where `connection.rtt` was only flushed for pageload transactions.\n setMeasurement('connection.rtt', connection.rtt, 'millisecond');\n }\n }\n }\n\n if (isMeasurementValue(navigator.deviceMemory)) {\n if (spanStreamingEnabled) {\n span.setAttribute('device.memory.estimated_capacity', navigator.deviceMemory);\n } else {\n span.setAttribute('deviceMemory', `${navigator.deviceMemory} GB`);\n }\n }\n\n if (isMeasurementValue(navigator.hardwareConcurrency)) {\n if (spanStreamingEnabled) {\n span.setAttribute('device.processor_count', navigator.hardwareConcurrency);\n } else {\n span.setAttribute('hardwareConcurrency', String(navigator.hardwareConcurrency));\n }\n }\n}\n\ntype ExperimentalResourceTimingProperty =\n | 'renderBlockingStatus'\n | 'deliveryType'\n // For some reason, TS during build, errors on `responseStatus` not being a property of\n // PerformanceResourceTiming while it actually is. Hence, we're adding it here.\n // Perhaps because response status is not yet available in Webkit/Safari.\n // https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStatus\n | 'responseStatus';\n\n/**\n * Use this to set any attributes we can take directly form the PerformanceResourceTiming entry.\n *\n * This is just a mapping function for entry->attribute to keep bundle-size minimal.\n * Experimental properties are also accepted (see {@link ExperimentalResourceTimingProperty}).\n * Assumes that all entry properties might be undefined for browser-specific differences.\n * Only accepts string and number values for now and also sets 0-values.\n */\nexport function _setResourceRequestAttributes(\n entry: Partial<PerformanceResourceTiming> & Partial<Record<ExperimentalResourceTimingProperty, number | string>>,\n attributes: SpanAttributes,\n properties: [keyof PerformanceResourceTiming | ExperimentalResourceTimingProperty, string][],\n): void {\n properties.forEach(([entryKey, attributeKey]) => {\n const entryVal = entry[entryKey];\n if (\n entryVal != null &&\n ((typeof entryVal === 'number' && entryVal < MAX_INT_AS_BYTES) || typeof entryVal === 'string')\n ) {\n attributes[attributeKey] = entryVal;\n }\n });\n}\n"],"names":["addPerformanceInstrumentationHandler","getActiveSpan","spanToJSON","msToSec","browserPerformanceTimeOrigin","SENTRY_OP","startAndEndSpan","UI_LONG_TASK","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","attributes","CODE_FILE_PATH","CODE_FUNCTION_NAME","UI_LONG_ANIMATION_FRAME","getBrowserPerformanceAPI","BROWSER_PAINT","BROWSER_TLS_SSL","BROWSER_CACHE","BROWSER_DNS","BROWSER_UNLOAD_EVENT","BROWSER_REDIRECT","BROWSER_CONNECT","BROWSER_DOM_CONTENT_LOADED_EVENT","BROWSER_LOAD_EVENT","BROWSER_REQUEST","BROWSER_RESPONSE","op","RESOURCE_OTHER","parseUrl","URL_SCHEME","SERVER_ADDRESS","URL_DOMAIN","HTTP_REQUEST_SAME_ORIGIN","WINDOW","URL_FULL","filterCollectedUrl","HTTP_RESPONSE_STATUS_CODE","HTTP_RESPONSE_SIZE","HTTP_RESPONSE_BODY_SIZE","resourceTimingToSpanAttributes","RESOURCE_SPAN_NAME_FALLBACK","NETWORK_CONNECTION_EFFECTIVE_TYPE","NETWORK_CONNECTION_TYPE","isMeasurementValue","NETWORK_CONNECTION_RTT","setMeasurement"],"mappings":";;;;;;;;;;AA0FA,MAAM,gBAAA,GAAmB,UAAA;AAEzB,IAAI,kBAAA,GAA6B,CAAA;AAK1B,SAAS,sBAAA,GAA+B;AAC7C,EAAAA,wDAAA,CAAqC,UAAA,EAAY,CAAC,EAAE,OAAA,EAAQ,KAAM;AAChE,IAAA,MAAM,SAASC,kBAAA,EAAc;AAC7B,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,EAAE,UAAA,EAAY,gBAAA,EAAkB,iBAAiB,oBAAA,EAAqB,GAAIC,gBAAW,MAAM,CAAA;AAEjG,IAAA,KAAA,MAAW,SAAS,OAAA,EAAS;AAC3B,MAAA,MAAM,SAAA,GAAYC,aAAA,CAASC,iCAAA,EAA6B,GAAe,MAAM,SAAS,CAAA;AACtF,MAAA,MAAM,QAAA,GAAWD,aAAA,CAAQ,KAAA,CAAM,QAAQ,CAAA;AAEvC,MAAA,IAAI,iBAAiBE,oBAAS,CAAA,KAAM,YAAA,IAAgB,oBAAA,IAAwB,YAAY,oBAAA,EAAsB;AAK5G,QAAA;AAAA,MACF;AAEA,MAAAC,qBAAA,CAAgB,MAAA,EAAQ,SAAA,EAAW,SAAA,GAAY,QAAA,EAAU;AAAA,QACvD,IAAA,EAAM,wBAAA;AAAA,QACN,EAAA,EAAIC,eAAA;AAAA,QACJ,U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AACxB,MAAA,IAAA,CAAK,YAAA,CAAa,wBAAA,EAA0B,SAAA,CAAU,mBAAmB,CAAA;AAAA,IAC3E,CAAA,MAAO;AACL,MAAA,IAAA,CAAK,YAAA,CAAa,qBAAA,EAAuB,MAAA,CAAO,SAAA,CAAU,mBAAmB,CAAC,CAAA;AAAA,IAChF;AAAA,EACF;AACF;AAmBO,SAAS,6BAAA,CACd,KAAA,EACA,UAAA,EACA,UAAA,EACM;AACN,EAAA,UAAA,CAAW,OAAA,CAAQ,CAAC,CAAC,QAAA,EAAU,YAAY,CAAA,KAAM;AAC/C,IAAA,MAAM,QAAA,GAAW,MAAM,QAAQ,CAAA;AAC/B,IAAA,IACE,QAAA,IAAY,SACV,OAAO,QAAA,KAAa,YAAY,QAAA,GAAW,gBAAA,IAAqB,OAAO,QAAA,KAAa,QAAA,CAAA,EACtF;AACA,MAAA,UAAA,CAAW,YAAY,CAAA,GAAI,QAAA;AAAA,IAC7B;AAAA,EACF,CAAC,CAAA;AACH;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"entries.js","sources":["../../../src/performance/entries.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport type { Span, SpanAttributes } from '@sentry/core';\nimport {\n browserPerformanceTimeOrigin,\n getActiveSpan,\n parseUrl,\n RESOURCE_SPAN_NAME_FALLBACK,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n setMeasurement,\n spanToJSON,\n filterCollectedUrl,\n} from '@sentry/core';\nimport {\n CODE_FILE_PATH,\n CODE_FUNCTION_NAME,\n HTTP_REQUEST_SAME_ORIGIN,\n HTTP_RESPONSE_BODY_SIZE,\n HTTP_RESPONSE_SIZE,\n HTTP_RESPONSE_STATUS_CODE,\n NETWORK_CONNECTION_EFFECTIVE_TYPE,\n NETWORK_CONNECTION_RTT,\n NETWORK_CONNECTION_TYPE,\n SENTRY_OP,\n SERVER_ADDRESS,\n URL_DOMAIN,\n URL_FULL,\n URL_SCHEME,\n} from '@sentry/conventions/attributes';\nimport {\n BROWSER_CACHE,\n BROWSER_CONNECT,\n BROWSER_DNS,\n BROWSER_DOM_CONTENT_LOADED_EVENT,\n BROWSER_LOAD_EVENT,\n BROWSER_PAINT,\n BROWSER_REDIRECT,\n BROWSER_REQUEST,\n BROWSER_RESPONSE,\n BROWSER_TLS_SSL,\n BROWSER_UNLOAD_EVENT,\n RESOURCE_OTHER,\n UI_LONG_ANIMATION_FRAME,\n UI_LONG_TASK,\n} from '@sentry/conventions/op';\nimport {\n addPerformanceInstrumentationHandler,\n type PerformanceLongAnimationFrameTiming,\n} from '../instrumentation/performanceObserver';\nimport { WINDOW } from '../types';\nimport { resourceTimingToSpanAttributes } from './resourceTiming';\nimport { getBrowserPerformanceAPI, isMeasurementValue, msToSec, startAndEndSpan } from './utils';\n\ninterface NavigatorNetworkInformation {\n readonly connection?: NetworkInformation;\n}\n\n// http://wicg.github.io/netinfo/#connection-types\ntype ConnectionType = 'bluetooth' | 'cellular' | 'ethernet' | 'mixed' | 'none' | 'other' | 'unknown' | 'wifi' | 'wimax';\n\n// http://wicg.github.io/netinfo/#effectiveconnectiontype-enum\ntype EffectiveConnectionType = '2g' | '3g' | '4g' | 'slow-2g';\n\n// http://wicg.github.io/netinfo/#dom-megabit\ntype Megabit = number;\n// http://wicg.github.io/netinfo/#dom-millisecond\ntype Millisecond = number;\n\n// http://wicg.github.io/netinfo/#networkinformation-interface\ninterface NetworkInformation extends EventTarget {\n // http://wicg.github.io/netinfo/#type-attribute\n readonly type?: ConnectionType;\n // http://wicg.github.io/netinfo/#effectivetype-attribute\n readonly effectiveType?: EffectiveConnectionType;\n // http://wicg.github.io/netinfo/#downlinkmax-attribute\n readonly downlinkMax?: Megabit;\n // http://wicg.github.io/netinfo/#downlink-attribute\n readonly downlink?: Megabit;\n // http://wicg.github.io/netinfo/#rtt-attribute\n readonly rtt?: Millisecond;\n // http://wicg.github.io/netinfo/#savedata-attribute\n readonly saveData?: boolean;\n // http://wicg.github.io/netinfo/#handling-changes-to-the-underlying-connection\n onchange?: EventListener;\n}\n\n// https://w3c.github.io/device-memory/#sec-device-memory-js-api\ninterface NavigatorDeviceMemory {\n readonly deviceMemory?: number;\n}\n\nconst MAX_INT_AS_BYTES = 2147483647;\n\nlet _performanceCursor: number = 0;\n\n/**\n * Start tracking long tasks.\n */\nexport function startTrackingLongTasks(): void {\n addPerformanceInstrumentationHandler('longtask', ({ entries }) => {\n const parent = getActiveSpan();\n if (!parent) {\n return;\n }\n\n const { attributes: parentAttributes, start_timestamp: parentStartTimestamp } = spanToJSON(parent);\n\n for (const entry of entries) {\n const startTime = msToSec((browserPerformanceTimeOrigin() as number) + entry.startTime);\n const duration = msToSec(entry.duration);\n\n if (parentAttributes[SENTRY_OP] === 'navigation' && parentStartTimestamp && startTime < parentStartTimestamp) {\n // Skip adding a span if the long task started before the navigation started.\n // `startAndEndSpan` will otherwise adjust the parent's start time to the span's start\n // time, potentially skewing the duration of the actual navigation as reported via our\n // routing instrumentations\n continue;\n }\n\n startAndEndSpan(parent, startTime, startTime + duration, {\n name: 'Main UI thread blocked',\n op: UI_LONG_TASK,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',\n },\n });\n }\n });\n}\n\n/**\n * Start tracking long animation frames.\n */\nexport function startTrackingLongAnimationFrames(): void {\n // NOTE: the current web-vitals version (3.5.2) does not support long-animation-frame, so\n // we directly observe `long-animation-frame` events instead of through the web-vitals\n // `observe` helper function.\n const observer = new PerformanceObserver(list => {\n const parent = getActiveSpan();\n if (!parent) {\n return;\n }\n for (const entry of list.getEntries() as PerformanceLongAnimationFrameTiming[]) {\n if (!entry.scripts[0]) {\n continue;\n }\n\n const startTime = msToSec((browserPerformanceTimeOrigin() as number) + entry.startTime);\n\n const {\n start_timestamp: parentStartTimestamp,\n attributes: { [SENTRY_OP]: parentOp },\n } = spanToJSON(parent);\n\n if (parentOp === 'navigation' && parentStartTimestamp && startTime < parentStartTimestamp) {\n // Skip adding the span if the long animation frame started before the navigation started.\n // `startAndEndSpan` will otherwise adjust the parent's start time to the span's start\n // time, potentially skewing the duration of the actual navigation as reported via our\n // routing instrumentations\n continue;\n }\n const duration = msToSec(entry.duration);\n\n const attributes: SpanAttributes = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',\n };\n\n const initialScript = entry.scripts[0];\n const { invoker, invokerType, sourceURL, sourceFunctionName, sourceCharPosition } = initialScript;\n attributes['browser.script.invoker'] = invoker;\n attributes['browser.script.invoker_type'] = invokerType;\n if (sourceURL) {\n attributes[CODE_FILE_PATH] = sourceURL;\n }\n if (sourceFunctionName) {\n attributes[CODE_FUNCTION_NAME] = sourceFunctionName;\n }\n if (sourceCharPosition !== -1) {\n attributes['browser.script.source_char_position'] = sourceCharPosition;\n }\n\n startAndEndSpan(parent, startTime, startTime + duration, {\n name: 'Main UI thread blocked',\n op: UI_LONG_ANIMATION_FRAME,\n attributes,\n });\n }\n });\n\n observer.observe({ type: 'long-animation-frame', buffered: true });\n}\n\ninterface AddPerformanceEntriesOptions {\n /**\n * Resource spans with `op`s matching strings in the array will not be emitted.\n *\n * Default: []\n */\n ignoreResourceSpans: Array<'resource.script' | 'resource.css' | 'resource.img' | 'resource.other' | string>;\n\n /**\n * Whether span streaming is enabled.\n */\n spanStreamingEnabled?: boolean;\n}\n\n/** Add performance related spans to a transaction */\nexport function addPerformanceEntries(span: Span, options: AddPerformanceEntriesOptions): void {\n const performance = getBrowserPerformanceAPI();\n const origin = browserPerformanceTimeOrigin();\n if (!performance?.getEntries || !origin) {\n // Gatekeeper if performance API not available\n return;\n }\n\n const { spanStreamingEnabled, ignoreResourceSpans } = options;\n\n const timeOrigin = msToSec(origin);\n\n const performanceEntries = performance.getEntries();\n\n const { attributes, start_timestamp: transactionStartTime } = spanToJSON(span);\n\n performanceEntries.slice(_performanceCursor).forEach(entry => {\n const startTime = msToSec(entry.startTime);\n const duration = msToSec(\n // Inexplicably, Chrome sometimes emits a negative duration. We need to work around this.\n // There is a SO post attempting to explain this, but it leaves one with open questions: https://stackoverflow.com/questions/23191918/peformance-getentries-and-negative-duration-display\n // The way we clamp the value is probably not accurate, since we have observed this happen for things that may take a while to load, like for example the replay worker.\n // TODO: Investigate why this happens and how to properly mitigate. For now, this is a workaround to prevent transactions being dropped due to negative duration spans.\n Math.max(0, entry.duration),\n );\n\n if (\n attributes[SENTRY_OP] === 'navigation' &&\n transactionStartTime &&\n timeOrigin + startTime < transactionStartTime\n ) {\n return;\n }\n\n switch (entry.entryType) {\n case 'navigation': {\n _addNavigationSpans(span, entry as PerformanceNavigationTiming, timeOrigin);\n break;\n }\n case 'paint': {\n _addPaintSpan(span, entry, startTime, duration, timeOrigin);\n break;\n }\n case 'resource': {\n _addResourceSpans(\n span,\n entry as PerformanceResourceTiming,\n entry.name,\n startTime,\n duration,\n timeOrigin,\n ignoreResourceSpans,\n spanStreamingEnabled,\n );\n break;\n }\n // Ignore other entry types.\n }\n });\n\n _performanceCursor = Math.max(performanceEntries.length - 1, 0);\n\n _trackNavigator(span, spanStreamingEnabled);\n}\n\n/** Create a span for a browser paint performance entry. */\nfunction _addPaintSpan(\n span: Span,\n entry: PerformanceEntry,\n startTime: number,\n duration: number,\n timeOrigin: number,\n): void {\n const startTimestamp = timeOrigin + startTime;\n\n startAndEndSpan(span, startTimestamp, startTimestamp + duration, {\n name: entry.name,\n attributes: {\n [SENTRY_OP]: BROWSER_PAINT,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.resource.browser.metrics',\n },\n });\n}\n\n/**\n * Instrument navigation entries\n * exported only for tests\n */\nexport function _addNavigationSpans(span: Span, entry: PerformanceNavigationTiming, timeOrigin: number): void {\n _addPerformanceNavigationTiming(span, entry, 'unloadEvent', timeOrigin);\n _addPerformanceNavigationTiming(span, entry, 'redirect', timeOrigin);\n _addPerformanceNavigationTiming(span, entry, 'domContentLoadedEvent', timeOrigin);\n _addPerformanceNavigationTiming(span, entry, 'loadEvent', timeOrigin);\n _addPerformanceNavigationTiming(span, entry, 'connect', timeOrigin);\n _addPerformanceNavigationTiming(span, entry, 'secureConnection', timeOrigin);\n _addPerformanceNavigationTiming(span, entry, 'fetch', timeOrigin);\n _addPerformanceNavigationTiming(span, entry, 'domainLookup', timeOrigin);\n\n _addRequest(span, entry, timeOrigin);\n}\n\ntype StartEventName =\n | 'secureConnection'\n | 'fetch'\n | 'domainLookup'\n | 'unloadEvent'\n | 'redirect'\n | 'connect'\n | 'domContentLoadedEvent'\n | 'loadEvent';\n\nconst NAVIGATION_TIMING_SPAN_OPS: Record<StartEventName, string> = {\n secureConnection: BROWSER_TLS_SSL,\n fetch: BROWSER_CACHE,\n domainLookup: BROWSER_DNS,\n unloadEvent: BROWSER_UNLOAD_EVENT,\n redirect: BROWSER_REDIRECT,\n connect: BROWSER_CONNECT,\n domContentLoadedEvent: BROWSER_DOM_CONTENT_LOADED_EVENT,\n loadEvent: BROWSER_LOAD_EVENT,\n};\n\ntype EndEventName =\n | 'domainLookupStart'\n | 'domainLookupEnd'\n | 'unloadEventEnd'\n | 'redirectEnd'\n | 'connectEnd'\n | 'domContentLoadedEventEnd'\n | 'loadEventEnd';\n\n/** Create performance navigation related spans */\nfunction _addPerformanceNavigationTiming(\n span: Span,\n entry: PerformanceNavigationTiming,\n event: StartEventName,\n timeOrigin: number,\n): void {\n const eventEnd = _getEndPropertyNameForNavigationTiming(event) satisfies keyof PerformanceNavigationTiming;\n const end = entry[eventEnd];\n const start = entry[`${event}Start`];\n if (!start || !end) {\n return;\n }\n startAndEndSpan(span, timeOrigin + msToSec(start), timeOrigin + msToSec(end), {\n name: entry.name,\n attributes: {\n [SENTRY_OP]: NAVIGATION_TIMING_SPAN_OPS[event],\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',\n ...(event === 'redirect' && entry.redirectCount != null ? { 'http.redirect_count': entry.redirectCount } : {}),\n },\n });\n}\n\nfunction _getEndPropertyNameForNavigationTiming(event: StartEventName): EndEventName {\n if (event === 'secureConnection') {\n return 'connectEnd';\n }\n if (event === 'fetch') {\n return 'domainLookupStart';\n }\n return `${event}End`;\n}\n\n/** Create request and response related spans */\nfunction _addRequest(span: Span, entry: PerformanceNavigationTiming, timeOrigin: number): void {\n const requestStartTimestamp = timeOrigin + msToSec(entry.requestStart);\n const responseEndTimestamp = timeOrigin + msToSec(entry.responseEnd);\n const responseStartTimestamp = timeOrigin + msToSec(entry.responseStart);\n if (entry.responseEnd) {\n // It is possible that we are collecting these metrics when the page hasn't finished loading yet, for example when the HTML slowly streams in.\n // In this case, ie. when the document request hasn't finished yet, `entry.responseEnd` will be 0.\n // In order not to produce faulty spans, where the end timestamp is before the start timestamp, we will only collect\n // these spans when the responseEnd value is available. The backend (Relay) would drop the entire span if it contained faulty spans.\n startAndEndSpan(span, requestStartTimestamp, responseEndTimestamp, {\n name: entry.name,\n attributes: {\n [SENTRY_OP]: BROWSER_REQUEST,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',\n },\n });\n\n startAndEndSpan(span, responseStartTimestamp, responseEndTimestamp, {\n name: entry.name,\n attributes: {\n [SENTRY_OP]: BROWSER_RESPONSE,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',\n },\n });\n }\n}\n\n/**\n * Create resource-related spans.\n * Exported only for tests.\n */\nexport function _addResourceSpans(\n span: Span,\n entry: PerformanceResourceTiming,\n resourceUrl: string,\n startTime: number,\n duration: number,\n timeOrigin: number,\n ignoredResourceSpanOps?: Array<string>,\n spanStreamingEnabled?: boolean,\n): void {\n // we already instrument based on fetch and xhr, so we don't need to\n // duplicate spans here.\n if (entry.initiatorType === 'xmlhttprequest' || entry.initiatorType === 'fetch') {\n return;\n }\n\n const op = entry.initiatorType ? `resource.${entry.initiatorType}` : RESOURCE_OTHER;\n if (ignoredResourceSpanOps?.includes(op)) {\n return;\n }\n\n const attributes: SpanAttributes = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.resource.browser.metrics',\n };\n\n const parsedUrl = parseUrl(resourceUrl);\n\n if (parsedUrl.protocol) {\n attributes[URL_SCHEME] = parsedUrl.protocol.split(':').pop(); // the protocol returned by parseUrl includes a :, but OTEL spec does not, so we remove it.\n }\n\n // `host` is the URL authority, so it can carry userinfo, which doesn't belong on either attribute.\n const host = parsedUrl.host?.replace(/^.*@/, '');\n\n if (host) {\n attributes[SERVER_ADDRESS] = host;\n }\n\n // Unlike `server.address`, `url.domain` excludes the port.\n const domain = host?.replace(/:\\d+$/, '');\n\n if (domain) {\n attributes[URL_DOMAIN] = domain;\n }\n\n attributes[HTTP_REQUEST_SAME_ORIGIN] = resourceUrl.includes(WINDOW.location.origin);\n\n attributes[URL_FULL] = filterCollectedUrl(resourceUrl);\n\n _setResourceRequestAttributes(entry, attributes, [\n // https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStatus\n ['responseStatus', HTTP_RESPONSE_STATUS_CODE],\n\n ['transferSize', HTTP_RESPONSE_SIZE],\n ['encodedBodySize', HTTP_RESPONSE_BODY_SIZE],\n ['decodedBodySize', 'http.response.body.decoded_size'],\n\n // https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/renderBlockingStatus\n ['renderBlockingStatus', 'resource.render_blocking_status'],\n\n // https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/deliveryType\n ['deliveryType', 'http.response_delivery_type'],\n ]);\n\n const attributesWithResourceTiming: SpanAttributes = { ...attributes, ...resourceTimingToSpanAttributes(entry) };\n\n const startTimestamp = timeOrigin + startTime;\n const endTimestamp = startTimestamp + duration;\n\n startAndEndSpan(span, startTimestamp, endTimestamp, {\n // With span streaming, span names have to be low cardinality, so we can't fall back to the URL.\n name: spanStreamingEnabled\n ? domain || RESOURCE_SPAN_NAME_FALLBACK\n : resourceUrl.replace(WINDOW.location.origin, ''),\n op,\n attributes: attributesWithResourceTiming,\n });\n}\n\n/**\n * Capture the information of the user agent.\n * TODO(v12): Remove non-span-streaming attributes and measurements once the static trace lifecycle is removed\n */\nfunction _trackNavigator(span: Span, spanStreamingEnabled: boolean | undefined): void {\n const navigator = WINDOW.navigator as null | (Navigator & NavigatorNetworkInformation & NavigatorDeviceMemory);\n if (!navigator) {\n return;\n }\n\n // track network connectivity\n const connection = navigator.connection;\n if (connection) {\n if (connection.effectiveType) {\n span.setAttribute(\n spanStreamingEnabled ? NETWORK_CONNECTION_EFFECTIVE_TYPE : 'effectiveConnectionType',\n connection.effectiveType,\n );\n }\n\n if (connection.type) {\n span.setAttribute(spanStreamingEnabled ? NETWORK_CONNECTION_TYPE : 'connectionType', connection.type);\n }\n\n if (isMeasurementValue(connection.rtt)) {\n if (spanStreamingEnabled) {\n span.setAttribute(NETWORK_CONNECTION_RTT, connection.rtt);\n } else if (spanToJSON(span).attributes[SENTRY_OP] === 'pageload') {\n // Measurements are only recorded on the pageload span, matching the historical\n // behavior where `connection.rtt` was only flushed for pageload transactions.\n setMeasurement('connection.rtt', connection.rtt, 'millisecond');\n }\n }\n }\n\n if (isMeasurementValue(navigator.deviceMemory)) {\n if (spanStreamingEnabled) {\n span.setAttribute('device.memory.estimated_capacity', navigator.deviceMemory);\n } else {\n span.setAttribute('deviceMemory', `${navigator.deviceMemory} GB`);\n }\n }\n\n if (isMeasurementValue(navigator.hardwareConcurrency)) {\n if (spanStreamingEnabled) {\n span.setAttribute('device.processor_count', navigator.hardwareConcurrency);\n } else {\n span.setAttribute('hardwareConcurrency', String(navigator.hardwareConcurrency));\n }\n }\n}\n\ntype ExperimentalResourceTimingProperty =\n | 'renderBlockingStatus'\n | 'deliveryType'\n // For some reason, TS during build, errors on `responseStatus` not being a property of\n // PerformanceResourceTiming while it actually is. Hence, we're adding it here.\n // Perhaps because response status is not yet available in Webkit/Safari.\n // https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStatus\n | 'responseStatus';\n\n/**\n * Use this to set any attributes we can take directly form the PerformanceResourceTiming entry.\n *\n * This is just a mapping function for entry->attribute to keep bundle-size minimal.\n * Experimental properties are also accepted (see {@link ExperimentalResourceTimingProperty}).\n * Assumes that all entry properties might be undefined for browser-specific differences.\n * Only accepts string and number values for now and also sets 0-values.\n */\nexport function _setResourceRequestAttributes(\n entry: Partial<PerformanceResourceTiming> & Partial<Record<ExperimentalResourceTimingProperty, number | string>>,\n attributes: SpanAttributes,\n properties: [keyof PerformanceResourceTiming | ExperimentalResourceTimingProperty, string][],\n): void {\n properties.forEach(([entryKey, attributeKey]) => {\n const entryVal = entry[entryKey];\n if (\n entryVal != null &&\n ((typeof entryVal === 'number' && entryVal < MAX_INT_AS_BYTES) || typeof entryVal === 'string')\n ) {\n attributes[attributeKey] = entryVal;\n }\n });\n}\n"],"names":["addPerformanceInstrumentationHandler","getActiveSpan","spanToJSON","msToSec","browserPerformanceTimeOrigin","SENTRY_OP","startAndEndSpan","UI_LONG_TASK","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","attributes","CODE_FILE_PATH","CODE_FUNCTION_NAME","UI_LONG_ANIMATION_FRAME","getBrowserPerformanceAPI","BROWSER_PAINT","BROWSER_TLS_SSL","BROWSER_CACHE","BROWSER_DNS","BROWSER_UNLOAD_EVENT","BROWSER_REDIRECT","BROWSER_CONNECT","BROWSER_DOM_CONTENT_LOADED_EVENT","BROWSER_LOAD_EVENT","BROWSER_REQUEST","BROWSER_RESPONSE","op","RESOURCE_OTHER","parseUrl","URL_SCHEME","SERVER_ADDRESS","URL_DOMAIN","HTTP_REQUEST_SAME_ORIGIN","WINDOW","URL_FULL","filterCollectedUrl","HTTP_RESPONSE_STATUS_CODE","HTTP_RESPONSE_SIZE","HTTP_RESPONSE_BODY_SIZE","resourceTimingToSpanAttributes","RESOURCE_SPAN_NAME_FALLBACK","NETWORK_CONNECTION_EFFECTIVE_TYPE","NETWORK_CONNECTION_TYPE","isMeasurementValue","NETWORK_CONNECTION_RTT","setMeasurement"],"mappings":";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W,MAAM,QAAQ,CAAA;AAC/B,IAAA,IACE,QAAA,IAAY,SACV,OAAO,QAAA,KAAa,YAAY,QAAA,GAAW,gBAAA,IAAqB,OAAO,QAAA,KAAa,QAAA,CAAA,EACtF;AACA,MAAA,UAAA,CAAW,YAAY,CAAA,GAAI,QAAA;AAAA,IAC7B;AAAA,EACF,CAAC,CAAA;AACH;;;;;;;;;"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const core = require('@sentry/core');
|
|
4
|
+
const browser = require('@sentry/core/browser');
|
|
5
|
+
const attributes = require('@sentry/conventions/attributes');
|
|
6
|
+
const types = require('../types.js');
|
|
7
|
+
|
|
8
|
+
const BROWSER_NAVIGATION_TYPES = {
|
|
9
|
+
reload: "reload",
|
|
10
|
+
prerender: "prerender",
|
|
11
|
+
"back-forward-cache": "bfcache",
|
|
12
|
+
"soft-navigation": "soft-navigation"
|
|
13
|
+
};
|
|
14
|
+
function toBrowserNavigationType(navigationType) {
|
|
15
|
+
return BROWSER_NAVIGATION_TYPES[navigationType] ?? "navigate";
|
|
16
|
+
}
|
|
17
|
+
function _emitWebVitalSpan(options) {
|
|
18
|
+
const {
|
|
19
|
+
name,
|
|
20
|
+
op,
|
|
21
|
+
origin,
|
|
22
|
+
metricName,
|
|
23
|
+
value,
|
|
24
|
+
attributes: passedAttributes,
|
|
25
|
+
parentSpan,
|
|
26
|
+
reportEvent,
|
|
27
|
+
startTime,
|
|
28
|
+
endTime,
|
|
29
|
+
standalone,
|
|
30
|
+
softNavigationId,
|
|
31
|
+
navigationType
|
|
32
|
+
} = options;
|
|
33
|
+
const segmentSpan = parentSpan && core.getRootSpan(parentSpan);
|
|
34
|
+
const segmentName = segmentSpan ? core.spanToJSON(segmentSpan).name : core.getCurrentScope().getScopeData().transactionName;
|
|
35
|
+
const attributes$1 = {
|
|
36
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: origin,
|
|
37
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
|
|
38
|
+
[core.SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME]: 0,
|
|
39
|
+
[`browser.web_vital.${metricName}.value`]: value,
|
|
40
|
+
// oxlint-disable-next-line typescript-eslint/no-deprecated
|
|
41
|
+
[attributes.SENTRY_TRANSACTION]: segmentName,
|
|
42
|
+
[attributes.SENTRY_SEGMENT_NAME]: segmentName,
|
|
43
|
+
// Web vital score calculation relies on the user agent
|
|
44
|
+
[attributes.USER_AGENT_ORIGINAL]: types.WINDOW.navigator?.userAgent,
|
|
45
|
+
...passedAttributes
|
|
46
|
+
};
|
|
47
|
+
if (parentSpan && core.spanToJSON(parentSpan).attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_OP] === "pageload") {
|
|
48
|
+
attributes$1["sentry.pageload.span_id"] = parentSpan.spanContext().spanId;
|
|
49
|
+
}
|
|
50
|
+
if (reportEvent) {
|
|
51
|
+
attributes$1[`browser.web_vital.${metricName}.report_event`] = reportEvent;
|
|
52
|
+
}
|
|
53
|
+
if (softNavigationId != null) {
|
|
54
|
+
attributes$1[attributes.BROWSER_NAVIGATION_ID] = softNavigationId;
|
|
55
|
+
}
|
|
56
|
+
if (navigationType) {
|
|
57
|
+
attributes$1[attributes.BROWSER_NAVIGATION_TYPE] = toBrowserNavigationType(navigationType);
|
|
58
|
+
}
|
|
59
|
+
if (standalone) {
|
|
60
|
+
Object.assign(attributes$1, getReplayAttributes());
|
|
61
|
+
}
|
|
62
|
+
const span = browser.startInactiveSpan({
|
|
63
|
+
name,
|
|
64
|
+
attributes: attributes$1,
|
|
65
|
+
startTime,
|
|
66
|
+
parentSpan,
|
|
67
|
+
// oxlint-disable-next-line typescript/no-deprecated -- intentional during the v1/v2 transition; see the TODO(standalone) above
|
|
68
|
+
experimental: standalone ? { standalone: true } : void 0
|
|
69
|
+
});
|
|
70
|
+
if (span) {
|
|
71
|
+
span.end(endTime ?? startTime);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function getReplayAttributes() {
|
|
75
|
+
const replay = core.getClient()?.getIntegrationByName("Replay");
|
|
76
|
+
const replayId = replay?.getReplayId(true);
|
|
77
|
+
if (!replayId) {
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
[attributes.SENTRY_REPLAY_ID]: replayId,
|
|
82
|
+
// Not the `SENTRY_REPLAY_IS_BUFFERING` convention: that one has no `sentry._internal.` prefix, and
|
|
83
|
+
// the rest of the SDK sets the prefixed key (see `logs/internal.ts`, `metrics/internal.ts`).
|
|
84
|
+
"sentry._internal.replay_is_buffering": replay.getRecordingMode() === "buffer" ? true : void 0
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
exports._emitWebVitalSpan = _emitWebVitalSpan;
|
|
89
|
+
//# sourceMappingURL=emitSpan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitSpan.js","sources":["../../../src/web-vitals/emitSpan.ts"],"sourcesContent":["import type { Integration, Span, SpanAttributes } from '@sentry/core';\nimport {\n getClient,\n getCurrentScope,\n getRootSpan,\n SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n spanToJSON,\n} from '@sentry/core';\nimport { startInactiveSpan } from '@sentry/core/browser';\nimport {\n BROWSER_NAVIGATION_ID,\n BROWSER_NAVIGATION_TYPE,\n SENTRY_REPLAY_ID,\n SENTRY_SEGMENT_NAME,\n SENTRY_TRANSACTION,\n USER_AGENT_ORIGINAL,\n} from '@sentry/conventions/attributes';\nimport { WINDOW } from '../types';\nimport type { MetricNavigationType } from '../instrumentation/performanceObserver';\nimport type { WebVitalReportEvent } from './reportEvents';\n\n// web-vitals reports a wider set of navigation types than the attribute defines. Only the states\n// Navigation Timing cannot express keep their own value; every ordinary document navigation folds\n// into `navigate`, including a back/forward that missed the bfcache and a discarded-tab restore.\nconst BROWSER_NAVIGATION_TYPES: Partial<Record<MetricNavigationType, string>> = {\n reload: 'reload',\n prerender: 'prerender',\n 'back-forward-cache': 'bfcache',\n 'soft-navigation': 'soft-navigation',\n};\n\nfunction toBrowserNavigationType(navigationType: MetricNavigationType): string {\n return BROWSER_NAVIGATION_TYPES[navigationType] ?? 'navigate';\n}\n\n// Locally-defined interfaces to avoid leaking bare global type references into the\n// generated .d.ts. The `declare global` augmentations in web-vitals/types.ts make these\n// available during this package's compilation but are NOT carried to consumers.\n// This mirrors the pattern used for PerformanceEventTiming in instrument.ts.\nexport interface LayoutShift extends PerformanceEntry {\n value: number;\n sources: Array<{ node: Node | null }>;\n hadRecentInput: boolean;\n}\n\nexport interface LargestContentfulPaint extends PerformanceEntry {\n readonly renderTime: DOMHighResTimeStamp;\n readonly loadTime: DOMHighResTimeStamp;\n readonly size: number;\n readonly id: string;\n readonly url: string;\n readonly element: Element | null;\n}\n\ninterface WebVitalSpanOptions {\n name: string;\n op: string;\n origin: string;\n metricName: 'lcp' | 'cls' | 'inp';\n value: number;\n attributes?: SpanAttributes;\n parentSpan?: Span;\n reportEvent?: WebVitalReportEvent;\n startTime: number;\n endTime?: number;\n /** Set when the vital was reported for a soft navigation rather than the initial page load. */\n softNavigationId?: number;\n /** The navigation the vital was measured on, as reported by web-vitals. */\n navigationType?: MetricNavigationType;\n /**\n * When `true`, the span is sent on its own as a v2 streamed span instead of being folded into a\n * transaction. Used for INP when span streaming is disabled (it reports late, so it can't ride\n * the pageload transaction).\n *\n * TODO(standalone): remove once the static (transaction) trace lifecycle is dropped and INP always streams.\n */\n standalone?: boolean;\n}\n\n/**\n * Emits a web vital span. When `standalone` is set it is sent on its own as a v2 streamed span;\n * otherwise it flows through the span streaming pipeline as a child of `parentSpan`.\n */\nexport function _emitWebVitalSpan(options: WebVitalSpanOptions): void {\n const {\n name,\n op,\n origin,\n metricName,\n value,\n attributes: passedAttributes,\n parentSpan,\n reportEvent,\n startTime,\n endTime,\n standalone,\n softNavigationId,\n navigationType,\n } = options;\n\n // Taken off the segment span itself, so it can't diverge from it: a routing instrumentation may\n // rename that span (a pageload span is named `Pageload` until its route resolves), and the scope's\n // transaction name is deliberately not kept in sync with it. Only a standalone span, which is sent\n // without its segment span, has to fall back to the scope.\n const segmentSpan = parentSpan && getRootSpan(parentSpan);\n const segmentName = segmentSpan ? spanToJSON(segmentSpan).name : getCurrentScope().getScopeData().transactionName;\n\n const attributes: SpanAttributes = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: origin,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,\n [SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME]: 0,\n [`browser.web_vital.${metricName}.value`]: value,\n // oxlint-disable-next-line typescript-eslint/no-deprecated\n [SENTRY_TRANSACTION]: segmentName,\n [SENTRY_SEGMENT_NAME]: segmentName,\n // Web vital score calculation relies on the user agent\n [USER_AGENT_ORIGINAL]: WINDOW.navigator?.userAgent,\n ...passedAttributes,\n };\n\n if (parentSpan && spanToJSON(parentSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] === 'pageload') {\n // for LCP and CLS, we collect the pageload span id as an attribute\n attributes['sentry.pageload.span_id'] = parentSpan.spanContext().spanId;\n }\n\n if (reportEvent) {\n attributes[`browser.web_vital.${metricName}.report_event`] = reportEvent;\n }\n\n if (softNavigationId != null) {\n attributes[BROWSER_NAVIGATION_ID] = softNavigationId;\n }\n\n if (navigationType) {\n attributes[BROWSER_NAVIGATION_TYPE] = toBrowserNavigationType(navigationType);\n }\n\n // A standalone span is sent as a plain v2 span without running the `processSpan` hooks (see\n // `captureStandaloneSpanWithStaticCallback`), so Replay can't attach the replay id itself. Set it\n // here, mirroring Replay's `processSpan`, so INP keeps its replay association like it did on v1.\n // TODO(standalone): remove once the static (transaction) trace lifecycle is dropped and INP always\n // streams, at which point Replay's `processSpan` runs and attaches the replay id.\n if (standalone) {\n Object.assign(attributes, getReplayAttributes());\n }\n\n const span = startInactiveSpan({\n name,\n attributes,\n startTime,\n parentSpan,\n // oxlint-disable-next-line typescript/no-deprecated -- intentional during the v1/v2 transition; see the TODO(standalone) above\n experimental: standalone ? { standalone: true } : undefined,\n });\n\n if (span) {\n span.end(endTime ?? startTime);\n }\n}\n\ninterface ReplayIntegration extends Integration {\n getReplayId: (onlyIfSampled?: boolean) => string | undefined;\n getRecordingMode: () => 'session' | 'buffer' | undefined;\n}\n\n// TODO(standalone): remove once the static (transaction) trace lifecycle is dropped; Replay's\n// `processSpan` then attaches the replay id to the streamed INP span instead.\nfunction getReplayAttributes(): SpanAttributes {\n const replay = getClient()?.getIntegrationByName<ReplayIntegration>('Replay');\n const replayId = replay?.getReplayId(true);\n if (!replayId) {\n return {};\n }\n\n return {\n [SENTRY_REPLAY_ID]: replayId,\n // Not the `SENTRY_REPLAY_IS_BUFFERING` convention: that one has no `sentry._internal.` prefix, and\n // the rest of the SDK sets the prefixed key (see `logs/internal.ts`, `metrics/internal.ts`).\n 'sentry._internal.replay_is_buffering': replay!.getRecordingMode() === 'buffer' ? true : undefined,\n };\n}\n"],"names":["getRootSpan","spanToJSON","getCurrentScope","attributes","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME","SENTRY_TRANSACTION","SENTRY_SEGMENT_NAME","USER_AGENT_ORIGINAL","WINDOW","BROWSER_NAVIGATION_ID","BROWSER_NAVIGATION_TYPE","startInactiveSpan","getClient","SENTRY_REPLAY_ID"],"mappings":";;;;;;;AA0BA,MAAM,wBAAA,GAA0E;AAAA,EAC9E,MAAA,EAAQ,QAAA;AAAA,EACR,SAAA,EAAW,WAAA;AAAA,EACX,oBAAA,EAAsB,SAAA;AAAA,EACtB,iBAAA,EAAmB;AACrB,CAAA;AAEA,SAAS,wBAAwB,cAAA,EAA8C;AAC7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/* @__PURE__ */ new Map();
|
|
10
|
+
const UNKNOWN_ELEMENT_NAME = "<unknown>";
|
|
10
11
|
const ELEMENT_NAME_TIMESTAMP_MAP = /* @__PURE__ */ new Map();
|
|
11
12
|
const MAX_PLAUSIBLE_INP_DURATION = 60;
|
|
12
13
|
const INP_ENTRY_MAP = {
|
|
@@ -54,6 +55,12 @@ function registerInpInteractionListener() {
|
|
|
54
55
|
}
|
|
55
56
|
const elementName = htmlTreeAsString.htmlTreeAsString(target);
|
|
56
57
|
const timestamp = Math.round(event.timeStamp);
|
|
58
|
+
if (!elementName || elementName === UNKNOWN_ELEMENT_NAME) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (ELEMENT_NAME_TIMESTAMP_MAP.has(timestamp)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
57
64
|
ELEMENT_NAME_TIMESTAMP_MAP.set(timestamp, elementName);
|
|
58
65
|
if (ELEMENT_NAME_TIMESTAMP_MAP.size > 50) {
|
|
59
66
|
const firstKey = ELEMENT_NAME_TIMESTAMP_MAP.keys().next().value;
|
|
@@ -74,7 +81,7 @@ function registerInpInteractionListener() {
|
|
|
74
81
|
}
|
|
75
82
|
}
|
|
76
83
|
}
|
|
77
|
-
return elementName ||
|
|
84
|
+
return elementName || UNKNOWN_ELEMENT_NAME;
|
|
78
85
|
}
|
|
79
86
|
const handleEntries = ({ entries }) => {
|
|
80
87
|
const activeSpan = core.getActiveSpan();
|