Skip to content

Commit

Permalink
adjust getNavigationEntry, undo test "fix"
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 committed Nov 29, 2024
1 parent 54aae93 commit e1eff2e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ sentryTest('should capture TTFB vital.', async ({ getLocalTestUrl, page }) => {
const responseStart = await page.evaluate("performance.getEntriesByType('navigation')[0].responseStart;");
if (responseStart !== 0) {
expect(eventData.measurements?.ttfb?.value).toBeDefined();
expect(eventData.measurements?.['ttfb.requestTime']?.value).toBeDefined();
}

expect(eventData.measurements?.['ttfb.requestTime']?.value).toBeDefined();
});
4 changes: 2 additions & 2 deletions packages/browser-utils/src/metrics/browserMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export function _addMeasureSpans(
duration: number,
timeOrigin: number,
): number {
const navEntry = getNavigationEntry();
const navEntry = getNavigationEntry(false);
const requestTime = msToSec(navEntry ? navEntry.requestStart : 0);
// Because performance.measure accepts arbitrary timestamps it can produce
// spans that happen before the browser even makes a request for the page.
Expand Down Expand Up @@ -666,7 +666,7 @@ function setResourceEntrySizeData(
* ttfb information is added via vendored web vitals library.
*/
function _addTtfbRequestTimeToMeasurements(_measurements: Measurements): void {
const navEntry = getNavigationEntry();
const navEntry = getNavigationEntry(false);
if (!navEntry) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@

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

export const getNavigationEntry = (): PerformanceNavigationTiming | void => {
// sentry-specific change:
// add optional param to not check for responseStart (see comment below)
export const getNavigationEntry = (checkResponseStart = true): PerformanceNavigationTiming | void => {
const navigationEntry =
WINDOW.performance && WINDOW.performance.getEntriesByType && WINDOW.performance.getEntriesByType('navigation')[0];

// Check to ensure the `responseStart` property is present and valid.
// In some cases no value is reported by the browser (for
// privacy/security reasons), and in other cases (bugs) the value is
// negative or is larger than the current page time. Ignore these cases:
// https://github.com/GoogleChrome/web-vitals/issues/137
// https://github.com/GoogleChrome/web-vitals/issues/162
// https://github.com/GoogleChrome/web-vitals/issues/275
if (navigationEntry && navigationEntry.responseStart > 0 && navigationEntry.responseStart < performance.now()) {
if (
// sentry-specific change:
// We don't want to check for responseStart for our own use of `getNavigationEntry`
!checkResponseStart ||
(navigationEntry && navigationEntry.responseStart > 0 && navigationEntry.responseStart < performance.now())
) {
return navigationEntry;
}
};

0 comments on commit e1eff2e

Please sign in to comment.