Skip to content

Commit eb4eeb4

Browse files
committed
adjust getNavigationEntry, undo test "fix"
1 parent 67b4c6e commit eb4eeb4

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ sentryTest('should capture TTFB vital.', async ({ getLocalTestUrl, page }) => {
1919
const responseStart = await page.evaluate("performance.getEntriesByType('navigation')[0].responseStart;");
2020
if (responseStart !== 0) {
2121
expect(eventData.measurements?.ttfb?.value).toBeDefined();
22-
expect(eventData.measurements?.['ttfb.requestTime']?.value).toBeDefined();
2322
}
23+
24+
expect(eventData.measurements?.['ttfb.requestTime']?.value).toBeDefined();
2425
});

packages/browser-utils/src/metrics/browserMetrics.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ export function _addMeasureSpans(
415415
duration: number,
416416
timeOrigin: number,
417417
): number {
418-
const navEntry = getNavigationEntry();
418+
const navEntry = getNavigationEntry(false);
419419
const requestTime = msToSec(navEntry ? navEntry.requestStart : 0);
420420
// Because performance.measure accepts arbitrary timestamps it can produce
421421
// spans that happen before the browser even makes a request for the page.
@@ -666,7 +666,7 @@ function setResourceEntrySizeData(
666666
* ttfb information is added via vendored web vitals library.
667667
*/
668668
function _addTtfbRequestTimeToMeasurements(_measurements: Measurements): void {
669-
const navEntry = getNavigationEntry();
669+
const navEntry = getNavigationEntry(false);
670670
if (!navEntry) {
671671
return;
672672
}

packages/browser-utils/src/metrics/web-vitals/lib/getNavigationEntry.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,24 @@
1616

1717
import { WINDOW } from '../../../types';
1818

19-
export const getNavigationEntry = (): PerformanceNavigationTiming | void => {
19+
// sentry-specific change:
20+
// add optional param to not check for responseStart (see comment below)
21+
export const getNavigationEntry = (checkResponseStart = true): PerformanceNavigationTiming | void => {
2022
const navigationEntry =
2123
WINDOW.performance && WINDOW.performance.getEntriesByType && WINDOW.performance.getEntriesByType('navigation')[0];
22-
2324
// Check to ensure the `responseStart` property is present and valid.
2425
// In some cases no value is reported by the browser (for
2526
// privacy/security reasons), and in other cases (bugs) the value is
2627
// negative or is larger than the current page time. Ignore these cases:
2728
// https://github.com/GoogleChrome/web-vitals/issues/137
2829
// https://github.com/GoogleChrome/web-vitals/issues/162
2930
// https://github.com/GoogleChrome/web-vitals/issues/275
30-
if (navigationEntry && navigationEntry.responseStart > 0 && navigationEntry.responseStart < performance.now()) {
31+
if (
32+
// sentry-specific change:
33+
// We don't want to check for responseStart for our own use of `getNavigationEntry`
34+
!checkResponseStart ||
35+
(navigationEntry && navigationEntry.responseStart > 0 && navigationEntry.responseStart < performance.now())
36+
) {
3137
return navigationEntry;
3238
}
3339
};

0 commit comments

Comments
 (0)