MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / setup

Function setup

packages/browser/src/integrations/webVitals.ts:44–94  ·  view source on GitHub ↗
(client)

Source from the content-addressed store, hash-verified

42 return {
43 name: WEB_VITALS_INTEGRATION_NAME,
44 setup(client) {
45 const spanStreamingEnabled = hasSpanStreamingEnabled(client);
46 const { enableStandaloneClsSpans, enableStandaloneLcpSpans } = options._experiments ?? {};
47
48 const recordClsStandaloneSpans =
49 spanStreamingEnabled || ignored.has('cls') ? undefined : enableStandaloneClsSpans || false;
50 const recordLcpStandaloneSpans =
51 spanStreamingEnabled || ignored.has('lcp') ? undefined : enableStandaloneLcpSpans || false;
52
53 // eslint-disable-next-line typescript/no-deprecated
54 const finalizeWebVitals = startTrackingWebVitals({
55 recordClsStandaloneSpans,
56 recordLcpStandaloneSpans,
57 client,
58 });
59
60 const pageloadSpans = new WeakSet<Span>();
61
62 client.on('afterStartPageLoadSpan', span => {
63 pageloadSpans.add(span);
64 });
65
66 client.on('spanEnd', span => {
67 if (!pageloadSpans.delete(span)) {
68 return;
69 }
70
71 finalizeWebVitals();
72 addWebVitalsToSpan(span, {
73 // CLS/LCP are recorded as pageload span measurements only when they're neither
74 // tracked as standalone spans nor handled by span streaming (and not ignored).
75 recordClsOnPageloadSpan: recordClsStandaloneSpans === false,
76 recordLcpOnPageloadSpan: recordLcpStandaloneSpans === false,
77 spanStreamingEnabled,
78 });
79 });
80
81 if (spanStreamingEnabled) {
82 if (!ignored.has('lcp')) {
83 trackLcpAsSpan(client);
84 }
85 if (!ignored.has('cls')) {
86 trackClsAsSpan(client);
87 }
88 if (!ignored.has('inp')) {
89 trackInpAsSpan();
90 }
91 } else if (!ignored.has('inp')) {
92 startTrackingINP();
93 }
94 },
95 afterAllSetup() {
96 if (!ignored.has('inp')) {
97 registerInpInteractionListener();

Callers

nothing calls this directly

Calls 11

startTrackingWebVitalsFunction · 0.90
addWebVitalsToSpanFunction · 0.90
trackLcpAsSpanFunction · 0.90
trackClsAsSpanFunction · 0.90
trackInpAsSpanFunction · 0.90
startTrackingINPFunction · 0.90
hasSpanStreamingEnabledFunction · 0.85
hasMethod · 0.65
onMethod · 0.65
addMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected