-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(browser): Remove faulty LCP, FCP and FP normalization logic (#13502)
Remove incorrect normalization logic we applied to LCP, FCP and FP web vital measurements. With this change, we no longer alter the three web vital values but report directly what we received from the web-vitals library. Add a span attribute, `performance.timeOrigin` (feel free to suggest better names) to the pageload root span. This attribute contains the `timeOrigin` value we determine in the SDK. This value [should be used](https://developer.mozilla.org/en-US/docs/Web/API/Performance/timeOrigin) to base performance measurements on.
- Loading branch information
Showing
8 changed files
with
111 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+15.7 KB
...egration-tests/suites/tracing/metrics/web-vitals/assets/sentry-logo-600x179.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions
11
dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals/template.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<div id="content"></div> | ||
<img src="https://example.com/library/image.png" /> | ||
<button type="button">Test button</button> | ||
</body> | ||
</html> |
81 changes: 81 additions & 0 deletions
81
dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import type { Route } from '@playwright/test'; | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
|
||
/** | ||
* Bit of an odd test but we previously ran into cases where we would report TTFB > (LCP, FCP, FP) | ||
* This should never happen and this test serves as a regression test for that. | ||
* | ||
* The problem is: We don't always get valid TTFB from the web-vitals library, so we skip the test if that's the case. | ||
* Note: There is another test that covers that we actually report TTFB if it is valid (@see ../web-vitals-lcp/test.ts). | ||
*/ | ||
sentryTest('paint web vitals values are greater than TTFB', async ({ browserName, getLocalTestPath, page }) => { | ||
// Only run in chromium to ensure all vitals are present | ||
if (shouldSkipTracingTest() || browserName !== 'chromium') { | ||
sentryTest.skip(); | ||
} | ||
|
||
page.route('**', route => route.continue()); | ||
page.route('**/library/image.png', async (route: Route) => { | ||
return route.fulfill({ path: `${__dirname}/assets/sentry-logo-600x179.png` }); | ||
}); | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
const [eventData] = await Promise.all([ | ||
getFirstSentryEnvelopeRequest<Event>(page), | ||
page.goto(url), | ||
page.locator('button').click(), | ||
]); | ||
|
||
expect(eventData.measurements).toBeDefined(); | ||
|
||
const ttfbValue = eventData.measurements?.ttfb?.value; | ||
|
||
if (!ttfbValue) { | ||
// TTFB is unfortunately quite flaky. Sometimes, the web-vitals library doesn't report TTFB because | ||
// responseStart is 0. This seems to happen somewhat randomly, so we just ignore this in that case. | ||
// @see packages/browser-utils/src/metrics/web-vitals/onTTFB | ||
|
||
// logging the skip reason so that we at least can check for that in CI logs | ||
// eslint-disable-next-line no-console | ||
console.log('SKIPPING: TTFB is not reported'); | ||
sentryTest.skip(); | ||
} | ||
|
||
const lcpValue = eventData.measurements?.lcp?.value; | ||
const fcpValue = eventData.measurements?.fcp?.value; | ||
const fpValue = eventData.measurements?.fp?.value; | ||
|
||
expect(lcpValue).toBeDefined(); | ||
expect(fcpValue).toBeDefined(); | ||
expect(fpValue).toBeDefined(); | ||
|
||
// (LCP, FCP, FP) >= TTFB | ||
expect(lcpValue).toBeGreaterThanOrEqual(ttfbValue!); | ||
expect(fcpValue).toBeGreaterThanOrEqual(ttfbValue!); | ||
expect(fpValue).toBeGreaterThanOrEqual(ttfbValue!); | ||
}); | ||
|
||
sentryTest('captures time origin as span attribute', async ({ getLocalTestPath, page }) => { | ||
// Only run in chromium to ensure all vitals are present | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
const [eventData] = await Promise.all([getFirstSentryEnvelopeRequest<Event>(page), page.goto(url)]); | ||
|
||
const timeOriginAttribute = eventData.contexts?.trace?.data?.['performance.timeOrigin']; | ||
const transactionStartTimestamp = eventData.start_timestamp; | ||
|
||
expect(timeOriginAttribute).toBeDefined(); | ||
expect(transactionStartTimestamp).toBeDefined(); | ||
|
||
const delta = Math.abs(transactionStartTimestamp! - timeOriginAttribute); | ||
|
||
// The delta should be less than 1ms if this flakes, we should increase the threshold | ||
expect(delta).toBeLessThanOrEqual(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters