diff --git a/packages/browser-utils/src/metrics/browserMetrics.ts b/packages/browser-utils/src/metrics/browserMetrics.ts index f2cea6c63205..787091523a48 100644 --- a/packages/browser-utils/src/metrics/browserMetrics.ts +++ b/packages/browser-utils/src/metrics/browserMetrics.ts @@ -6,12 +6,11 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getActiveSpan, - getClient, getCurrentScope, startInactiveSpan, } from '@sentry/core'; import { setMeasurement } from '@sentry/core'; -import type { Integration, Measurements, Span, SpanAttributes, StartSpanOptions } from '@sentry/types'; +import type { Measurements, Span, SpanAttributes, StartSpanOptions } from '@sentry/types'; import { browserPerformanceTimeOrigin, dropUndefinedKeys, @@ -41,7 +40,6 @@ import { } from './utils'; import { getNavigationEntry } from './web-vitals/lib/getNavigationEntry'; import { getVisibilityWatcher } from './web-vitals/lib/getVisibilityWatcher'; -import { onFCP } from './web-vitals/onFCP'; import type { Metric } from './web-vitals/types'; interface NavigatorNetworkInformation { @@ -89,6 +87,7 @@ let _performanceCursor: number = 0; let _measurements: Measurements = {}; let _lcpEntry: LargestContentfulPaint | undefined; let _clsEntry: LayoutShift | undefined; + interface StartTrackingWebVitalsOptions { recordClsStandaloneSpans: boolean; } @@ -243,25 +242,15 @@ export { startTrackingINP, registerInpInteractionListener } from './inp'; /** Starts tracking the Cumulative Layout Shift on the current page. */ function _trackCLS(sendAsStandaloneSpan: boolean): () => void { - let _emittedFcp = false; - if (sendAsStandaloneSpan) { - onFCP( - () => { - _emittedFcp = true; - }, - { reportAllChanges: true }, - ); - } - const cleanupClsCallback = addClsInstrumentationHandler(({ metric }) => { const entry = metric.entries[metric.entries.length - 1] as LayoutShift | undefined; if (!entry) { return; } - if (sendAsStandaloneSpan && _emittedFcp) { + if (sendAsStandaloneSpan) { sendStandaloneClsSpan(metric, entry); - // For now, we only emit once CLS span for the initial page load. + // For now, we only emit one CLS span for the initial page load. // Once we send this, we don't need to track CLS anymore. setTimeout(() => { cleanupClsCallback(); @@ -472,6 +461,7 @@ export function addPerformanceEntries(span: Span, options: AddPerformanceEntries // If FCP is not recorded we should not record the cls value // according to the new definition of CLS. + // TODO: Check if the first condition is still necessary: `onCLS` already only fires once `onFCP` was called. if (!('fcp' in _measurements) || !options.recordClsOnPageloadSpan) { delete _measurements.cls; } diff --git a/packages/browser-utils/src/metrics/instrument.ts b/packages/browser-utils/src/metrics/instrument.ts index c10df607b6b1..8249c1ad8ba9 100644 --- a/packages/browser-utils/src/metrics/instrument.ts +++ b/packages/browser-utils/src/metrics/instrument.ts @@ -226,8 +226,6 @@ function instrumentCls(): StopListening { }); _previousCls = metric; }, - // We want the callback to be called whenever the CLS value updates. - // By default, the callback is only called when the tab goes to the background. { reportAllChanges: false }, ); } diff --git a/packages/browser-utils/src/metrics/utils.ts b/packages/browser-utils/src/metrics/utils.ts index 9ae3652eef07..17c537072b9f 100644 --- a/packages/browser-utils/src/metrics/utils.ts +++ b/packages/browser-utils/src/metrics/utils.ts @@ -1,12 +1,5 @@ import type { SentrySpan } from '@sentry/core'; -import { - SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME, - getClient, - getCurrentScope, - spanToJSON, - startInactiveSpan, - withActiveSpan, -} from '@sentry/core'; +import { getClient, getCurrentScope, spanToJSON, startInactiveSpan, withActiveSpan } from '@sentry/core'; import type { Integration, Span, SpanAttributes, SpanTimeInput, StartSpanOptions } from '@sentry/types'; import { WINDOW } from '../types'; diff --git a/packages/browser-utils/src/metrics/web-vitals/getCLS.ts b/packages/browser-utils/src/metrics/web-vitals/getCLS.ts index 4e97d1b6c48b..ef650b48a345 100644 --- a/packages/browser-utils/src/metrics/web-vitals/getCLS.ts +++ b/packages/browser-utils/src/metrics/web-vitals/getCLS.ts @@ -15,9 +15,6 @@ */ import { getClient } from '@sentry/core'; -import { logger } from '@sentry/utils'; -import { DEBUG_BUILD } from '../../debug-build'; -import { WINDOW } from '../../types'; import { bindReporter } from './lib/bindReporter'; import { initMetric } from './lib/initMetric'; import { observe } from './lib/observe'; @@ -49,8 +46,6 @@ export const CLSThresholds: MetricRatingThresholds = [0.1, 0.25]; * `callback` is always called when the page's visibility state changes to * hidden. As a result, the `callback` function might be called multiple times * during the same page load._ - * - * SENTRY-SPECIFIC-CHANGE: */ export const onCLS = (onReport: CLSReportCallback, opts: ReportOpts = {}): void => { // Start monitoring FCP so we can only report CLS if FCP is also reported.