Skip to content

Commit 48171a3

Browse files
logaretmclaude
andcommitted
fix(browser): Guard auto-register call and update web-vital test assertions
- Guard `client.getIntegrationByName?.()` / `client.addIntegration?.()` in `browserTracingIntegration.afterAllSetup` so stripped-down test/mock clients don't crash on auto-registering `webVitalsIntegration`. - Drop `eventData.measurements.{lcp,cls,inp,ttfb,fp,fcp}` assertions from browser integration tests; web vitals are no longer recorded as transaction measurements. Web-vital-specific tests now assert the new `browser.web_vital.X.value` attribute on the corresponding span (the LCP/CLS child span, or the pageload span for ttfb/fp/fcp). - Delete legacy INP test suites (`web-vitals-inp`, `web-vitals-inp-late`, `web-vitals-inp-navigate`, `web-vitals-inp-parametrized`, `web-vitals-inp-parametrized-late`). They tested the v1 standalone INP envelope path which is gone; `web-vitals-inp-streamed-spans` covers the supported flow. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 5d368f6 commit 48171a3

27 files changed

Lines changed: 51 additions & 950 deletions

File tree

dev-packages/browser-integration-tests/suites/tracing/metrics/handlers-lcp/test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ sentryTest(
2626
page.locator('button').click(),
2727
]);
2828

29-
expect(eventData.measurements).toBeDefined();
30-
expect(eventData.measurements?.lcp?.value).toBeDefined();
29+
const lcpSpan = eventData.spans?.find(({ op }) => op === 'ui.webvital.lcp');
30+
expect(lcpSpan).toBeDefined();
31+
const lcpAttrs = lcpSpan?.data ?? {};
32+
expect(lcpAttrs['browser.web_vital.lcp.value']).toBeGreaterThan(0);
3133

3234
// This should be body > img, but it can be flakey as sometimes it will report
3335
// the button as LCP.
34-
expect(eventData.contexts?.trace?.data?.['lcp.element'].startsWith('body >')).toBe(true);
36+
expect(String(lcpAttrs['browser.web_vital.lcp.element']).startsWith('body >')).toBe(true);
3537

3638
// Working around flakiness
3739
// Only testing this when the LCP element is an image, not a button
38-
if (eventData.contexts?.trace?.data?.['lcp.element'] === 'body > img') {
39-
expect(eventData.contexts?.trace?.data?.['lcp.size']).toBe(107400);
40+
if (lcpAttrs['browser.web_vital.lcp.element'] === 'body > img') {
41+
expect(lcpAttrs['browser.web_vital.lcp.size']).toBe(107400);
4042

4143
const lcp = await (await page.waitForFunction('window._LCP')).jsonValue();
4244
const lcp2 = await (await page.waitForFunction('window._LCP2')).jsonValue();

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-cls/test.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,49 @@ sentryTest.beforeEach(async ({ browserName, page }) => {
1111
await page.setViewportSize({ width: 800, height: 1200 });
1212
});
1313

14+
function getClsAttrs(eventData: Event): Record<string, unknown> {
15+
const clsSpan = eventData.spans?.find(({ op }) => op === 'ui.webvital.cls');
16+
expect(clsSpan).toBeDefined();
17+
return clsSpan?.data ?? {};
18+
}
19+
1420
sentryTest('should capture a "GOOD" CLS vital with its source(s).', async ({ getLocalTestUrl, page }) => {
1521
const url = await getLocalTestUrl({ testDir: __dirname });
1622
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, `${url}#0.05`);
1723

18-
expect(eventData.measurements).toBeDefined();
19-
expect(eventData.measurements?.cls?.value).toBeDefined();
24+
const clsAttrs = getClsAttrs(eventData);
25+
const clsValue = clsAttrs['browser.web_vital.cls.value'] as number;
2026

2127
// Flakey value dependent on timings -> we check for a range
22-
expect(eventData.measurements?.cls?.value).toBeGreaterThan(0.03);
23-
expect(eventData.measurements?.cls?.value).toBeLessThan(0.07);
28+
expect(clsValue).toBeGreaterThan(0.03);
29+
expect(clsValue).toBeLessThan(0.07);
2430

25-
expect(eventData.contexts?.trace?.data?.['cls.source.1']).toBe('body > div#content > p#partial');
31+
expect(clsAttrs['browser.web_vital.cls.source.1']).toBe('body > div#content > p#partial');
2632
});
2733

2834
sentryTest('should capture a "MEH" CLS vital with its source(s).', async ({ getLocalTestUrl, page }) => {
2935
const url = await getLocalTestUrl({ testDir: __dirname });
3036
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, `${url}#0.21`);
3137

32-
expect(eventData.measurements).toBeDefined();
33-
expect(eventData.measurements?.cls?.value).toBeDefined();
38+
const clsAttrs = getClsAttrs(eventData);
39+
const clsValue = clsAttrs['browser.web_vital.cls.value'] as number;
3440

3541
// Flakey value dependent on timings -> we check for a range
36-
expect(eventData.measurements?.cls?.value).toBeGreaterThan(0.18);
37-
expect(eventData.measurements?.cls?.value).toBeLessThan(0.23);
42+
expect(clsValue).toBeGreaterThan(0.18);
43+
expect(clsValue).toBeLessThan(0.23);
3844

39-
expect(eventData.contexts?.trace?.data?.['cls.source.1']).toBe('body > div#content > p');
45+
expect(clsAttrs['browser.web_vital.cls.source.1']).toBe('body > div#content > p');
4046
});
4147

4248
sentryTest('should capture a "POOR" CLS vital with its source(s).', async ({ getLocalTestUrl, page }) => {
4349
const url = await getLocalTestUrl({ testDir: __dirname });
4450
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, `${url}#0.35`);
4551

46-
expect(eventData.measurements).toBeDefined();
47-
expect(eventData.measurements?.cls?.value).toBeDefined();
52+
const clsAttrs = getClsAttrs(eventData);
53+
const clsValue = clsAttrs['browser.web_vital.cls.value'] as number;
4854

4955
// Flakey value dependent on timings -> we check for a range
50-
expect(eventData.measurements?.cls?.value).toBeGreaterThan(0.34);
51-
expect(eventData.measurements?.cls?.value).toBeLessThan(0.36);
52-
expect(eventData.contexts?.trace?.data?.['cls.source.1']).toBe('body > div#content > p');
56+
expect(clsValue).toBeGreaterThan(0.34);
57+
expect(clsValue).toBeLessThan(0.36);
58+
expect(clsAttrs['browser.web_vital.cls.source.1']).toBe('body > div#content > p');
5359
});

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-fp-fcp/test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ sentryTest('should capture FP vital.', async ({ browserName, getLocalTestUrl, pa
1212
const url = await getLocalTestUrl({ testDir: __dirname });
1313
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
1414

15-
expect(eventData.measurements).toBeDefined();
16-
expect(eventData.measurements?.fp?.value).toBeDefined();
15+
expect(eventData.contexts?.trace?.data?.['browser.web_vital.fp.value']).toBeGreaterThan(0);
1716

1817
const fpSpan = eventData.spans?.filter(({ description }) => description === 'first-paint')[0];
1918

@@ -30,8 +29,7 @@ sentryTest('should capture FCP vital.', async ({ getLocalTestUrl, page }) => {
3029
const url = await getLocalTestUrl({ testDir: __dirname });
3130
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
3231

33-
expect(eventData.measurements).toBeDefined();
34-
expect(eventData.measurements?.fcp?.value).toBeDefined();
32+
expect(eventData.contexts?.trace?.data?.['browser.web_vital.fcp.value']).toBeGreaterThan(0);
3533

3634
const fcpSpan = eventData.spans?.filter(({ description }) => description === 'first-contentful-paint')[0];
3735

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-inp-late/init.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-inp-late/subject.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-inp-late/template.html

Lines changed: 0 additions & 12 deletions
This file was deleted.

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-inp-late/test.ts

Lines changed: 0 additions & 89 deletions
This file was deleted.

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-inp-navigate/init.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-inp-navigate/subject.js

Lines changed: 0 additions & 44 deletions
This file was deleted.

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-inp-navigate/template.html

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)