11/* eslint-disable max-lines */
2- import type { Measurements , Span , SpanAttributes , SpanAttributeValue , StartSpanOptions } from '@sentry/core' ;
2+ import type { Client , Measurements , Span , SpanAttributes , SpanAttributeValue , StartSpanOptions } from '@sentry/core' ;
33import {
44 browserPerformanceTimeOrigin ,
55 debug ,
@@ -23,6 +23,7 @@ import { getBrowserPerformanceAPI, isMeasurementValue, msToSec, startAndEndSpan
2323import { getActivationStart } from './web-vitals/lib/getActivationStart' ;
2424import { getNavigationEntry } from './web-vitals/lib/getNavigationEntry' ;
2525import { getVisibilityWatcher } from './web-vitals/lib/getVisibilityWatcher' ;
26+ import { trackClsAsSpan , trackInpAsSpan , trackLcpAsSpan } from './webVitalSpans' ;
2627import { DEBUG_BUILD } from '../debug-build' ;
2728interface NavigatorNetworkInformation {
2829 readonly connection ?: NetworkInformation ;
@@ -69,6 +70,7 @@ let _performanceCursor: number = 0;
6970let _measurements : Measurements = { } ;
7071
7172type PageloadWebVitalName = 'ttfb' | 'fp' | 'fcp' ;
73+ export type WebVitalName = PageloadWebVitalName | 'lcp' | 'cls' | 'inp' ;
7274
7375const DEFAULT_PAGELOAD_WEB_VITALS = new Set < PageloadWebVitalName > ( [ 'ttfb' , 'fp' , 'fcp' ] ) ;
7476
@@ -78,17 +80,26 @@ let _collectTtfb: (() => void) | undefined;
7880
7981/**
8082 * Start tracking web vitals.
81- *
82- * LCP, CLS and INP are handled separately as spans by `webVitalsIntegration`;
83- * this function tracks pageload web vitals which are attached as attributes.
8483 */
85- export function startTrackingWebVitals ( options : { disable ?: Array < 'ttfb' | 'fp' | 'fcp' > } = { } ) : void {
84+ export function startTrackingWebVitals ( client : Client , disabled : ReadonlySet < WebVitalName > ) : void {
85+ startTrackingPageloadWebVitals ( disabled ) ;
86+
87+ if ( ! disabled . has ( 'lcp' ) ) {
88+ trackLcpAsSpan ( client ) ;
89+ }
90+ if ( ! disabled . has ( 'cls' ) ) {
91+ trackClsAsSpan ( client ) ;
92+ }
93+ if ( ! disabled . has ( 'inp' ) ) {
94+ trackInpAsSpan ( ) ;
95+ }
96+ }
97+
98+ function startTrackingPageloadWebVitals ( disabled : ReadonlySet < WebVitalName > ) : void {
8699 _collectTtfb ?.( ) ;
87100 _collectTtfb = undefined ;
88101
89- _enabledPageloadWebVitals = new Set (
90- Array . from ( DEFAULT_PAGELOAD_WEB_VITALS ) . filter ( vital => ! options . disable ?. includes ( vital ) ) ,
91- ) ;
102+ _enabledPageloadWebVitals = new Set ( Array . from ( DEFAULT_PAGELOAD_WEB_VITALS ) . filter ( vital => ! disabled . has ( vital ) ) ) ;
92103
93104 const performance = getBrowserPerformanceAPI ( ) ;
94105 if ( performance && browserPerformanceTimeOrigin ( ) ) {
0 commit comments