@sentry/browser-utils 11.4.0 → 11.6.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/getNativeImplementation.js +8 -1
- package/build/cjs/getNativeImplementation.js.map +1 -1
- package/build/cjs/performance/entries.js +43 -39
- package/build/cjs/performance/entries.js.map +1 -1
- package/build/cjs/performance/interactions.js +4 -1
- package/build/cjs/performance/interactions.js.map +1 -1
- package/build/cjs/performance/resourceTiming.js +7 -5
- package/build/cjs/performance/resourceTiming.js.map +1 -1
- package/build/cjs/performance/userTiming.js +17 -22
- package/build/cjs/performance/userTiming.js.map +1 -1
- package/build/cjs/web-vitals/emitSpan.js +3 -3
- package/build/cjs/web-vitals/emitSpan.js.map +1 -1
- package/build/cjs/web-vitals/softNavs.js +1 -1
- package/build/cjs/web-vitals/softNavs.js.map +1 -1
- package/build/cjs/web-vitals/spans.js +9 -9
- package/build/cjs/web-vitals/spans.js.map +1 -1
- package/build/esm/getNativeImplementation.js +8 -1
- package/build/esm/getNativeImplementation.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/performance/entries.js +45 -41
- package/build/esm/performance/entries.js.map +1 -1
- package/build/esm/performance/interactions.js +5 -2
- package/build/esm/performance/interactions.js.map +1 -1
- package/build/esm/performance/resourceTiming.js +9 -7
- package/build/esm/performance/resourceTiming.js.map +1 -1
- package/build/esm/performance/userTiming.js +19 -24
- package/build/esm/performance/userTiming.js.map +1 -1
- package/build/esm/web-vitals/emitSpan.js +5 -5
- package/build/esm/web-vitals/emitSpan.js.map +1 -1
- package/build/esm/web-vitals/softNavs.js +3 -3
- package/build/esm/web-vitals/softNavs.js.map +1 -1
- package/build/esm/web-vitals/spans.js +11 -11
- package/build/esm/web-vitals/spans.js.map +1 -1
- package/build/types/getNativeImplementation.d.ts.map +1 -1
- package/build/types/performance/entries.d.ts +3 -3
- package/build/types/performance/entries.d.ts.map +1 -1
- package/build/types/performance/resourceTiming.d.ts.map +1 -1
- package/build/types/performance/userTiming.d.ts +1 -1
- package/build/types/performance/userTiming.d.ts.map +1 -1
- package/build/types/web-vitals/emitSpan.d.ts.map +1 -1
- package/build/types/web-vitals/spans.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -11,11 +11,9 @@ const _userTimingIntegration = ((options = {}) => {
|
|
|
11
11
|
name: INTEGRATION_NAME,
|
|
12
12
|
setup(client) {
|
|
13
13
|
const performance = utils.getBrowserPerformanceAPI();
|
|
14
|
-
|
|
15
|
-
if (!performance?.getEntries || !timeOrigin) {
|
|
14
|
+
if (!performance?.getEntries) {
|
|
16
15
|
return;
|
|
17
16
|
}
|
|
18
|
-
const timeOriginInSeconds = utils.msToSec(timeOrigin);
|
|
19
17
|
let performanceCursor = 0;
|
|
20
18
|
client.on("beforeIdleSpanEnd", (idleSpan) => {
|
|
21
19
|
const { attributes: attributes$1, start_timestamp: parentStartTimestamp } = core.spanToJSON(idleSpan);
|
|
@@ -23,26 +21,25 @@ const _userTimingIntegration = ((options = {}) => {
|
|
|
23
21
|
if (parentOp !== "pageload" && parentOp !== "navigation") {
|
|
24
22
|
return;
|
|
25
23
|
}
|
|
26
|
-
const
|
|
24
|
+
const requestStart = utils$1.getNavigationEntry(false)?.requestStart ?? 0;
|
|
27
25
|
const performanceEntries = performance.getEntries();
|
|
28
26
|
for (const entry of performanceEntries.slice(performanceCursor)) {
|
|
29
27
|
if (entry.entryType !== "mark" && entry.entryType !== "measure") {
|
|
30
28
|
continue;
|
|
31
29
|
}
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
if (parentOp === "navigation" && parentStartTimestamp && absoluteStartTime < parentStartTimestamp) {
|
|
30
|
+
const startTimestamp = core._INTERNAL_performanceTimeToSeconds(entry.startTime);
|
|
31
|
+
if (!startTimestamp) {
|
|
35
32
|
continue;
|
|
36
33
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
requestTime,
|
|
44
|
-
options.ignore ?? []
|
|
34
|
+
if (parentOp === "navigation" && parentStartTimestamp && startTimestamp < parentStartTimestamp) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const endTimestamp = core._INTERNAL_performanceTimeToSeconds(
|
|
38
|
+
entry.startTime + Math.max(0, entry.duration),
|
|
39
|
+
entry.startTime
|
|
45
40
|
);
|
|
41
|
+
const requestTimestamp = core._INTERNAL_performanceTimeToSeconds(requestStart, entry.startTime);
|
|
42
|
+
_addUserTimingSpan(idleSpan, entry, startTimestamp, endTimestamp, requestTimestamp, options.ignore ?? []);
|
|
46
43
|
}
|
|
47
44
|
performanceCursor = performanceEntries.length;
|
|
48
45
|
});
|
|
@@ -50,23 +47,21 @@ const _userTimingIntegration = ((options = {}) => {
|
|
|
50
47
|
};
|
|
51
48
|
});
|
|
52
49
|
const userTimingIntegration = core.defineIntegration(_userTimingIntegration);
|
|
53
|
-
function _addUserTimingSpan(parentSpan, entry,
|
|
50
|
+
function _addUserTimingSpan(parentSpan, entry, startTimestamp, endTimestamp, requestTimestamp, ignore) {
|
|
54
51
|
if (isReact19MeasureEntry(entry) || core.stringMatchesSomePattern(entry.name, ignore)) {
|
|
55
52
|
return;
|
|
56
53
|
}
|
|
57
|
-
const spanStartTimestamp =
|
|
58
|
-
const originalStartTimestamp = timeOrigin + startTime;
|
|
59
|
-
const spanEndTimestamp = originalStartTimestamp + duration;
|
|
54
|
+
const spanStartTimestamp = Math.max(startTimestamp, requestTimestamp);
|
|
60
55
|
const attributes$1 = {
|
|
61
56
|
[attributes.SENTRY_ORIGIN]: `auto.browser.user_timing.${entry.entryType}`
|
|
62
57
|
};
|
|
63
|
-
if (spanStartTimestamp !==
|
|
58
|
+
if (spanStartTimestamp !== startTimestamp) {
|
|
64
59
|
attributes$1["sentry.browser.measure_happened_before_request"] = true;
|
|
65
60
|
attributes$1["sentry.browser.measure_start_time"] = spanStartTimestamp;
|
|
66
61
|
}
|
|
67
62
|
addDetailToSpanAttributes(attributes$1, entry);
|
|
68
|
-
if (spanStartTimestamp <=
|
|
69
|
-
utils.startAndEndSpan(parentSpan, spanStartTimestamp,
|
|
63
|
+
if (spanStartTimestamp <= endTimestamp) {
|
|
64
|
+
utils.startAndEndSpan(parentSpan, spanStartTimestamp, endTimestamp, {
|
|
70
65
|
name: entry.name,
|
|
71
66
|
op: entry.entryType,
|
|
72
67
|
attributes: attributes$1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userTiming.js","sources":["../../../src/performance/userTiming.ts"],"sourcesContent":["import { SENTRY_OP, SENTRY_ORIGIN } from '@sentry/conventions/attributes';\nimport type { IntegrationFn, Span, SpanAttributes, SpanAttributeValue } from '@sentry/core';\nimport {\n browserPerformanceTimeOrigin,\n defineIntegration,\n isPrimitive,\n spanToJSON,\n stringMatchesSomePattern,\n} from '@sentry/core';\nimport { getBrowserPerformanceAPI, msToSec, startAndEndSpan } from './utils';\nimport { getNavigationEntry } from '../web-vitals/utils';\n\ninterface UserTimingOptions {\n /**\n * User Timing entries with names matching any of these strings or regular expressions will not be emitted.\n *\n * Default: []\n */\n ignore?: Array<string | RegExp>;\n}\n\nconst INTEGRATION_NAME = 'UserTiming';\n\nconst _userTimingIntegration = ((options: UserTimingOptions = {}) => {\n return {\n name: INTEGRATION_NAME,\n setup(client) {\n const performance = getBrowserPerformanceAPI();\n const timeOrigin = browserPerformanceTimeOrigin();\n if (!performance?.getEntries || !timeOrigin) {\n return;\n }\n const timeOriginInSeconds = msToSec(timeOrigin);\n let performanceCursor = 0;\n\n client.on('beforeIdleSpanEnd', idleSpan => {\n const { attributes, start_timestamp: parentStartTimestamp } = spanToJSON(idleSpan);\n const parentOp = attributes[SENTRY_OP];\n\n if (parentOp !== 'pageload' && parentOp !== 'navigation') {\n return;\n }\n\n const requestTime = msToSec(getNavigationEntry(false)?.requestStart ?? 0);\n const performanceEntries = performance.getEntries();\n\n for (const entry of performanceEntries.slice(performanceCursor)) {\n if (entry.entryType !== 'mark' && entry.entryType !== 'measure') {\n continue;\n }\n\n const startTime = msToSec(entry.startTime);\n const absoluteStartTime = timeOriginInSeconds + startTime;\n\n if (parentOp === 'navigation' && parentStartTimestamp && absoluteStartTime < parentStartTimestamp) {\n continue;\n }\n\n _addUserTimingSpan(\n idleSpan,\n entry,\n startTime,\n msToSec(Math.max(0, entry.duration)),\n timeOriginInSeconds,\n requestTime,\n options.ignore ?? [],\n );\n }\n\n performanceCursor = performanceEntries.length;\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Captures spans created with the browser's User Timing APIs, `performance.mark` and `performance.measure`.\n *\n * The integration must be explicitly added to `Sentry.init`. Entries are attached to the active pageload or\n * navigation span when it ends.\n *\n * @example\n * ```ts\n * Sentry.init({\n * integrations: [\n * Sentry.browserTracingIntegration(),\n * Sentry.userTimingIntegration({\n * ignore: ['third-party-mark', /framework-measure/],\n * }),\n * ],\n * });\n * ```\n */\nexport const userTimingIntegration = defineIntegration(_userTimingIntegration);\n\n/**\n * Creates a span for a browser User Timing entry.\n * Exported only for tests.\n */\nexport function _addUserTimingSpan(\n parentSpan: Span,\n entry: PerformanceEntry,\n startTime: number,\n duration: number,\n timeOrigin: number,\n requestTime: number,\n ignore: Array<string | RegExp>,\n): void {\n if (isReact19MeasureEntry(entry) || stringMatchesSomePattern(entry.name, ignore)) {\n return;\n }\n\n // Measures can reference arbitrary timestamps, including timestamps before the page request started.\n const spanStartTimestamp = timeOrigin + Math.max(startTime, requestTime);\n const originalStartTimestamp = timeOrigin + startTime;\n const spanEndTimestamp = originalStartTimestamp + duration;\n\n const attributes: SpanAttributes = {\n [SENTRY_ORIGIN]: `auto.browser.user_timing.${entry.entryType}`,\n };\n\n if (spanStartTimestamp !== originalStartTimestamp) {\n attributes['sentry.browser.measure_happened_before_request'] = true;\n attributes['sentry.browser.measure_start_time'] = spanStartTimestamp;\n }\n\n addDetailToSpanAttributes(attributes, entry as PerformanceMeasure);\n\n // Third-party measurements can contain timestamps which would produce invalid spans.\n if (spanStartTimestamp <= spanEndTimestamp) {\n startAndEndSpan(parentSpan, spanStartTimestamp, spanEndTimestamp, {\n name: entry.name,\n op: entry.entryType,\n attributes,\n });\n }\n}\n\n/**\n * React 19.2+ creates performance.measure entries for component renders.\n * We can identify them by the `detail.devtools.track` property being set to 'Components ⚛'.\n * See https://react.dev/reference/dev-tools/react-performance-tracks.\n */\nfunction isReact19MeasureEntry(entry: PerformanceEntry): boolean | void {\n if (entry.entryType !== 'measure') {\n return;\n }\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return (entry as PerformanceMeasure).detail.devtools.track === 'Components ⚛';\n } catch {\n return;\n }\n}\n\nfunction addDetailToSpanAttributes(attributes: SpanAttributes, entry: PerformanceMeasure): void {\n try {\n // Accessing detail can throw in some browsers due to security restrictions.\n const detail = entry.detail;\n if (!detail) {\n return;\n }\n\n if (typeof detail === 'object') {\n for (const [key, value] of Object.entries(detail)) {\n if (value && isPrimitive(value)) {\n attributes[`sentry.browser.measure.detail.${key}`] = value as SpanAttributeValue;\n } else if (value !== undefined) {\n try {\n attributes[`sentry.browser.measure.detail.${key}`] = JSON.stringify(value);\n } catch {\n // User-provided detail values are not guaranteed to be serializable.\n }\n }\n }\n return;\n }\n\n if (isPrimitive(detail)) {\n attributes['sentry.browser.measure.detail'] = detail as SpanAttributeValue;\n return;\n }\n\n try {\n attributes['sentry.browser.measure.detail'] = JSON.stringify(detail);\n } catch {\n // User-provided detail values are not guaranteed to be serializable.\n }\n } catch {\n // Accessing detail can throw in some browsers due to security restrictions.\n }\n}\n"],"names":["getBrowserPerformanceAPI","browserPerformanceTimeOrigin","msToSec","attributes","spanToJSON","SENTRY_OP","getNavigationEntry","defineIntegration","stringMatchesSomePattern","SENTRY_ORIGIN","startAndEndSpan","isPrimitive"],"mappings":";;;;;;;AAqBA,MAAM,gBAAA,GAAmB,YAAA;AAEzB,MAAM,sBAAA,IAA0B,CAAC,OAAA,GAA6B,EAAC,KAAM;AACn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CAAA;AAAA,IACrE,CAAA,CAAA,MAAQ;AAAA,IAER;AAAA,EACF,CAAA,CAAA,MAAQ;AAAA,EAER;AACF;;;;;"}
|
|
1
|
+
{"version":3,"file":"userTiming.js","sources":["../../../src/performance/userTiming.ts"],"sourcesContent":["import { SENTRY_OP, SENTRY_ORIGIN } from '@sentry/conventions/attributes';\nimport type { IntegrationFn, Span, SpanAttributes, SpanAttributeValue } from '@sentry/core';\nimport {\n defineIntegration,\n isPrimitive,\n _INTERNAL_performanceTimeToSeconds,\n spanToJSON,\n stringMatchesSomePattern,\n} from '@sentry/core';\nimport { getBrowserPerformanceAPI, startAndEndSpan } from './utils';\nimport { getNavigationEntry } from '../web-vitals/utils';\n\ninterface UserTimingOptions {\n /**\n * User Timing entries with names matching any of these strings or regular expressions will not be emitted.\n *\n * Default: []\n */\n ignore?: Array<string | RegExp>;\n}\n\nconst INTEGRATION_NAME = 'UserTiming';\n\nconst _userTimingIntegration = ((options: UserTimingOptions = {}) => {\n return {\n name: INTEGRATION_NAME,\n setup(client) {\n const performance = getBrowserPerformanceAPI();\n if (!performance?.getEntries) {\n return;\n }\n let performanceCursor = 0;\n\n client.on('beforeIdleSpanEnd', idleSpan => {\n const { attributes, start_timestamp: parentStartTimestamp } = spanToJSON(idleSpan);\n const parentOp = attributes[SENTRY_OP];\n\n if (parentOp !== 'pageload' && parentOp !== 'navigation') {\n return;\n }\n\n const requestStart = getNavigationEntry(false)?.requestStart ?? 0;\n const performanceEntries = performance.getEntries();\n\n for (const entry of performanceEntries.slice(performanceCursor)) {\n if (entry.entryType !== 'mark' && entry.entryType !== 'measure') {\n continue;\n }\n\n const startTimestamp = _INTERNAL_performanceTimeToSeconds(entry.startTime);\n if (!startTimestamp) {\n continue;\n }\n\n if (parentOp === 'navigation' && parentStartTimestamp && startTimestamp < parentStartTimestamp) {\n continue;\n }\n\n const endTimestamp = _INTERNAL_performanceTimeToSeconds(\n entry.startTime + Math.max(0, entry.duration),\n entry.startTime,\n ) as number;\n\n // We convert the request start with the entry's time origin, so that the clamp in `_addUserTimingSpan` compares\n // timestamps on the same timeline, even if the time origin was corrected between the request and the entry.\n const requestTimestamp = _INTERNAL_performanceTimeToSeconds(requestStart, entry.startTime) as number;\n\n _addUserTimingSpan(idleSpan, entry, startTimestamp, endTimestamp, requestTimestamp, options.ignore ?? []);\n }\n\n performanceCursor = performanceEntries.length;\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Captures spans created with the browser's User Timing APIs, `performance.mark` and `performance.measure`.\n *\n * The integration must be explicitly added to `Sentry.init`. Entries are attached to the active pageload or\n * navigation span when it ends.\n *\n * @example\n * ```ts\n * Sentry.init({\n * integrations: [\n * Sentry.browserTracingIntegration(),\n * Sentry.userTimingIntegration({\n * ignore: ['third-party-mark', /framework-measure/],\n * }),\n * ],\n * });\n * ```\n */\nexport const userTimingIntegration = defineIntegration(_userTimingIntegration);\n\n/**\n * Creates a span for a browser User Timing entry.\n * Exported only for tests.\n */\nexport function _addUserTimingSpan(\n parentSpan: Span,\n entry: PerformanceEntry,\n startTimestamp: number,\n endTimestamp: number,\n requestTimestamp: number,\n ignore: Array<string | RegExp>,\n): void {\n if (isReact19MeasureEntry(entry) || stringMatchesSomePattern(entry.name, ignore)) {\n return;\n }\n\n // Measures can reference arbitrary timestamps, including timestamps before the page request started.\n const spanStartTimestamp = Math.max(startTimestamp, requestTimestamp);\n\n const attributes: SpanAttributes = {\n [SENTRY_ORIGIN]: `auto.browser.user_timing.${entry.entryType}`,\n };\n\n if (spanStartTimestamp !== startTimestamp) {\n attributes['sentry.browser.measure_happened_before_request'] = true;\n attributes['sentry.browser.measure_start_time'] = spanStartTimestamp;\n }\n\n addDetailToSpanAttributes(attributes, entry as PerformanceMeasure);\n\n // Third-party measurements can contain timestamps which would produce invalid spans.\n if (spanStartTimestamp <= endTimestamp) {\n startAndEndSpan(parentSpan, spanStartTimestamp, endTimestamp, {\n name: entry.name,\n op: entry.entryType,\n attributes,\n });\n }\n}\n\n/**\n * React 19.2+ creates performance.measure entries for component renders.\n * We can identify them by the `detail.devtools.track` property being set to 'Components ⚛'.\n * See https://react.dev/reference/dev-tools/react-performance-tracks.\n */\nfunction isReact19MeasureEntry(entry: PerformanceEntry): boolean | void {\n if (entry.entryType !== 'measure') {\n return;\n }\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return (entry as PerformanceMeasure).detail.devtools.track === 'Components ⚛';\n } catch {\n return;\n }\n}\n\nfunction addDetailToSpanAttributes(attributes: SpanAttributes, entry: PerformanceMeasure): void {\n try {\n // Accessing detail can throw in some browsers due to security restrictions.\n const detail = entry.detail;\n if (!detail) {\n return;\n }\n\n if (typeof detail === 'object') {\n for (const [key, value] of Object.entries(detail)) {\n if (value && isPrimitive(value)) {\n attributes[`sentry.browser.measure.detail.${key}`] = value as SpanAttributeValue;\n } else if (value !== undefined) {\n try {\n attributes[`sentry.browser.measure.detail.${key}`] = JSON.stringify(value);\n } catch {\n // User-provided detail values are not guaranteed to be serializable.\n }\n }\n }\n return;\n }\n\n if (isPrimitive(detail)) {\n attributes['sentry.browser.measure.detail'] = detail as SpanAttributeValue;\n return;\n }\n\n try {\n attributes['sentry.browser.measure.detail'] = JSON.stringify(detail);\n } catch {\n // User-provided detail values are not guaranteed to be serializable.\n }\n } catch {\n // Accessing detail can throw in some browsers due to security restrictions.\n }\n}\n"],"names":["getBrowserPerformanceAPI","attributes","spanToJSON","SENTRY_OP","getNavigationEntry","_INTERNAL_performanceTimeToSeconds","defineIntegration","stringMatchesSomePattern","SENTRY_ORIGIN","startAndEndSpan","isPrimitive"],"mappings":";;;;;;;AAqBA,MAAM,gBAAA,GAAmB,YAAA;AAEzB,MAAM,sBAAA,IAA0B,CAAC,OAAA,GAA6B,EAAC,KAAM;AACnE,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,MAAM,MAAA,EAAQ;AACZ,MAAA,MAAM,cAAcA,8BAAA,EAAyB;AAC7C,MAAA,IAAI,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Span ? core.spanToJSON(segmentSpan).name : core.getCurrentScope().getScopeData().transactionName;
|
|
25
25
|
const attributes$1 = {
|
|
26
|
-
[
|
|
27
|
-
[
|
|
26
|
+
[attributes.SENTRY_ORIGIN]: origin,
|
|
27
|
+
[attributes.SENTRY_OP]: op,
|
|
28
28
|
[attributes.SENTRY_EXCLUSIVE_TIME]: 0,
|
|
29
29
|
[`browser.web_vital.${metricName}.value`]: value,
|
|
30
30
|
// oxlint-disable-next-line typescript-eslint/no-deprecated
|
|
@@ -34,7 +34,7 @@ function _emitWebVitalSpan(options) {
|
|
|
34
34
|
[attributes.USER_AGENT_ORIGINAL]: types.WINDOW.navigator?.userAgent,
|
|
35
35
|
...passedAttributes
|
|
36
36
|
};
|
|
37
|
-
if (parentSpan && core.spanToJSON(parentSpan).attributes[
|
|
37
|
+
if (parentSpan && core.spanToJSON(parentSpan).attributes[attributes.SENTRY_OP] === "pageload") {
|
|
38
38
|
attributes$1["sentry.pageload.span_id"] = parentSpan.spanContext().spanId;
|
|
39
39
|
}
|
|
40
40
|
if (softNavigationId != null) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emitSpan.js","sources":["../../../src/web-vitals/emitSpan.ts"],"sourcesContent":["import type { Integration, Span, SpanAttributes } from '@sentry/core';\nimport {
|
|
1
|
+
{"version":3,"file":"emitSpan.js","sources":["../../../src/web-vitals/emitSpan.ts"],"sourcesContent":["import type { Integration, Span, SpanAttributes } from '@sentry/core';\nimport { getClient, getCurrentScope, getRootSpan, spanToJSON } from '@sentry/core';\nimport { startInactiveSpan } from '@sentry/core/browser';\nimport {\n SENTRY_EXCLUSIVE_TIME,\n BROWSER_NAVIGATION_ID,\n BROWSER_NAVIGATION_TYPE,\n SENTRY_REPLAY_ID,\n SENTRY_SEGMENT_NAME,\n SENTRY_TRANSACTION,\n USER_AGENT_ORIGINAL,\n SENTRY_OP,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { WINDOW } from '../types';\nimport type { MetricNavigationType } from '../instrumentation/performanceObserver';\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 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 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 [SENTRY_ORIGIN]: origin,\n [SENTRY_OP]: op,\n [SENTRY_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[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 (softNavigationId != null) {\n attributes[BROWSER_NAVIGATION_ID] = softNavigationId;\n }\n\n if (navigationType) {\n attributes[BROWSER_NAVIGATION_TYPE] = 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","SENTRY_ORIGIN","SENTRY_OP","SENTRY_EXCLUSIVE_TIME","SENTRY_TRANSACTION","SENTRY_SEGMENT_NAME","USER_AGENT_ORIGINAL","WINDOW","BROWSER_NAVIGATION_ID","BROWSER_NAVIGATION_TYPE","startInactiveSpan","getClient","SENTRY_REPLAY_ID"],"mappings":";;;;;;;AAgEO,SAAS,kBAAkB,OAAA,EAAoC;AACpE,EAAA,MAAM;AAAA,IACJ,IAAA;AAAA,IACA,EAAA;AAAA,IACA,MAAA;AAAA,IACA,UAAA;AAAA,IACA,KAAA;AAAA,IACA,UAAA,EAAY,gBAAA;AAAA,IACZ,UAAA;AAAA,IACA,SAAA;AAAA,IACA,OAAA;AAAA,IACA,UAAA;AAAA,IACA,gBAAA;AAAA,IACA;AAAA,GACF,GAAI,OAAA;AAMJ,EAAA,MAAM,WAAA,GAAc,UAAA,IAAcA,gBAAA,CAAY,UAAU,CAAA;AACxD,EAAA,MAAM,WAAA,GAAc,cAAcC,eAAA,CAAW,WAAW,EAAE,IAAA,GAAOC,oBAAA,EAAgB,CAAE,YAAA,EAAa,CAAE,eAAA;AAElG,EAAA,MAAMC,YAAA,GAA6B;AAAA,IACjC,CAACC,wBAAa,GAAG,MAAA;AAAA,IACjB,CAACC,oBAAS,GAAG,EAAA;AAAA,IACb,CAACC,gCAAqB,GAAG,CAAA;AAAA,IACzB,CAAC,CAAA,kBAAA,EAAqB,UAAU,CAAA,MAAA,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AAAA,EACV;AAEA,EAAA,OAAO;AAAA,IACL,CAACC,2BAAgB,GAAG,QAAA;AAAA;AAAA;AAAA,IAGpB,sCAAA,EAAwC,MAAA,CAAQ,gBAAA,EAAiB,KAAM,WAAW,IAAA,GAAO;AAAA,GAC3F;AACF;;;;"}
|
|
@@ -39,7 +39,7 @@ function startSoftNavigationCorrelation(client) {
|
|
|
39
39
|
types.WINDOW.addEventListener("click", onInteraction, { capture: true, passive: true });
|
|
40
40
|
types.WINDOW.addEventListener("keydown", onInteraction, { capture: true, passive: true });
|
|
41
41
|
client.on("spanStart", (span) => {
|
|
42
|
-
if (core.spanToJSON(span).attributes?.[
|
|
42
|
+
if (core.spanToJSON(span).attributes?.[attributes.SENTRY_OP] !== "navigation") {
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
45
|
_pendingNavigation = void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"softNavs.js","sources":["../../../src/web-vitals/softNavs.ts"],"sourcesContent":["import type { Client, Span } from '@sentry/core';\nimport { debug, LRUMap, SEMANTIC_ATTRIBUTE_SENTRY_OP, spanToJSON } from '@sentry/core';\nimport { BROWSER_NAVIGATION_ID } from '@sentry/conventions/attributes';\nimport { DEBUG_BUILD } from '../debug-build';\nimport type { PerformanceSoftNavigation } from '../instrumentation/performanceObserver';\nimport { addPerformanceInstrumentationHandler, isPerformanceEventTiming } from '../instrumentation/performanceObserver';\nimport { WINDOW } from '../types';\n\n/**\n * A page only ever needs its most recent navigations to still be joinable: web vitals for a soft\n * navigation are finalized at the next soft navigation or on pagehide, never later than that.\n */\nconst MAX_TRACKED_NAVIGATIONS = 5;\n\n/**\n * Tolerance when matching a DOM event's `timeStamp` against the `startTime` of its Event Timing\n * entry. Both are `DOMHighResTimeStamp`s from the same clock, so this only absorbs rounding.\n */\nconst INTERACTION_MATCH_TOLERANCE_MS = 5;\n\ninterface SoftNavMetric {\n navigationType: string;\n navigationId: number;\n navigationInteractionId?: number;\n}\n\ninterface PendingNavigation {\n span: Span;\n interactionTimestamp: number;\n}\n\ninterface PendingInteraction {\n interactionId: number;\n interactionTimestamp: number;\n}\n\n// The navigation span whose triggering interaction we haven't identified yet.\nlet _pendingNavigation: PendingNavigation | undefined;\n// The interaction whose Event Timing entry arrived before any navigation span claimed it.\nlet _pendingInteraction: PendingInteraction | undefined;\n// The timestamp of the most recent trusted click/keydown, i.e. our best guess at the interaction\n// that a history change happening right now was driven by.\nlet _lastInteractionTimestamp: number | undefined;\n\nconst _interactionIdToNavigationSpan = new LRUMap<number, Span>(MAX_TRACKED_NAVIGATIONS);\nconst _navigationIdToNavigationSpan = new LRUMap<number, Span>(MAX_TRACKED_NAVIGATIONS);\n\nlet _correlationStarted = false;\n\n/**\n * Whether an Event Timing entry's `startTime` and a DOM event's `timeStamp` name the same\n * interaction.\n */\nfunction interactionMatches(entryStartTime: number, interactionTimestamp: number): boolean {\n return Math.abs(entryStartTime - interactionTimestamp) <= INTERACTION_MATCH_TOLERANCE_MS;\n}\n\n/**\n * Whether the browser can report web vitals for soft navigations.\n *\n * This mirrors web-vitals' own feature detection: passing `reportSoftNavs` on a browser that fails\n * this check is a no-op there, so it has to be a no-op here too.\n */\nexport function supportsSoftNavigations(): boolean {\n try {\n return (\n PerformanceObserver.supportedEntryTypes.includes('soft-navigation') &&\n // Older implementations exposed this as an attribute rather than a method. Only the method\n // form shipped unflagged, so it's what web-vitals gates on.\n typeof (\n WINDOW as {\n PerformanceSoftNavigation?: { prototype?: { getLargestInteractionContentfulPaint?: unknown } };\n }\n ).PerformanceSoftNavigation?.prototype?.getLargestInteractionContentfulPaint === 'function'\n );\n } catch {\n return false;\n }\n}\n\n/**\n * Start correlating the browser's soft navigations with the SDK's navigation spans.\n *\n * A navigation span is created synchronously on the history change, but the browser only mints the\n * `soft-navigation` entry (and with it the `navigationId` that web vitals are reported against)\n * once the navigation has been confirmed by a paint. So the `navigationId` cannot be known at span\n * creation time and the two have to be joined after the fact.\n *\n * The join key is the `interactionId` of the interaction that drove the navigation: per the Soft\n * Navigations spec the `soft-navigation` entry carries the `interactionId` of the interaction that\n * triggered it, which is the same id the interaction's own `PerformanceEventTiming` entry carries.\n * So we bind a navigation span to the interaction it happened during, and the soft navigation\n * joins back to that span through the shared id.\n *\n * This is inherently partial. Navigations that don't meet the browser's soft navigation heuristic\n * (programmatic navigations, navigations that never paint, back/forward from the browser chrome)\n * produce no entry at all, so those navigation spans simply have no web vitals.\n */\nexport function startSoftNavigationCorrelation(client: Client): void {\n if (_correlationStarted || !supportsSoftNavigations()) {\n return;\n }\n _correlationStarted = true;\n\n const onInteraction = (event: Event): void => {\n if (event.isTrusted) {\n _lastInteractionTimestamp = event.timeStamp;\n }\n };\n // Only click and keydown can start a soft navigation, which is also what the SDK's redirect\n // detection listens for.\n WINDOW.addEventListener('click', onInteraction, { capture: true, passive: true });\n WINDOW.addEventListener('keydown', onInteraction, { capture: true, passive: true });\n\n client.on('spanStart', span => {\n if (spanToJSON(span).attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_OP] !== 'navigation') {\n return;\n }\n\n // A navigation with no preceding interaction can't produce a soft navigation, so there is\n // nothing to wait for. Dropping the pending span here also keeps us from binding a stale one.\n _pendingNavigation = undefined;\n const interactionTimestamp = _lastInteractionTimestamp;\n if (interactionTimestamp == null) {\n return;\n }\n\n // The interaction's entry may already be here: the router code that starts this span races the\n // paint that flushes the entry, so either one can win.\n if (_pendingInteraction?.interactionTimestamp === interactionTimestamp) {\n _interactionIdToNavigationSpan.set(_pendingInteraction.interactionId, span);\n _pendingInteraction = undefined;\n return;\n }\n\n _pendingNavigation = { span, interactionTimestamp };\n });\n\n const bindInteractionToNavigationSpan = ({ entries }: { entries: PerformanceEntry[] }): void => {\n for (const entry of entries) {\n if (!isPerformanceEventTiming(entry) || !entry.interactionId) {\n continue;\n }\n\n const pending = _pendingNavigation;\n if (pending && interactionMatches(entry.startTime, pending.interactionTimestamp)) {\n _interactionIdToNavigationSpan.set(entry.interactionId, pending.span);\n _pendingNavigation = undefined;\n continue;\n }\n\n // Once a navigation span has claimed this interaction, only a span that is still waiting can\n // rebind it, which the check above already allows. Holding on to the interaction's remaining\n // entries would instead let an unrelated later navigation claim it.\n if (_interactionIdToNavigationSpan.get(entry.interactionId)) {\n continue;\n }\n\n // The navigation span this interaction drove may still be on its way, so hold on to the\n // interaction instead of dropping it. Only the most recent one is worth keeping:\n // `_lastInteractionTimestamp` is what `spanStart` matches against and it only moves forward,\n // so an entry that doesn't match it now can never match it later.\n if (_lastInteractionTimestamp != null && interactionMatches(entry.startTime, _lastInteractionTimestamp)) {\n _pendingInteraction = { interactionId: entry.interactionId, interactionTimestamp: _lastInteractionTimestamp };\n }\n }\n };\n\n // `durationThreshold: 0` is applied for `event` by the shared observer, which matters here:\n // interactions below the 104ms default would otherwise never surface an `interactionId`.\n addPerformanceInstrumentationHandler('event', bindInteractionToNavigationSpan);\n addPerformanceInstrumentationHandler('first-input', bindInteractionToNavigationSpan);\n\n addPerformanceInstrumentationHandler('soft-navigation', ({ entries }) => {\n for (const entry of entries as PerformanceSoftNavigation[]) {\n const span = _interactionIdToNavigationSpan.get(entry.interactionId);\n if (!span) {\n DEBUG_BUILD && debug.log(`[SoftNav] No navigation span found for soft navigation ${entry.navigationId}`, entry);\n continue;\n }\n\n _navigationIdToNavigationSpan.set(entry.navigationId, span);\n // Best effort: the soft navigation entry usually lands well within the navigation span's idle\n // window, but if the span has already been sent this attribute is dropped.\n span.setAttribute(BROWSER_NAVIGATION_ID, entry.navigationId);\n }\n });\n}\n\n/**\n * The navigation span a soft navigation web vital belongs to, or `undefined` if the metric isn't\n * for a soft navigation or we failed to correlate it.\n */\nexport function getNavigationSpanForMetric(metric: SoftNavMetric): Span | undefined {\n if (metric.navigationType !== 'soft-navigation') {\n return undefined;\n }\n\n const span = _navigationIdToNavigationSpan.get(metric.navigationId);\n if (span) {\n return span;\n }\n\n // The `soft-navigation` observer may not have run for this navigation yet - entries from\n // different observers aren't delivered in a guaranteed order - so fall back to the join key the\n // metric carries itself.\n return metric.navigationInteractionId != null\n ? _interactionIdToNavigationSpan.get(metric.navigationInteractionId)\n : undefined;\n}\n"],"names":["LRUMap","WINDOW","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_OP","isPerformanceEventTiming","addPerformanceInstrumentationHandler","DEBUG_BUILD","debug","BROWSER_NAVIGATION_ID"],"mappings":";;;;;;;;AAYA,MAAM,uBAAA,GAA0B,CAAA;AAMhC,MAAM,8BAAA,GAAiC,CAAA;AAmBvC,IAAI,kBAAA;AAEJ,IAAI,mBAAA;AAGJ,IAAI,yBAAA;AAEJ,MAAM,8BAAA,GAAiC,IAAIA,WAAA,CAAqB,uBAAuB,CAAA;AACvF,MAAM,6BAAA,GAAgC,IAAIA,WAAA,CAAqB,uBAAuB,CAAA;AAEtF,IAAI,mBAAA,GAAsB,KAAA;AAM1B,SAAS,kBAAA,CAAmB,gBAAwB,oBAAA,EAAuC;AACzF,EAAA,OAAO,IAAA,CAAK,GAAA,CAAI,cAAA,GAAiB,oBAAoB,CAAA,IAAK,8BAAA;AAC5D;AAQO,SAAS,uBAAA,GAAmC;AACjD,EAAA,IAAI;AACF,IAAA,OACE,mBAAA,CAAoB,mBAAA,CAAoB,QAAA,CAAS,iBAAiB,CAAA;AAAA;AAAA,IAGlE,OACEC,YAAA,CAGA,yBAAA,EAA2B,SAAA,EAAW,oCAAA,KAAyC,UAAA;AAAA,EAErF,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,KAAA;AAAA,EACT;AACF;AAoBO,SAAS,+BAA+B,MAAA,EAAsB;AACnE,EAAA,IAAI,mBAAA,IAAuB,CAAC,uBAAA,EAAwB,EAAG;AACrD,IAAA;AAAA,EACF;AACA,EAAA,mBAAA,GAAsB,IAAA;AAEtB,EAAA,MAAM,aAAA,GAAgB,CAAC,KAAA,KAAuB;AAC5C,IAAA,IAAI,MAAM,SAAA,EAAW;AACnB,MAAA,yBAAA,GAA4B,KAAA,CAAM,SAAA;AAAA,IACpC;A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,CAAA;AAClE,EAAA,IAAI,IAAA,EAAM;AACR,IAAA,OAAO,IAAA;AAAA,EACT;AAKA,EAAA,OAAO,OAAO,uBAAA,IAA2B,IAAA,GACrC,+BAA+B,GAAA,CAAI,MAAA,CAAO,uBAAuB,CAAA,GACjE,MAAA;AACN;;;;;;"}
|
|
1
|
+
{"version":3,"file":"softNavs.js","sources":["../../../src/web-vitals/softNavs.ts"],"sourcesContent":["import type { Client, Span } from '@sentry/core';\nimport { debug, LRUMap, spanToJSON } from '@sentry/core';\nimport { BROWSER_NAVIGATION_ID, SENTRY_OP } from '@sentry/conventions/attributes';\nimport { DEBUG_BUILD } from '../debug-build';\nimport type { PerformanceSoftNavigation } from '../instrumentation/performanceObserver';\nimport { addPerformanceInstrumentationHandler, isPerformanceEventTiming } from '../instrumentation/performanceObserver';\nimport { WINDOW } from '../types';\n\n/**\n * A page only ever needs its most recent navigations to still be joinable: web vitals for a soft\n * navigation are finalized at the next soft navigation or on pagehide, never later than that.\n */\nconst MAX_TRACKED_NAVIGATIONS = 5;\n\n/**\n * Tolerance when matching a DOM event's `timeStamp` against the `startTime` of its Event Timing\n * entry. Both are `DOMHighResTimeStamp`s from the same clock, so this only absorbs rounding.\n */\nconst INTERACTION_MATCH_TOLERANCE_MS = 5;\n\ninterface SoftNavMetric {\n navigationType: string;\n navigationId: number;\n navigationInteractionId?: number;\n}\n\ninterface PendingNavigation {\n span: Span;\n interactionTimestamp: number;\n}\n\ninterface PendingInteraction {\n interactionId: number;\n interactionTimestamp: number;\n}\n\n// The navigation span whose triggering interaction we haven't identified yet.\nlet _pendingNavigation: PendingNavigation | undefined;\n// The interaction whose Event Timing entry arrived before any navigation span claimed it.\nlet _pendingInteraction: PendingInteraction | undefined;\n// The timestamp of the most recent trusted click/keydown, i.e. our best guess at the interaction\n// that a history change happening right now was driven by.\nlet _lastInteractionTimestamp: number | undefined;\n\nconst _interactionIdToNavigationSpan = new LRUMap<number, Span>(MAX_TRACKED_NAVIGATIONS);\nconst _navigationIdToNavigationSpan = new LRUMap<number, Span>(MAX_TRACKED_NAVIGATIONS);\n\nlet _correlationStarted = false;\n\n/**\n * Whether an Event Timing entry's `startTime` and a DOM event's `timeStamp` name the same\n * interaction.\n */\nfunction interactionMatches(entryStartTime: number, interactionTimestamp: number): boolean {\n return Math.abs(entryStartTime - interactionTimestamp) <= INTERACTION_MATCH_TOLERANCE_MS;\n}\n\n/**\n * Whether the browser can report web vitals for soft navigations.\n *\n * This mirrors web-vitals' own feature detection: passing `reportSoftNavs` on a browser that fails\n * this check is a no-op there, so it has to be a no-op here too.\n */\nexport function supportsSoftNavigations(): boolean {\n try {\n return (\n PerformanceObserver.supportedEntryTypes.includes('soft-navigation') &&\n // Older implementations exposed this as an attribute rather than a method. Only the method\n // form shipped unflagged, so it's what web-vitals gates on.\n typeof (\n WINDOW as {\n PerformanceSoftNavigation?: { prototype?: { getLargestInteractionContentfulPaint?: unknown } };\n }\n ).PerformanceSoftNavigation?.prototype?.getLargestInteractionContentfulPaint === 'function'\n );\n } catch {\n return false;\n }\n}\n\n/**\n * Start correlating the browser's soft navigations with the SDK's navigation spans.\n *\n * A navigation span is created synchronously on the history change, but the browser only mints the\n * `soft-navigation` entry (and with it the `navigationId` that web vitals are reported against)\n * once the navigation has been confirmed by a paint. So the `navigationId` cannot be known at span\n * creation time and the two have to be joined after the fact.\n *\n * The join key is the `interactionId` of the interaction that drove the navigation: per the Soft\n * Navigations spec the `soft-navigation` entry carries the `interactionId` of the interaction that\n * triggered it, which is the same id the interaction's own `PerformanceEventTiming` entry carries.\n * So we bind a navigation span to the interaction it happened during, and the soft navigation\n * joins back to that span through the shared id.\n *\n * This is inherently partial. Navigations that don't meet the browser's soft navigation heuristic\n * (programmatic navigations, navigations that never paint, back/forward from the browser chrome)\n * produce no entry at all, so those navigation spans simply have no web vitals.\n */\nexport function startSoftNavigationCorrelation(client: Client): void {\n if (_correlationStarted || !supportsSoftNavigations()) {\n return;\n }\n _correlationStarted = true;\n\n const onInteraction = (event: Event): void => {\n if (event.isTrusted) {\n _lastInteractionTimestamp = event.timeStamp;\n }\n };\n // Only click and keydown can start a soft navigation, which is also what the SDK's redirect\n // detection listens for.\n WINDOW.addEventListener('click', onInteraction, { capture: true, passive: true });\n WINDOW.addEventListener('keydown', onInteraction, { capture: true, passive: true });\n\n client.on('spanStart', span => {\n if (spanToJSON(span).attributes?.[SENTRY_OP] !== 'navigation') {\n return;\n }\n\n // A navigation with no preceding interaction can't produce a soft navigation, so there is\n // nothing to wait for. Dropping the pending span here also keeps us from binding a stale one.\n _pendingNavigation = undefined;\n const interactionTimestamp = _lastInteractionTimestamp;\n if (interactionTimestamp == null) {\n return;\n }\n\n // The interaction's entry may already be here: the router code that starts this span races the\n // paint that flushes the entry, so either one can win.\n if (_pendingInteraction?.interactionTimestamp === interactionTimestamp) {\n _interactionIdToNavigationSpan.set(_pendingInteraction.interactionId, span);\n _pendingInteraction = undefined;\n return;\n }\n\n _pendingNavigation = { span, interactionTimestamp };\n });\n\n const bindInteractionToNavigationSpan = ({ entries }: { entries: PerformanceEntry[] }): void => {\n for (const entry of entries) {\n if (!isPerformanceEventTiming(entry) || !entry.interactionId) {\n continue;\n }\n\n const pending = _pendingNavigation;\n if (pending && interactionMatches(entry.startTime, pending.interactionTimestamp)) {\n _interactionIdToNavigationSpan.set(entry.interactionId, pending.span);\n _pendingNavigation = undefined;\n continue;\n }\n\n // Once a navigation span has claimed this interaction, only a span that is still waiting can\n // rebind it, which the check above already allows. Holding on to the interaction's remaining\n // entries would instead let an unrelated later navigation claim it.\n if (_interactionIdToNavigationSpan.get(entry.interactionId)) {\n continue;\n }\n\n // The navigation span this interaction drove may still be on its way, so hold on to the\n // interaction instead of dropping it. Only the most recent one is worth keeping:\n // `_lastInteractionTimestamp` is what `spanStart` matches against and it only moves forward,\n // so an entry that doesn't match it now can never match it later.\n if (_lastInteractionTimestamp != null && interactionMatches(entry.startTime, _lastInteractionTimestamp)) {\n _pendingInteraction = { interactionId: entry.interactionId, interactionTimestamp: _lastInteractionTimestamp };\n }\n }\n };\n\n // `durationThreshold: 0` is applied for `event` by the shared observer, which matters here:\n // interactions below the 104ms default would otherwise never surface an `interactionId`.\n addPerformanceInstrumentationHandler('event', bindInteractionToNavigationSpan);\n addPerformanceInstrumentationHandler('first-input', bindInteractionToNavigationSpan);\n\n addPerformanceInstrumentationHandler('soft-navigation', ({ entries }) => {\n for (const entry of entries as PerformanceSoftNavigation[]) {\n const span = _interactionIdToNavigationSpan.get(entry.interactionId);\n if (!span) {\n DEBUG_BUILD && debug.log(`[SoftNav] No navigation span found for soft navigation ${entry.navigationId}`, entry);\n continue;\n }\n\n _navigationIdToNavigationSpan.set(entry.navigationId, span);\n // Best effort: the soft navigation entry usually lands well within the navigation span's idle\n // window, but if the span has already been sent this attribute is dropped.\n span.setAttribute(BROWSER_NAVIGATION_ID, entry.navigationId);\n }\n });\n}\n\n/**\n * The navigation span a soft navigation web vital belongs to, or `undefined` if the metric isn't\n * for a soft navigation or we failed to correlate it.\n */\nexport function getNavigationSpanForMetric(metric: SoftNavMetric): Span | undefined {\n if (metric.navigationType !== 'soft-navigation') {\n return undefined;\n }\n\n const span = _navigationIdToNavigationSpan.get(metric.navigationId);\n if (span) {\n return span;\n }\n\n // The `soft-navigation` observer may not have run for this navigation yet - entries from\n // different observers aren't delivered in a guaranteed order - so fall back to the join key the\n // metric carries itself.\n return metric.navigationInteractionId != null\n ? _interactionIdToNavigationSpan.get(metric.navigationInteractionId)\n : undefined;\n}\n"],"names":["LRUMap","WINDOW","spanToJSON","SENTRY_OP","isPerformanceEventTiming","addPerformanceInstrumentationHandler","DEBUG_BUILD","debug","BROWSER_NAVIGATION_ID"],"mappings":";;;;;;;;AAYA,MAAM,uBAAA,GAA0B,CAAA;AAMhC,MAAM,8BAAA,GAAiC,CAAA;AAmBvC,IAAI,kBAAA;AAEJ,IAAI,mBAAA;AAGJ,IAAI,yBAAA;AAEJ,MAAM,8BAAA,GAAiC,IAAIA,WAAA,CAAqB,u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+BAA+B,CAAA;AAC7E,EAAAA,wDAAA,CAAqC,eAAe,+BAA+B,CAAA;AAEnF,EAAAA,wDAAA,CAAqC,iBAAA,EAAmB,CAAC,EAAE,OAAA,EAAQ,KAAM;AACvE,IAAA,KAAA,MAAW,SAAS,OAAA,EAAwC;AAC1D,MAAA,MAAM,IAAA,GAAO,8BAAA,CAA+B,GAAA,CAAI,KAAA,CAAM,aAAa,CAAA;AACnE,MAAA,IAAI,CAAC,IAAA,EAAM;AACT,QAAAC,sBAAA,IAAeC,WAAM,GAAA,CAAI,CAAA,uDAAA,EAA0D,KAAA,CAAM,YAAY,IAAI,KAAK,CAAA;AAC9G,QAAA;AAAA,MACF;AAEA,MAAA,6BAAA,CAA8B,GAAA,CAAI,KAAA,CAAM,YAAA,EAAc,IAAI,CAAA;AAG1D,MAAA,IAAA,CAAK,YAAA,CAAaC,gCAAA,EAAuB,KAAA,CAAM,YAAY,CAAA;AAAA,IAC7D;AAAA,EACF,CAAC,CAAA;AACH;AAMO,SAAS,2BAA2B,MAAA,EAAyC;AAClF,EAAA,IAAI,MAAA,CAAO,mBAAmB,iBAAA,EAAmB;AAC/C,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,MAAM,IAAA,GAAO,6BAAA,CAA8B,GAAA,CAAI,MAAA,CAAO,YAAY,CAAA;AAClE,EAAA,IAAI,IAAA,EAAM;AACR,IAAA,OAAO,IAAA;AAAA,EACT;AAKA,EAAA,OAAO,OAAO,uBAAA,IAA2B,IAAA,GACrC,+BAA+B,GAAA,CAAI,MAAA,CAAO,uBAAuB,CAAA,GACjE,MAAA;AACN;;;;;;"}
|
|
@@ -34,7 +34,7 @@ function trackWebVitalPerNavigation(client, addInstrumentationHandler, send) {
|
|
|
34
34
|
let bfcacheNavigationSpan;
|
|
35
35
|
client.on("spanStart", (span) => {
|
|
36
36
|
const attributes$1 = core.spanToJSON(span).attributes;
|
|
37
|
-
if (attributes$1?.[
|
|
37
|
+
if (attributes$1?.[attributes.SENTRY_OP] === op.NAVIGATION && attributes$1[attributes.BROWSER_NAVIGATION_TYPE] === "back-forward-cache") {
|
|
38
38
|
bfcacheNavigationSpan = span;
|
|
39
39
|
}
|
|
40
40
|
});
|
|
@@ -95,9 +95,9 @@ function _sendLcpSpan(lcpValue, entry, pageloadSpan, softNavigationId, navigatio
|
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
97
|
debugBuild.DEBUG_BUILD && core.debug.log(`Sending LCP span (${lcpValue})`);
|
|
98
|
-
const
|
|
99
|
-
const startTime =
|
|
100
|
-
const endTime = entry ? utils.msToSec(
|
|
98
|
+
const navigationStart = navigationStartTime || 0;
|
|
99
|
+
const startTime = core._INTERNAL_performanceTimeToSeconds(navigationStart) ?? utils.msToSec(navigationStart);
|
|
100
|
+
const endTime = entry ? core._INTERNAL_performanceTimeToSeconds(entry.startTime, navigationStart) ?? utils.msToSec(entry.startTime) : startTime + utils.msToSec(lcpValue);
|
|
101
101
|
const selector = entry ? htmlTreeAsString.htmlTreeAsString(entry.element) : void 0;
|
|
102
102
|
const componentName$1 = entry?.element ? componentName.getComponentName(entry.element) : null;
|
|
103
103
|
const client = core.getClient();
|
|
@@ -166,9 +166,8 @@ function trackClsAsSpan(client, perNavigation = false) {
|
|
|
166
166
|
}
|
|
167
167
|
function _sendClsSpan(clsValue, entry, pageloadSpan, softNavigationId, navigationType, navigationStartTime) {
|
|
168
168
|
debugBuild.DEBUG_BUILD && core.debug.log(`Sending CLS span (${clsValue})`);
|
|
169
|
-
const performanceTimeOrigin = core.browserPerformanceTimeOrigin();
|
|
170
169
|
const offset = entry?.startTime ?? navigationStartTime ?? 0;
|
|
171
|
-
const startTime =
|
|
170
|
+
const startTime = core._INTERNAL_performanceTimeToSeconds(offset) ?? core.timestampInSeconds();
|
|
172
171
|
const firstSourceNode = entry?.sources[0]?.node;
|
|
173
172
|
const selector = entry ? htmlTreeAsString.htmlTreeAsString(firstSourceNode) : void 0;
|
|
174
173
|
const componentName$1 = firstSourceNode ? componentName.getComponentName(firstSourceNode) : null;
|
|
@@ -226,9 +225,10 @@ function findInpEntry(metric) {
|
|
|
226
225
|
}
|
|
227
226
|
function _sendInpSpan(inpValue, entry, standalone = false, attributedSpan, softNavigationId, metric) {
|
|
228
227
|
debugBuild.DEBUG_BUILD && core.debug.log(`Sending INP span (${inpValue})`);
|
|
229
|
-
const startTime =
|
|
230
|
-
|
|
231
|
-
|
|
228
|
+
const startTime = core._INTERNAL_performanceTimeToSeconds(entry?.startTime ?? metric?.navigationStartTime ?? 0);
|
|
229
|
+
if (!startTime) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
232
|
const duration = utils.msToSec(inpValue);
|
|
233
233
|
const entryInteractionType = entry && inp.INP_ENTRY_MAP[entry.name];
|
|
234
234
|
const interactionType = entryInteractionType || "click";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spans.js","sources":["../../../src/web-vitals/spans.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport type { Client, Span, SpanAttributes } from '@sentry/core';\nimport {\n browserPerformanceTimeOrigin,\n debug,\n getActiveSpan,\n getClient,\n getRootSpan,\n hasSpanStreamingEnabled,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n spanToJSON,\n timestampInSeconds,\n UI_INTERACTION_CLICK_SPAN_NAME_FALLBACK,\n UI_INTERACTION_DRAG_SPAN_NAME_FALLBACK,\n UI_INTERACTION_HOVER_SPAN_NAME_FALLBACK,\n UI_INTERACTION_PRESS_SPAN_NAME_FALLBACK,\n UI_WEBVITAL_CLS_SPAN_NAME_FALLBACK,\n UI_WEBVITAL_LCP_SPAN_NAME_FALLBACK,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { htmlTreeAsString } from '../htmlTreeAsString';\nimport { getComponentName } from '../component-name';\nimport type { InteractionType } from './inp';\nimport { getCachedInteractionContext, INP_ENTRY_MAP, MAX_PLAUSIBLE_INP_DURATION, UNKNOWN_ELEMENT_NAME } from './inp';\nimport type { InstrumentationHandlerCallback, MetricNavigationType } from '../instrumentation/performanceObserver';\nimport {\n addClsInstrumentationHandler,\n addInpInstrumentationHandler,\n addLcpInstrumentationHandler,\n} from '../instrumentation/performanceObserver';\nimport type { LargestContentfulPaint, LayoutShift } from './emitSpan';\nimport {\n SENTRY_EXCLUSIVE_TIME,\n BROWSER_NAVIGATION_TYPE,\n BROWSER_WEB_VITAL_INP_INTERACTION_TYPE,\n BROWSER_WEB_VITAL_INP_TARGET,\n UI_COMPONENT_NAME,\n} from '@sentry/conventions/attributes';\nimport { _emitWebVitalSpan } from './emitSpan';\nimport { isValidLcpMetric } from './lcp';\nimport { listenForWebVitalReportEvents } from './reportEvents';\nimport { getNavigationSpanForMetric } from './softNavs';\nimport { getBrowserPerformanceAPI, msToSec, supportsWebVital } from '../performance/utils';\nimport type { PerformanceEventTiming } from '../instrumentation/performanceObserver';\nimport {\n NAVIGATION,\n UI_INTERACTION_CLICK,\n UI_INTERACTION_DRAG,\n UI_INTERACTION_HOVER,\n UI_INTERACTION_PRESS,\n UI_WEBVITAL_CLS,\n UI_WEBVITAL_LCP,\n} from '@sentry/conventions/op';\n\nconst INTERACTION_TYPE_TO_SPAN_OP: Record<InteractionType, string> = {\n click: UI_INTERACTION_CLICK,\n hover: UI_INTERACTION_HOVER,\n drag: UI_INTERACTION_DRAG,\n press: UI_INTERACTION_PRESS,\n};\n\nconst INTERACTION_TYPE_TO_SPAN_NAME_FALLBACK: Record<InteractionType, string> = {\n click: UI_INTERACTION_CLICK_SPAN_NAME_FALLBACK,\n hover: UI_INTERACTION_HOVER_SPAN_NAME_FALLBACK,\n drag: UI_INTERACTION_DRAG_SPAN_NAME_FALLBACK,\n press: UI_INTERACTION_PRESS_SPAN_NAME_FALLBACK,\n};\n\ntype WebVitalMetric = Parameters<Parameters<typeof addLcpInstrumentationHandler>[0]>[0]['metric'];\ntype InpMetric = Parameters<InstrumentationHandlerCallback>[0]['metric'];\n\n/**\n * Reports a web vital once per navigation, rather than once per page load.\n *\n * web-vitals restarts the metric on every soft navigation and force-reports the previous one just\n * before it does (and again on pagehide), and re-reports every metric after a bfcache restore.\n * Since `reportAllChanges` is off in this mode, every value we're handed is already the final one\n * for its navigation, so there is nothing to accumulate: each report is a span.\n */\nfunction trackWebVitalPerNavigation<M extends WebVitalMetric>(\n client: Client,\n addInstrumentationHandler: (callback: (data: { metric: M }) => void) => unknown,\n send: (metric: M, parentSpan: Span | undefined, softNavigationId: number | undefined) => void,\n): void {\n let pageloadSpan: Span | undefined;\n client.on('afterStartPageLoadSpan', span => {\n pageloadSpan = span;\n });\n\n // Remembered when the restore happens rather than read back at report time: the restore\n // navigation span is an idle span, and CLS and INP are only finalized on pagehide, by which point\n // it has long ended and is no longer what is active.\n let bfcacheNavigationSpan: Span | undefined;\n client.on('spanStart', span => {\n // The op has to be checked too: the web vital spans emitted for a restore carry the same\n // `back-forward-cache` navigation type, so matching on that alone lets the first of them replace the\n // navigation span, and every later vital then hangs off a sibling vital instead.\n const attributes = spanToJSON(span).attributes;\n if (\n attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_OP] === NAVIGATION &&\n attributes[BROWSER_NAVIGATION_TYPE] === 'back-forward-cache'\n ) {\n bfcacheNavigationSpan = span;\n }\n });\n\n addInstrumentationHandler(({ metric }) => {\n const navigationSpan = getNavigationSpanForMetric(metric);\n if (metric.navigationType === 'soft-navigation') {\n // Reporting an uncorrelated soft navigation vital would attribute it to the wrong route, so\n // it's dropped instead.\n if (navigationSpan) {\n send(metric, navigationSpan, metric.navigationId);\n } else {\n DEBUG_BUILD &&\n debug.log(`[SoftNav] Dropping ${metric.name} for uncorrelated soft navigation ${metric.navigationId}`);\n }\n return;\n }\n\n if (metric.navigationType === 'back-forward-cache') {\n // A restore reuses the frozen document, so the pageload span above belongs to the page view\n // from before the freeze. The navigation span started for the restore is the page view these\n // values were actually measured on.\n send(metric, bfcacheNavigationSpan, undefined);\n return;\n }\n\n send(metric, pageloadSpan, undefined);\n });\n}\n\n/**\n * Tracks LCP as a streamed span.\n */\nexport function trackLcpAsSpan(client: Client, perNavigation = false): void {\n if (!supportsWebVital('largest-contentful-paint')) {\n return;\n }\n\n if (perNavigation) {\n trackWebVitalPerNavigation(client, addLcpInstrumentationHandler, (metric, parentSpan, softNavigationId) => {\n const entry = metric.entries[metric.entries.length - 1] as LargestContentfulPaint | undefined;\n _sendLcpSpan(\n metric.value,\n entry,\n parentSpan,\n softNavigationId,\n metric.navigationType,\n metric.navigationStartTime,\n );\n });\n return;\n }\n\n let lcpValue = 0;\n let lcpEntry: LargestContentfulPaint | undefined;\n let lcpNavigationType: MetricNavigationType | undefined;\n\n const cleanupLcpHandler = addLcpInstrumentationHandler(({ metric }) => {\n // The navigation type describes the page, not the entry, so it is worth keeping even for a\n // report we otherwise discard.\n lcpNavigationType = metric.navigationType;\n\n const entry = metric.entries[metric.entries.length - 1] as LargestContentfulPaint | undefined;\n if (!entry || !isValidLcpMetric(metric.value)) {\n return;\n }\n lcpValue = metric.value;\n lcpEntry = entry;\n }, true);\n\n listenForWebVitalReportEvents(client, pageloadSpan => {\n _sendLcpSpan(lcpValue, lcpEntry, pageloadSpan, undefined, lcpNavigationType);\n cleanupLcpHandler();\n });\n}\n\n/**\n * Exported only for testing.\n */\nexport function _sendLcpSpan(\n lcpValue: number,\n entry: LargestContentfulPaint | undefined,\n pageloadSpan?: Span,\n softNavigationId?: number,\n navigationType?: MetricNavigationType,\n navigationStartTime?: number,\n): void {\n if (!isValidLcpMetric(lcpValue)) {\n return;\n }\n\n DEBUG_BUILD && debug.log(`Sending LCP span (${lcpValue})`);\n\n const performanceTimeOrigin = browserPerformanceTimeOrigin() || 0;\n // A soft navigation's LCP is measured from the triggering interaction, not the document time\n // origin. Starting the span there too keeps it inside the navigation span it is parented to and\n // keeps its duration equal to the value it reports.\n const startTime = msToSec(performanceTimeOrigin + (navigationStartTime || 0));\n // Without an entry there is no render time to end at, so the span lasts the value it reports,\n // like an entry-less INP does. Ending at the time origin instead would invert the span.\n const endTime = entry ? msToSec(performanceTimeOrigin + entry.startTime) : startTime + msToSec(lcpValue);\n const selector = entry ? htmlTreeAsString(entry.element) : undefined;\n const componentName = entry?.element ? getComponentName(entry.element) : null;\n const client = getClient();\n const hasSpanStreaming = !!client && hasSpanStreamingEnabled(client);\n const name = hasSpanStreaming\n ? componentName || UI_WEBVITAL_LCP_SPAN_NAME_FALLBACK\n : (selector ?? UI_WEBVITAL_LCP_SPAN_NAME_FALLBACK);\n\n const attributes: SpanAttributes = {};\n\n if (selector) {\n attributes['browser.web_vital.lcp.element'] = selector;\n }\n if (componentName) {\n attributes[UI_COMPONENT_NAME] = componentName;\n }\n entry?.id && (attributes['browser.web_vital.lcp.id'] = entry.id);\n entry?.url && (attributes['browser.web_vital.lcp.url'] = entry.url);\n entry?.loadTime != null && (attributes['browser.web_vital.lcp.load_time'] = entry.loadTime);\n entry?.renderTime != null && (attributes['browser.web_vital.lcp.render_time'] = entry.renderTime);\n entry?.size != null && (attributes['browser.web_vital.lcp.size'] = entry.size);\n\n _emitWebVitalSpan({\n name,\n op: UI_WEBVITAL_LCP,\n origin: 'auto.http.browser.lcp',\n metricName: 'lcp',\n value: lcpValue,\n attributes,\n parentSpan: pageloadSpan,\n startTime,\n endTime,\n softNavigationId,\n navigationType,\n });\n}\n\n/**\n * Tracks CLS as a streamed span.\n */\nexport function trackClsAsSpan(client: Client, perNavigation = false): void {\n if (!supportsWebVital('layout-shift')) {\n return;\n }\n\n if (perNavigation) {\n trackWebVitalPerNavigation(client, addClsInstrumentationHandler, (metric, parentSpan, softNavigationId) => {\n const entry = metric.entries[metric.entries.length - 1] as LayoutShift | undefined;\n _sendClsSpan(\n metric.value,\n entry,\n parentSpan,\n softNavigationId,\n metric.navigationType,\n metric.navigationStartTime,\n );\n });\n return;\n }\n\n let clsValue = 0;\n let clsEntry: LayoutShift | undefined;\n let clsNavigationType: MetricNavigationType | undefined;\n\n const cleanupClsHandler = addClsInstrumentationHandler(({ metric }) => {\n // A CLS of 0 is reported with no entries and still emits a span, so the navigation type has to\n // be captured before the entry check rather than alongside the value.\n clsNavigationType = metric.navigationType;\n\n const entry = metric.entries[metric.entries.length - 1] as LayoutShift | undefined;\n if (!entry) {\n return;\n }\n clsValue = metric.value;\n clsEntry = entry;\n }, true);\n\n listenForWebVitalReportEvents(client, pageloadSpan => {\n _sendClsSpan(clsValue, clsEntry, pageloadSpan, undefined, clsNavigationType);\n cleanupClsHandler();\n });\n}\n\n/**\n * Exported only for testing.\n */\nexport function _sendClsSpan(\n clsValue: number,\n entry: LayoutShift | undefined,\n pageloadSpan?: Span,\n softNavigationId?: number,\n navigationType?: MetricNavigationType,\n navigationStartTime?: number,\n): void {\n DEBUG_BUILD && debug.log(`Sending CLS span (${clsValue})`);\n\n const performanceTimeOrigin = browserPerformanceTimeOrigin();\n // A CLS of 0 has no shift to place the span at. It is reported when the navigation it was\n // measured on is already over - the next soft navigation, or pagehide - so the current time would\n // land it outside that navigation, on the route that follows it.\n const offset = entry?.startTime ?? navigationStartTime ?? 0;\n const startTime = performanceTimeOrigin ? msToSec(performanceTimeOrigin + offset) : timestampInSeconds();\n const firstSourceNode = entry?.sources[0]?.node;\n const selector = entry ? htmlTreeAsString(firstSourceNode) : undefined;\n const componentName = firstSourceNode ? getComponentName(firstSourceNode) : null;\n const client = getClient();\n const hasSpanStreaming = !!client && hasSpanStreamingEnabled(client);\n const name = hasSpanStreaming\n ? componentName || UI_WEBVITAL_CLS_SPAN_NAME_FALLBACK\n : (selector ?? UI_WEBVITAL_CLS_SPAN_NAME_FALLBACK);\n\n const attributes: SpanAttributes = {};\n\n if (componentName) {\n attributes[UI_COMPONENT_NAME] = componentName;\n }\n\n if (entry?.sources) {\n entry.sources.forEach((source, index) => {\n attributes[`browser.web_vital.cls.source.${index + 1}`] = htmlTreeAsString(source.node);\n });\n }\n\n _emitWebVitalSpan({\n name,\n op: UI_WEBVITAL_CLS,\n origin: 'auto.http.browser.cls',\n metricName: 'cls',\n value: clsValue,\n attributes,\n parentSpan: pageloadSpan,\n startTime,\n softNavigationId,\n navigationType,\n });\n}\n\n/**\n * Tracks INP and emits it as a web vital span, as a child of the interaction's root span.\n * Requires `registerInpInteractionListener()` to be called separately for cached element names and\n * root spans per interaction.\n */\nexport function trackInpAsSpan(client: Client, perNavigation = false): void {\n const performance = getBrowserPerformanceAPI();\n if (!performance || !browserPerformanceTimeOrigin()) {\n return;\n }\n\n // INP reports late (on pagehide, after the pageload span has ended). With span streaming enabled\n // it rides the streaming pipeline. With streaming disabled it would be dropped as a late span, so\n // it is emitted as its own standalone v2 span instead (see `_emitWebVitalSpan`), overriding the\n // static trace lifecycle for INP only.\n // TODO(standalone): once the static trace lifecycle is dropped, INP always streams; drop this flag.\n const standalone = !hasSpanStreamingEnabled(client);\n\n if (perNavigation) {\n // INP restarts per navigation and reports once that navigation is over, by which point the\n // navigation span has ended and the interaction cache no longer knows about it. The metric\n // says which navigation it belongs to, so INP is attributed exactly like LCP and CLS.\n trackWebVitalPerNavigation(client, addInpInstrumentationHandler, (metric, parentSpan, softNavigationId) => {\n if (isPlausibleInp(metric)) {\n _sendInpSpan(metric.value, findInpEntry(metric), standalone, parentSpan, softNavigationId, metric);\n }\n });\n return;\n }\n\n const onInp: InstrumentationHandlerCallback = ({ metric }) => {\n if (isPlausibleInp(metric)) {\n _sendInpSpan(metric.value, findInpEntry(metric), standalone, undefined, undefined, metric);\n }\n };\n\n addInpInstrumentationHandler(onInp);\n}\n\nfunction isPlausibleInp(metric: InpMetric): boolean {\n return metric.value != null && msToSec(metric.value) <= MAX_PLAUSIBLE_INP_DURATION;\n}\n\n/**\n * The entry an INP span is built from: the one whose duration the reported value came from.\n *\n * There isn't always one. When every interaction of a soft navigation stayed below the Event Timing\n * threshold, web-vitals reports a synthetic value with no entries at all - see\n * `_estimateP98LongestInteraction`. The span still gets reported in that case, just without the\n * element and interaction type an entry would have supplied.\n */\nfunction findInpEntry(metric: InpMetric): PerformanceEventTiming | undefined {\n return metric.entries.find(e => e.duration === metric.value && INP_ENTRY_MAP[e.name]);\n}\n\n/**\n * Exported only for testing.\n */\nexport function _sendInpSpan(\n inpValue: number,\n entry: PerformanceEventTiming | undefined,\n standalone = false,\n attributedSpan?: Span,\n softNavigationId?: number,\n metric?: InpMetric,\n): void {\n DEBUG_BUILD && debug.log(`Sending INP span (${inpValue})`);\n\n // A web vital span carries the metric, not a real interaction timing, so an INP without an entry\n // is still worth reporting. It just has no element or interaction type to describe, and is placed\n // at the start of the navigation it belongs to rather than at the interaction.\n const startTime = msToSec(\n (browserPerformanceTimeOrigin() as number) + (entry?.startTime ?? metric?.navigationStartTime ?? 0),\n );\n const duration = msToSec(inpValue);\n // An INP without an entry has no interaction type to report. It still has to land inside the\n // `ui.interaction.*` family, because falling outside it would hide exactly the fast navigations\n // that web-vitals synthesizes these values for (GoogleChrome/web-vitals#724), reintroducing the\n // reporting bias they were added to remove.\n const entryInteractionType = entry && INP_ENTRY_MAP[entry.name];\n const interactionType = entryInteractionType || 'click';\n\n const cachedContext = entry && getCachedInteractionContext(entry.interactionId);\n const activeSpan = getActiveSpan();\n const rootSpan = activeSpan ? getRootSpan(activeSpan) : undefined;\n\n // With soft navigations the caller knows exactly which navigation the metric belongs to. Without\n // them we fall back to the span that was active when the interaction was observed.\n const spanToUse = attributedSpan || cachedContext?.span || rootSpan;\n const selector = cachedContext?.elementName || (entry ? htmlTreeAsString(entry.target) : undefined);\n const componentName = entry?.target ? getComponentName(entry.target) : null;\n const client = getClient();\n const hasSpanStreaming = !!client && hasSpanStreamingEnabled(client);\n const fallbackName = INTERACTION_TYPE_TO_SPAN_NAME_FALLBACK[interactionType];\n const name = hasSpanStreaming ? componentName || fallbackName : (selector ?? 'Interaction to next paint');\n\n const attributes: SpanAttributes = {\n [SENTRY_EXCLUSIVE_TIME]: entry?.duration ?? inpValue,\n };\n\n // The span's name and op always have a value, even for an INP without an entry, so they can't\n // say whether there was an interaction to describe. These attributes can: they are only set for\n // what was actually observed. The name no longer holds the selector either, now that it is the\n // component name or the op's fallback under span streaming.\n selector && selector !== UNKNOWN_ELEMENT_NAME && (attributes[BROWSER_WEB_VITAL_INP_TARGET] = selector);\n entryInteractionType && (attributes[BROWSER_WEB_VITAL_INP_INTERACTION_TYPE] = entryInteractionType);\n\n if (componentName) {\n attributes[UI_COMPONENT_NAME] = componentName;\n }\n\n _emitWebVitalSpan({\n name,\n op: INTERACTION_TYPE_TO_SPAN_OP[interactionType],\n origin: 'auto.http.browser.inp',\n metricName: 'inp',\n value: inpValue,\n attributes,\n startTime,\n endTime: startTime + duration,\n navigationType: metric?.navigationType,\n parentSpan: spanToUse,\n standalone,\n softNavigationId,\n });\n}\n"],"names":["UI_INTERACTION_CLICK","UI_INTERACTION_HOVER","UI_INTERACTION_DRAG","UI_INTERACTION_PRESS","UI_INTERACTION_CLICK_SPAN_NAME_FALLBACK","UI_INTERACTION_HOVER_SPAN_NAME_FALLBACK","UI_INTERACTION_DRAG_SPAN_NAME_FALLBACK","UI_INTERACTION_PRESS_SPAN_NAME_FALLBACK","attributes","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_OP","NAVIGATION","BROWSER_NAVIGATION_TYPE","getNavigationSpanForMetric","DEBUG_BUILD","debug","supportsWebVital","addLcpInstrumentationHandler","isValidLcpMetric","listenForWebVitalReportEvents","browserPerformanceTimeOrigin","msToSec","htmlTreeAsString","componentName","getComponentName","getClient","hasSpanStreamingEnabled","UI_WEBVITAL_LCP_SPAN_NAME_FALLBACK","UI_COMPONENT_NAME","_emitWebVitalSpan","UI_WEBVITAL_LCP","addClsInstrumentationHandler","timestampInSeconds","UI_WEBVITAL_CLS_SPAN_NAME_FALLBACK","UI_WEBVITAL_CLS","getBrowserPerformanceAPI","addInpInstrumentationHandler","MAX_PLAUSIBLE_INP_DURATION","INP_ENTRY_MAP","getCachedInteractionContext","getActiveSpan","getRootSpan","SENTRY_EXCLUSIVE_TIME","UNKNOWN_ELEMENT_NAME","BROWSER_WEB_VITAL_INP_TARGET","BROWSER_WEB_V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,gBAAA,GAAmB,CAAC,CAAC,MAAA,IAAUC,6BAAwB,MAAM,CAAA;AACnE,EAAA,MAAM,YAAA,GAAe,uCAAuC,eAAe,CAAA;AAC3E,EAAA,MAAM,IAAA,GAAO,gBAAA,GAAmBH,eAAA,IAAiB,YAAA,GAAgB,QAAA,IAAY,2BAAA;AAE7E,EAAA,MAAMf,YAAA,GAA6B;AAAA,IACjC,CAACkC,gCAAqB,GAAG,KAAA,EAAO,QAAA,IAAY;AAAA,GAC9C;AAMA,EAAA,QAAA,IAAY,QAAA,KAAaC,wBAAA,KAAyBnC,YAAA,CAAWoC,uCAA4B,CAAA,GAAI,QAAA,CAAA;AAC7F,EAAA,oBAAA,KAAyBpC,YAAA,CAAWqC,iDAAsC,CAAA,GAAI,oBAAA,CAAA;AAE9E,EAAA,IAAItB,eAAA,EAAe;AACjB,IAAAf,YAAA,CAAWoB,4BAAiB,CAAA,GAAIL,eAAA;AAAA,EAClC;AAEA,EAAAM,0BAAA,CAAkB;AAAA,IAChB,IAAA;AAAA,IACA,EAAA,EAAI,4BAA4B,eAAe,CAAA;AAAA,IAC/C,MAAA,EAAQ,uBAAA;AAAA,IACR,UAAA,EAAY,KAAA;AAAA,IACZ,KAAA,EAAO,QAAA;AAAA,gBACPrB,YAAA;AAAA,IACA,SAAA;AAAA,IACA,SAAS,SAAA,GAAY,QAAA;AAAA,IACrB,gBAAgB,MAAA,EAAQ,cAAA;AAAA,IACxB,UAAA,EAAY,SAAA;AAAA,IACZ,UAAA;AAAA,IACA;AAAA,GACD,CAAA;AACH;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"spans.js","sources":["../../../src/web-vitals/spans.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport type { Client, Span, SpanAttributes } from '@sentry/core';\nimport {\n browserPerformanceTimeOrigin,\n debug,\n getActiveSpan,\n getClient,\n getRootSpan,\n hasSpanStreamingEnabled,\n _INTERNAL_performanceTimeToSeconds,\n spanToJSON,\n timestampInSeconds,\n UI_INTERACTION_CLICK_SPAN_NAME_FALLBACK,\n UI_INTERACTION_DRAG_SPAN_NAME_FALLBACK,\n UI_INTERACTION_HOVER_SPAN_NAME_FALLBACK,\n UI_INTERACTION_PRESS_SPAN_NAME_FALLBACK,\n UI_WEBVITAL_CLS_SPAN_NAME_FALLBACK,\n UI_WEBVITAL_LCP_SPAN_NAME_FALLBACK,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { htmlTreeAsString } from '../htmlTreeAsString';\nimport { getComponentName } from '../component-name';\nimport type { InteractionType } from './inp';\nimport { getCachedInteractionContext, INP_ENTRY_MAP, MAX_PLAUSIBLE_INP_DURATION, UNKNOWN_ELEMENT_NAME } from './inp';\nimport type { InstrumentationHandlerCallback, MetricNavigationType } from '../instrumentation/performanceObserver';\nimport {\n addClsInstrumentationHandler,\n addInpInstrumentationHandler,\n addLcpInstrumentationHandler,\n} from '../instrumentation/performanceObserver';\nimport type { LargestContentfulPaint, LayoutShift } from './emitSpan';\nimport {\n SENTRY_EXCLUSIVE_TIME,\n BROWSER_NAVIGATION_TYPE,\n BROWSER_WEB_VITAL_INP_INTERACTION_TYPE,\n BROWSER_WEB_VITAL_INP_TARGET,\n UI_COMPONENT_NAME,\n SENTRY_OP,\n} from '@sentry/conventions/attributes';\nimport { _emitWebVitalSpan } from './emitSpan';\nimport { isValidLcpMetric } from './lcp';\nimport { listenForWebVitalReportEvents } from './reportEvents';\nimport { getNavigationSpanForMetric } from './softNavs';\nimport { getBrowserPerformanceAPI, msToSec, supportsWebVital } from '../performance/utils';\nimport type { PerformanceEventTiming } from '../instrumentation/performanceObserver';\nimport {\n NAVIGATION,\n UI_INTERACTION_CLICK,\n UI_INTERACTION_DRAG,\n UI_INTERACTION_HOVER,\n UI_INTERACTION_PRESS,\n UI_WEBVITAL_CLS,\n UI_WEBVITAL_LCP,\n} from '@sentry/conventions/op';\n\nconst INTERACTION_TYPE_TO_SPAN_OP: Record<InteractionType, string> = {\n click: UI_INTERACTION_CLICK,\n hover: UI_INTERACTION_HOVER,\n drag: UI_INTERACTION_DRAG,\n press: UI_INTERACTION_PRESS,\n};\n\nconst INTERACTION_TYPE_TO_SPAN_NAME_FALLBACK: Record<InteractionType, string> = {\n click: UI_INTERACTION_CLICK_SPAN_NAME_FALLBACK,\n hover: UI_INTERACTION_HOVER_SPAN_NAME_FALLBACK,\n drag: UI_INTERACTION_DRAG_SPAN_NAME_FALLBACK,\n press: UI_INTERACTION_PRESS_SPAN_NAME_FALLBACK,\n};\n\ntype WebVitalMetric = Parameters<Parameters<typeof addLcpInstrumentationHandler>[0]>[0]['metric'];\ntype InpMetric = Parameters<InstrumentationHandlerCallback>[0]['metric'];\n\n/**\n * Reports a web vital once per navigation, rather than once per page load.\n *\n * web-vitals restarts the metric on every soft navigation and force-reports the previous one just\n * before it does (and again on pagehide), and re-reports every metric after a bfcache restore.\n * Since `reportAllChanges` is off in this mode, every value we're handed is already the final one\n * for its navigation, so there is nothing to accumulate: each report is a span.\n */\nfunction trackWebVitalPerNavigation<M extends WebVitalMetric>(\n client: Client,\n addInstrumentationHandler: (callback: (data: { metric: M }) => void) => unknown,\n send: (metric: M, parentSpan: Span | undefined, softNavigationId: number | undefined) => void,\n): void {\n let pageloadSpan: Span | undefined;\n client.on('afterStartPageLoadSpan', span => {\n pageloadSpan = span;\n });\n\n // Remembered when the restore happens rather than read back at report time: the restore\n // navigation span is an idle span, and CLS and INP are only finalized on pagehide, by which point\n // it has long ended and is no longer what is active.\n let bfcacheNavigationSpan: Span | undefined;\n client.on('spanStart', span => {\n // The op has to be checked too: the web vital spans emitted for a restore carry the same\n // `back-forward-cache` navigation type, so matching on that alone lets the first of them replace the\n // navigation span, and every later vital then hangs off a sibling vital instead.\n const attributes = spanToJSON(span).attributes;\n if (attributes?.[SENTRY_OP] === NAVIGATION && attributes[BROWSER_NAVIGATION_TYPE] === 'back-forward-cache') {\n bfcacheNavigationSpan = span;\n }\n });\n\n addInstrumentationHandler(({ metric }) => {\n const navigationSpan = getNavigationSpanForMetric(metric);\n if (metric.navigationType === 'soft-navigation') {\n // Reporting an uncorrelated soft navigation vital would attribute it to the wrong route, so\n // it's dropped instead.\n if (navigationSpan) {\n send(metric, navigationSpan, metric.navigationId);\n } else {\n DEBUG_BUILD &&\n debug.log(`[SoftNav] Dropping ${metric.name} for uncorrelated soft navigation ${metric.navigationId}`);\n }\n return;\n }\n\n if (metric.navigationType === 'back-forward-cache') {\n // A restore reuses the frozen document, so the pageload span above belongs to the page view\n // from before the freeze. The navigation span started for the restore is the page view these\n // values were actually measured on.\n send(metric, bfcacheNavigationSpan, undefined);\n return;\n }\n\n send(metric, pageloadSpan, undefined);\n });\n}\n\n/**\n * Tracks LCP as a streamed span.\n */\nexport function trackLcpAsSpan(client: Client, perNavigation = false): void {\n if (!supportsWebVital('largest-contentful-paint')) {\n return;\n }\n\n if (perNavigation) {\n trackWebVitalPerNavigation(client, addLcpInstrumentationHandler, (metric, parentSpan, softNavigationId) => {\n const entry = metric.entries[metric.entries.length - 1] as LargestContentfulPaint | undefined;\n _sendLcpSpan(\n metric.value,\n entry,\n parentSpan,\n softNavigationId,\n metric.navigationType,\n metric.navigationStartTime,\n );\n });\n return;\n }\n\n let lcpValue = 0;\n let lcpEntry: LargestContentfulPaint | undefined;\n let lcpNavigationType: MetricNavigationType | undefined;\n\n const cleanupLcpHandler = addLcpInstrumentationHandler(({ metric }) => {\n // The navigation type describes the page, not the entry, so it is worth keeping even for a\n // report we otherwise discard.\n lcpNavigationType = metric.navigationType;\n\n const entry = metric.entries[metric.entries.length - 1] as LargestContentfulPaint | undefined;\n if (!entry || !isValidLcpMetric(metric.value)) {\n return;\n }\n lcpValue = metric.value;\n lcpEntry = entry;\n }, true);\n\n listenForWebVitalReportEvents(client, pageloadSpan => {\n _sendLcpSpan(lcpValue, lcpEntry, pageloadSpan, undefined, lcpNavigationType);\n cleanupLcpHandler();\n });\n}\n\n/**\n * Exported only for testing.\n */\nexport function _sendLcpSpan(\n lcpValue: number,\n entry: LargestContentfulPaint | undefined,\n pageloadSpan?: Span,\n softNavigationId?: number,\n navigationType?: MetricNavigationType,\n navigationStartTime?: number,\n): void {\n if (!isValidLcpMetric(lcpValue)) {\n return;\n }\n\n DEBUG_BUILD && debug.log(`Sending LCP span (${lcpValue})`);\n\n // A soft navigation's LCP is measured from the triggering interaction, not the document time\n // origin. Starting the span there too keeps it inside the navigation span it is parented to and\n // keeps its duration equal to the reported value. The span's end uses the same origin, even if\n // the time origin was corrected in between.\n const navigationStart = navigationStartTime || 0;\n const startTime = _INTERNAL_performanceTimeToSeconds(navigationStart) ?? msToSec(navigationStart);\n // Without an entry there is no render time to end at, so the span lasts the value it reports,\n // like an entry-less INP does. Ending at the time origin instead would invert the span.\n const endTime = entry\n ? (_INTERNAL_performanceTimeToSeconds(entry.startTime, navigationStart) ?? msToSec(entry.startTime))\n : startTime + msToSec(lcpValue);\n const selector = entry ? htmlTreeAsString(entry.element) : undefined;\n const componentName = entry?.element ? getComponentName(entry.element) : null;\n const client = getClient();\n const hasSpanStreaming = !!client && hasSpanStreamingEnabled(client);\n const name = hasSpanStreaming\n ? componentName || UI_WEBVITAL_LCP_SPAN_NAME_FALLBACK\n : (selector ?? UI_WEBVITAL_LCP_SPAN_NAME_FALLBACK);\n\n const attributes: SpanAttributes = {};\n\n if (selector) {\n attributes['browser.web_vital.lcp.element'] = selector;\n }\n if (componentName) {\n attributes[UI_COMPONENT_NAME] = componentName;\n }\n entry?.id && (attributes['browser.web_vital.lcp.id'] = entry.id);\n entry?.url && (attributes['browser.web_vital.lcp.url'] = entry.url);\n entry?.loadTime != null && (attributes['browser.web_vital.lcp.load_time'] = entry.loadTime);\n entry?.renderTime != null && (attributes['browser.web_vital.lcp.render_time'] = entry.renderTime);\n entry?.size != null && (attributes['browser.web_vital.lcp.size'] = entry.size);\n\n _emitWebVitalSpan({\n name,\n op: UI_WEBVITAL_LCP,\n origin: 'auto.http.browser.lcp',\n metricName: 'lcp',\n value: lcpValue,\n attributes,\n parentSpan: pageloadSpan,\n startTime,\n endTime,\n softNavigationId,\n navigationType,\n });\n}\n\n/**\n * Tracks CLS as a streamed span.\n */\nexport function trackClsAsSpan(client: Client, perNavigation = false): void {\n if (!supportsWebVital('layout-shift')) {\n return;\n }\n\n if (perNavigation) {\n trackWebVitalPerNavigation(client, addClsInstrumentationHandler, (metric, parentSpan, softNavigationId) => {\n const entry = metric.entries[metric.entries.length - 1] as LayoutShift | undefined;\n _sendClsSpan(\n metric.value,\n entry,\n parentSpan,\n softNavigationId,\n metric.navigationType,\n metric.navigationStartTime,\n );\n });\n return;\n }\n\n let clsValue = 0;\n let clsEntry: LayoutShift | undefined;\n let clsNavigationType: MetricNavigationType | undefined;\n\n const cleanupClsHandler = addClsInstrumentationHandler(({ metric }) => {\n // A CLS of 0 is reported with no entries and still emits a span, so the navigation type has to\n // be captured before the entry check rather than alongside the value.\n clsNavigationType = metric.navigationType;\n\n const entry = metric.entries[metric.entries.length - 1] as LayoutShift | undefined;\n if (!entry) {\n return;\n }\n clsValue = metric.value;\n clsEntry = entry;\n }, true);\n\n listenForWebVitalReportEvents(client, pageloadSpan => {\n _sendClsSpan(clsValue, clsEntry, pageloadSpan, undefined, clsNavigationType);\n cleanupClsHandler();\n });\n}\n\n/**\n * Exported only for testing.\n */\nexport function _sendClsSpan(\n clsValue: number,\n entry: LayoutShift | undefined,\n pageloadSpan?: Span,\n softNavigationId?: number,\n navigationType?: MetricNavigationType,\n navigationStartTime?: number,\n): void {\n DEBUG_BUILD && debug.log(`Sending CLS span (${clsValue})`);\n\n // A CLS of 0 has no shift to place the span at. It is reported when the navigation it was\n // measured on is already over - the next soft navigation, or pagehide - so the current time would\n // land it outside that navigation, on the route that follows it.\n const offset = entry?.startTime ?? navigationStartTime ?? 0;\n // CLS is only reported on pagehide, so we use the time origin from when the layout shift happened.\n const startTime = _INTERNAL_performanceTimeToSeconds(offset) ?? timestampInSeconds();\n const firstSourceNode = entry?.sources[0]?.node;\n const selector = entry ? htmlTreeAsString(firstSourceNode) : undefined;\n const componentName = firstSourceNode ? getComponentName(firstSourceNode) : null;\n const client = getClient();\n const hasSpanStreaming = !!client && hasSpanStreamingEnabled(client);\n const name = hasSpanStreaming\n ? componentName || UI_WEBVITAL_CLS_SPAN_NAME_FALLBACK\n : (selector ?? UI_WEBVITAL_CLS_SPAN_NAME_FALLBACK);\n\n const attributes: SpanAttributes = {};\n\n if (componentName) {\n attributes[UI_COMPONENT_NAME] = componentName;\n }\n\n if (entry?.sources) {\n entry.sources.forEach((source, index) => {\n attributes[`browser.web_vital.cls.source.${index + 1}`] = htmlTreeAsString(source.node);\n });\n }\n\n _emitWebVitalSpan({\n name,\n op: UI_WEBVITAL_CLS,\n origin: 'auto.http.browser.cls',\n metricName: 'cls',\n value: clsValue,\n attributes,\n parentSpan: pageloadSpan,\n startTime,\n softNavigationId,\n navigationType,\n });\n}\n\n/**\n * Tracks INP and emits it as a web vital span, as a child of the interaction's root span.\n * Requires `registerInpInteractionListener()` to be called separately for cached element names and\n * root spans per interaction.\n */\nexport function trackInpAsSpan(client: Client, perNavigation = false): void {\n const performance = getBrowserPerformanceAPI();\n if (!performance || !browserPerformanceTimeOrigin()) {\n return;\n }\n\n // INP reports late (on pagehide, after the pageload span has ended). With span streaming enabled\n // it rides the streaming pipeline. With streaming disabled it would be dropped as a late span, so\n // it is emitted as its own standalone v2 span instead (see `_emitWebVitalSpan`), overriding the\n // static trace lifecycle for INP only.\n // TODO(standalone): once the static trace lifecycle is dropped, INP always streams; drop this flag.\n const standalone = !hasSpanStreamingEnabled(client);\n\n if (perNavigation) {\n // INP restarts per navigation and reports once that navigation is over, by which point the\n // navigation span has ended and the interaction cache no longer knows about it. The metric\n // says which navigation it belongs to, so INP is attributed exactly like LCP and CLS.\n trackWebVitalPerNavigation(client, addInpInstrumentationHandler, (metric, parentSpan, softNavigationId) => {\n if (isPlausibleInp(metric)) {\n _sendInpSpan(metric.value, findInpEntry(metric), standalone, parentSpan, softNavigationId, metric);\n }\n });\n return;\n }\n\n const onInp: InstrumentationHandlerCallback = ({ metric }) => {\n if (isPlausibleInp(metric)) {\n _sendInpSpan(metric.value, findInpEntry(metric), standalone, undefined, undefined, metric);\n }\n };\n\n addInpInstrumentationHandler(onInp);\n}\n\nfunction isPlausibleInp(metric: InpMetric): boolean {\n return metric.value != null && msToSec(metric.value) <= MAX_PLAUSIBLE_INP_DURATION;\n}\n\n/**\n * The entry an INP span is built from: the one whose duration the reported value came from.\n *\n * There isn't always one. When every interaction of a soft navigation stayed below the Event Timing\n * threshold, web-vitals reports a synthetic value with no entries at all - see\n * `_estimateP98LongestInteraction`. The span still gets reported in that case, just without the\n * element and interaction type an entry would have supplied.\n */\nfunction findInpEntry(metric: InpMetric): PerformanceEventTiming | undefined {\n return metric.entries.find(e => e.duration === metric.value && INP_ENTRY_MAP[e.name]);\n}\n\n/**\n * Exported only for testing.\n */\nexport function _sendInpSpan(\n inpValue: number,\n entry: PerformanceEventTiming | undefined,\n standalone = false,\n attributedSpan?: Span,\n softNavigationId?: number,\n metric?: InpMetric,\n): void {\n DEBUG_BUILD && debug.log(`Sending INP span (${inpValue})`);\n\n // A web vital span carries the metric, not a real interaction timing, so an INP without an entry\n // is still worth reporting. It just has no element or interaction type to describe, and is placed\n // at the start of the navigation it belongs to rather than at the interaction.\n // INP is reported on pagehide, often long after the interaction, so we use the time origin from when the\n // interaction happened.\n const startTime = _INTERNAL_performanceTimeToSeconds(entry?.startTime ?? metric?.navigationStartTime ?? 0);\n if (!startTime) {\n return;\n }\n const duration = msToSec(inpValue);\n // An INP without an entry has no interaction type to report. It still has to land inside the\n // `ui.interaction.*` family, because falling outside it would hide exactly the fast navigations\n // that web-vitals synthesizes these values for (GoogleChrome/web-vitals#724), reintroducing the\n // reporting bias they were added to remove.\n const entryInteractionType = entry && INP_ENTRY_MAP[entry.name];\n const interactionType = entryInteractionType || 'click';\n\n const cachedContext = entry && getCachedInteractionContext(entry.interactionId);\n const activeSpan = getActiveSpan();\n const rootSpan = activeSpan ? getRootSpan(activeSpan) : undefined;\n\n // With soft navigations the caller knows exactly which navigation the metric belongs to. Without\n // them we fall back to the span that was active when the interaction was observed.\n const spanToUse = attributedSpan || cachedContext?.span || rootSpan;\n const selector = cachedContext?.elementName || (entry ? htmlTreeAsString(entry.target) : undefined);\n const componentName = entry?.target ? getComponentName(entry.target) : null;\n const client = getClient();\n const hasSpanStreaming = !!client && hasSpanStreamingEnabled(client);\n const fallbackName = INTERACTION_TYPE_TO_SPAN_NAME_FALLBACK[interactionType];\n const name = hasSpanStreaming ? componentName || fallbackName : (selector ?? 'Interaction to next paint');\n\n const attributes: SpanAttributes = {\n [SENTRY_EXCLUSIVE_TIME]: entry?.duration ?? inpValue,\n };\n\n // The span's name and op always have a value, even for an INP without an entry, so they can't\n // say whether there was an interaction to describe. These attributes can: they are only set for\n // what was actually observed. The name no longer holds the selector either, now that it is the\n // component name or the op's fallback under span streaming.\n selector && selector !== UNKNOWN_ELEMENT_NAME && (attributes[BROWSER_WEB_VITAL_INP_TARGET] = selector);\n entryInteractionType && (attributes[BROWSER_WEB_VITAL_INP_INTERACTION_TYPE] = entryInteractionType);\n\n if (componentName) {\n attributes[UI_COMPONENT_NAME] = componentName;\n }\n\n _emitWebVitalSpan({\n name,\n op: INTERACTION_TYPE_TO_SPAN_OP[interactionType],\n origin: 'auto.http.browser.inp',\n metricName: 'inp',\n value: inpValue,\n attributes,\n startTime,\n endTime: startTime + duration,\n navigationType: metric?.navigationType,\n parentSpan: spanToUse,\n standalone,\n softNavigationId,\n });\n}\n"],"names":["UI_INTERACTION_CLICK","UI_INTERACTION_HOVER","UI_INTERACTION_DRAG","UI_INTERACTION_PRESS","UI_INTERACTION_CLICK_SPAN_NAME_FALLBACK","UI_INTERACTION_HOVER_SPAN_NAME_FALLBACK","UI_INTERACTION_DRAG_SPAN_NAME_FALLBACK","UI_INTERACTION_PRESS_SPAN_NAME_FALLBACK","attributes","spanToJSON","SENTRY_OP","NAVIGATION","BROWSER_NAVIGATION_TYPE","getNavigationSpanForMetric","DEBUG_BUILD","debug","supportsWebVital","addLcpInstrumentationHandler","isValidLcpMetric","listenForWebVitalReportEvents","_INTERNAL_performanceTimeToSeconds","msToSec","htmlTreeAsString","componentName","getComponentName","getClient","hasSpanStreamingEnabled","UI_WEBVITAL_LCP_SPAN_NAME_FALLBACK","UI_COMPONENT_NAME","_emitWebVitalSpan","UI_WEBVITAL_LCP","addClsInstrumentationHandler","timestampInSeconds","UI_WEBVITAL_CLS_SPAN_NAME_FALLBACK","UI_WEBVITAL_CLS","getBrowserPerformanceAPI","browserPerformanceTimeOrigin","addInpInstrumentationHandler","MAX_PLAUSIBLE_INP_DURATION","INP_ENTRY_MAP","getCachedInteractionContext","getActiveSpan","getRootSpan","SENTRY_EXCLUSIVE_TIME","UNKNOWN_ELEMENT_NAME","BROWSER_WEB_VITAL_INP_TARGET","BROWSER_WEB_VITAL_INP_INTERACTION_TYPE"],"mappings":";;;;;;;;;;;;;;;;AAuDA,MAAM,2BAAA,GAA+D;AAAA,EACnE,KAAA,EAAOA,uBAAA;AAAA,EACP,KAAA,EAAOC,uBAAA;AAAA,EACP,IAAA,EAAMC,sBAAA;AAAA,EACN,KAAA,EAAOC;AACT,CAAA;AAEA,MAAM,sCAAA,GAA0E;AAAA,EAC9E,KAAA,EAAOC,4CAAA;AAAA,EACP,KAAA,EAAOC,4CAAA;AAAA,EACP,IAAA,EAAMC,2CAAA;AAAA,EACN,KAAA,EAAOC;AACT,CAAA;AAaA,SAAS,0BAAA,CACP,MAAA,EACA,yBAAA,EACA,IAAA,EACM;AACN,EAAA,IAAI,YAAA;AACJ,EAAA,MAAA,CAAO,EAAA,CAAG,0BAA0B,CAAA,IAAA,KAAQ;AAC1C,IAAA,YAAA,GAAe,IAAA;AAAA,EACjB,CAAC,CAAA;AAKD,EAAA,IAAI,qBAAA;AACJ,EAAA,MAAA,CAAO,EAAA,CAAG,aAAa,CAAA,IAAA,KAAQ;AAI7B,IAAA,MAAMC,YAAA,GAAaC,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AC/C,MAAA,EAAQ,uBAAA;AAAA,IACR,UAAA,EAAY,KAAA;AAAA,IACZ,KAAA,EAAO,QAAA;AAAA,gBACPrB,YAAA;AAAA,IACA,SAAA;AAAA,IACA,SAAS,SAAA,GAAY,QAAA;AAAA,IACrB,gBAAgB,MAAA,EAAQ,cAAA;AAAA,IACxB,UAAA,EAAY,SAAA;AAAA,IACZ,UAAA;AAAA,IACA;AAAA,GACD,CAAA;AACH;;;;;;;;;"}
|
|
@@ -39,7 +39,14 @@ function fetch(...rest) {
|
|
|
39
39
|
return getNativeImplementation("fetch")(...rest);
|
|
40
40
|
}
|
|
41
41
|
function setTimeout(...rest) {
|
|
42
|
-
|
|
42
|
+
try {
|
|
43
|
+
return getNativeImplementation("setTimeout")(...rest);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
DEBUG_BUILD && debug.warn("Could not use native setTimeout implementation, falling back to window.setTimeout: ", e);
|
|
46
|
+
const fallback = WINDOW.setTimeout.bind(WINDOW);
|
|
47
|
+
cachedImplementations.setTimeout = fallback;
|
|
48
|
+
return fallback(...rest);
|
|
49
|
+
}
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
export { clearCachedImplementation, fetch, getNativeImplementation, setTimeout };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNativeImplementation.js","sources":["../../src/getNativeImplementation.ts"],"sourcesContent":["import { debug, isNativeFunction } from '@sentry/core';\nimport { DEBUG_BUILD } from './debug-build';\nimport { WINDOW } from './types';\n\n/**\n * We generally want to use window.fetch / window.setTimeout.\n * However, in some cases this may be wrapped (e.g. by Zone.js for Angular),\n * so we try to get an unpatched version of this from a sandboxed iframe.\n */\n\ninterface CacheableImplementations {\n setTimeout: typeof WINDOW.setTimeout;\n fetch: typeof WINDOW.fetch;\n}\n\nconst cachedImplementations: Partial<CacheableImplementations> = {};\n\n/**\n * Get the native implementation of a browser function.\n *\n * This can be used to ensure we get an unwrapped version of a function, in cases where a wrapped function can lead to problems.\n *\n * The following methods can be retrieved:\n * - `setTimeout`: This can be wrapped by e.g. Angular, causing change detection to be triggered.\n * - `fetch`: This can be wrapped by e.g. ad-blockers, causing an infinite loop when a request is blocked.\n */\nexport function getNativeImplementation<T extends keyof CacheableImplementations>(\n name: T,\n): CacheableImplementations[T] {\n const cached = cachedImplementations[name];\n if (cached) {\n return cached;\n }\n\n let impl = WINDOW[name] as CacheableImplementations[T];\n\n // Fast path to avoid DOM I/O\n if (isNativeFunction(impl)) {\n return (cachedImplementations[name] = impl.bind(WINDOW) as CacheableImplementations[T]);\n }\n\n const document = WINDOW.document;\n // eslint-disable-next-line typescript/no-deprecated\n if (document && typeof document.createElement === 'function') {\n try {\n const sandbox = document.createElement('iframe');\n sandbox.hidden = true;\n document.head.appendChild(sandbox);\n const contentWindow = sandbox.contentWindow;\n if (contentWindow?.[name]) {\n impl = contentWindow[name] as CacheableImplementations[T];\n }\n document.head.removeChild(sandbox);\n } catch (e) {\n // Could not create sandbox iframe, just use window.xxx\n DEBUG_BUILD && debug.warn(`Could not create sandbox iframe for ${name} check, bailing to window.${name}: `, e);\n }\n }\n\n // Sanity check: This _should_ not happen, but if it does, we just skip caching...\n // This can happen e.g. in tests where fetch may not be available in the env, or similar.\n if (!impl) {\n return impl;\n }\n\n return (cachedImplementations[name] = impl.bind(WINDOW) as CacheableImplementations[T]);\n}\n\n/** Clear a cached implementation. */\nexport function clearCachedImplementation(name: keyof CacheableImplementations): void {\n cachedImplementations[name] = undefined;\n}\n\n/**\n * A special usecase for incorrectly wrapped Fetch APIs in conjunction with ad-blockers.\n * Whenever someone wraps the Fetch API and returns the wrong promise chain,\n * this chain becomes orphaned and there is no possible way to capture it's rejections\n * other than allowing it bubble up to this very handler. eg.\n *\n * const f = window.fetch;\n * window.fetch = function () {\n * const p = f.apply(this, arguments);\n *\n * p.then(function() {\n * console.log('hi.');\n * });\n *\n * return p;\n * }\n *\n * `p.then(function () { ... })` is producing a completely separate promise chain,\n * however, what's returned is `p` - the result of original `fetch` call.\n *\n * This mean, that whenever we use the Fetch API to send our own requests, _and_\n * some ad-blocker blocks it, this orphaned chain will _always_ reject,\n * effectively causing another event to be captured.\n * This makes a whole process become an infinite loop, which we need to somehow\n * deal with, and break it in one way or another.\n *\n * To deal with this issue, we are making sure that we _always_ use the real\n * browser Fetch API, instead of relying on what `window.fetch` exposes.\n * The only downside to this would be missing our own requests as breadcrumbs,\n * but because we are already not doing this, it should be just fine.\n *\n * Possible failed fetch error messages per-browser:\n *\n * Chrome: Failed to fetch\n * Edge: Failed to Fetch\n * Firefox: NetworkError when attempting to fetch resource\n * Safari: resource blocked by content blocker\n */\nexport function fetch(...rest: Parameters<typeof WINDOW.fetch>): ReturnType<typeof WINDOW.fetch> {\n return getNativeImplementation('fetch')(...rest);\n}\n\n/**\n * Get an unwrapped `setTimeout` method.\n * This ensures that even if e.g. Angular wraps `setTimeout`, we get the native implementation,\n * avoiding triggering change detection.\n */\nexport function setTimeout(...rest: Parameters<typeof WINDOW.setTimeout>): ReturnType<typeof WINDOW.setTimeout> {\n return getNativeImplementation('setTimeout')(...rest);\n}\n"],"names":[],"mappings":";;;;AAeA,MAAM,wBAA2D,EAAC;AAW3D,SAAS,wBACd,IAAA,EAC6B;AAC7B,EAAA,MAAM,MAAA,GAAS,sBAAsB,IAAI,CAAA;AACzC,EAAA,IAAI,MAAA,EAAQ;AACV,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,IAAI,IAAA,GAAO,OAAO,IAAI,CAAA;AAGtB,EAAA,IAAI,gBAAA,CAAiB,IAAI,CAAA,EAAG;AAC1B,IAAA,OAAQ,qBAAA,CAAsB,IAAI,CAAA,GAAI,IAAA,CAAK,KAAK,MAAM,CAAA;AAAA,EACxD;AAEA,EAAA,MAAM,WAAW,MAAA,CAAO,QAAA;AAExB,EAAA,IAAI,QAAA,IAAY,OAAO,QAAA,CAAS,aAAA,KAAkB,UAAA,EAAY;AAC5D,IAAA,IAAI;AACF,MAAA,MAAM,OAAA,GAAU,QAAA,CAAS,aAAA,CAAc,QAAQ,CAAA;AAC/C,MAAA,OAAA,CAAQ,MAAA,GAAS,IAAA;AACjB,MAAA,QAAA,CAAS,IAAA,CAAK,YAAY,OAAO,CAAA;AACjC,MAAA,MAAM,gBAAgB,OAAA,CAAQ,aAAA;AAC9B,MAAA,IAAI,aAAA,GAAgB,IAAI,CAAA,EAAG;AACzB,QAAA,IAAA,GAAO,cAAc,IAAI,CAAA;AAAA,MAC3B;AACA,MAAA,QAAA,CAAS,IAAA,CAAK,YAAY,OAAO,CAAA;AAAA,IACnC,SAAS,CAAA,EAAG;AAEV,MAAA,WAAA,IAAe,MAAM,IAAA,CAAK,CAAA,oCAAA,EAAuC,IAAI,CAAA,0BAAA,EAA6B,IAAI,MAAM,CAAC,CAAA;AAAA,IAC/G;AAAA,EACF;AAIA,EAAA,IAAI,CAAC,IAAA,EAAM;AACT,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,OAAQ,qBAAA,CAAsB,IAAI,CAAA,GAAI,IAAA,CAAK,KAAK,MAAM,CAAA;AACxD;AAGO,SAAS,0BAA0B,IAAA,EAA4C;AACpF,EAAA,qBAAA,CAAsB,IAAI,CAAA,GAAI,MAAA;AAChC;AAwCO,SAAS,SAAS,IAAA,EAAwE;AAC/F,EAAA,OAAO,uBAAA,CAAwB,OAAO,CAAA,CAAE,GAAG,IAAI,CAAA;AACjD;AAOO,SAAS,cAAc,IAAA,EAAkF;AAC9G,EAAA,OAAO,uBAAA,CAAwB,YAAY,CAAA,CAAE,GAAG,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"getNativeImplementation.js","sources":["../../src/getNativeImplementation.ts"],"sourcesContent":["import { debug, isNativeFunction } from '@sentry/core';\nimport { DEBUG_BUILD } from './debug-build';\nimport { WINDOW } from './types';\n\n/**\n * We generally want to use window.fetch / window.setTimeout.\n * However, in some cases this may be wrapped (e.g. by Zone.js for Angular),\n * so we try to get an unpatched version of this from a sandboxed iframe.\n */\n\ninterface CacheableImplementations {\n setTimeout: typeof WINDOW.setTimeout;\n fetch: typeof WINDOW.fetch;\n}\n\nconst cachedImplementations: Partial<CacheableImplementations> = {};\n\n/**\n * Get the native implementation of a browser function.\n *\n * This can be used to ensure we get an unwrapped version of a function, in cases where a wrapped function can lead to problems.\n *\n * The following methods can be retrieved:\n * - `setTimeout`: This can be wrapped by e.g. Angular, causing change detection to be triggered.\n * - `fetch`: This can be wrapped by e.g. ad-blockers, causing an infinite loop when a request is blocked.\n */\nexport function getNativeImplementation<T extends keyof CacheableImplementations>(\n name: T,\n): CacheableImplementations[T] {\n const cached = cachedImplementations[name];\n if (cached) {\n return cached;\n }\n\n let impl = WINDOW[name] as CacheableImplementations[T];\n\n // Fast path to avoid DOM I/O\n if (isNativeFunction(impl)) {\n return (cachedImplementations[name] = impl.bind(WINDOW) as CacheableImplementations[T]);\n }\n\n const document = WINDOW.document;\n // eslint-disable-next-line typescript/no-deprecated\n if (document && typeof document.createElement === 'function') {\n try {\n const sandbox = document.createElement('iframe');\n sandbox.hidden = true;\n document.head.appendChild(sandbox);\n const contentWindow = sandbox.contentWindow;\n if (contentWindow?.[name]) {\n impl = contentWindow[name] as CacheableImplementations[T];\n }\n document.head.removeChild(sandbox);\n } catch (e) {\n // Could not create sandbox iframe, just use window.xxx\n DEBUG_BUILD && debug.warn(`Could not create sandbox iframe for ${name} check, bailing to window.${name}: `, e);\n }\n }\n\n // Sanity check: This _should_ not happen, but if it does, we just skip caching...\n // This can happen e.g. in tests where fetch may not be available in the env, or similar.\n if (!impl) {\n return impl;\n }\n\n return (cachedImplementations[name] = impl.bind(WINDOW) as CacheableImplementations[T]);\n}\n\n/** Clear a cached implementation. */\nexport function clearCachedImplementation(name: keyof CacheableImplementations): void {\n cachedImplementations[name] = undefined;\n}\n\n/**\n * A special usecase for incorrectly wrapped Fetch APIs in conjunction with ad-blockers.\n * Whenever someone wraps the Fetch API and returns the wrong promise chain,\n * this chain becomes orphaned and there is no possible way to capture it's rejections\n * other than allowing it bubble up to this very handler. eg.\n *\n * const f = window.fetch;\n * window.fetch = function () {\n * const p = f.apply(this, arguments);\n *\n * p.then(function() {\n * console.log('hi.');\n * });\n *\n * return p;\n * }\n *\n * `p.then(function () { ... })` is producing a completely separate promise chain,\n * however, what's returned is `p` - the result of original `fetch` call.\n *\n * This mean, that whenever we use the Fetch API to send our own requests, _and_\n * some ad-blocker blocks it, this orphaned chain will _always_ reject,\n * effectively causing another event to be captured.\n * This makes a whole process become an infinite loop, which we need to somehow\n * deal with, and break it in one way or another.\n *\n * To deal with this issue, we are making sure that we _always_ use the real\n * browser Fetch API, instead of relying on what `window.fetch` exposes.\n * The only downside to this would be missing our own requests as breadcrumbs,\n * but because we are already not doing this, it should be just fine.\n *\n * Possible failed fetch error messages per-browser:\n *\n * Chrome: Failed to fetch\n * Edge: Failed to Fetch\n * Firefox: NetworkError when attempting to fetch resource\n * Safari: resource blocked by content blocker\n */\nexport function fetch(...rest: Parameters<typeof WINDOW.fetch>): ReturnType<typeof WINDOW.fetch> {\n return getNativeImplementation('fetch')(...rest);\n}\n\n/**\n * Get an unwrapped `setTimeout` method.\n * This ensures that even if e.g. Angular wraps `setTimeout`, we get the native implementation,\n * avoiding triggering change detection.\n */\nexport function setTimeout(...rest: Parameters<typeof WINDOW.setTimeout>): ReturnType<typeof WINDOW.setTimeout> {\n try {\n return getNativeImplementation('setTimeout')(...rest);\n } catch (e) {\n // The implementation retrieved from the (since removed) sandbox iframe may throw when invoked,\n // e.g. Firefox throws `NS_ERROR_NOT_INITIALIZED` for timers of a detached window.\n // In this case, fall back to (and cache) the window's own setTimeout.\n DEBUG_BUILD && debug.warn('Could not use native setTimeout implementation, falling back to window.setTimeout: ', e);\n const fallback = WINDOW.setTimeout.bind(WINDOW) as typeof WINDOW.setTimeout;\n cachedImplementations.setTimeout = fallback;\n return fallback(...rest);\n }\n}\n"],"names":[],"mappings":";;;;AAeA,MAAM,wBAA2D,EAAC;AAW3D,SAAS,wBACd,IAAA,EAC6B;AAC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