Skip to content

Commit 4c3d192

Browse files
authoredOct 7, 2024
Use perf_hooks for fetch metrics timers (vercel#70924)
These are better for telemetry and Date.now() will start to be dynamic in prerenders
1 parent cbf3215 commit 4c3d192

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed
 

‎packages/next/src/server/dev/log-requests.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function logFetchMetric(
9393

9494
writeLine(
9595
white(
96-
`${method} ${url} ${status} in ${end - start}ms ${formatCacheStatus(cacheStatus)}`
96+
`${method} ${url} ${status} in ${Math.round(end - start)}ms ${formatCacheStatus(cacheStatus)}`
9797
),
9898
1
9999
)

‎packages/next/src/server/lib/patch-fetch.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ function trackFetchMetric(
220220

221221
workStore.fetchMetrics.push({
222222
...ctx,
223-
end: Date.now(),
223+
end: performance.timeOrigin + performance.now(),
224224
idx: workStore.nextFetchId || 0,
225225
})
226226
}
@@ -250,7 +250,7 @@ export function createPatchedFetcher(
250250
url = undefined
251251
}
252252
const fetchUrl = url?.href ?? ''
253-
const fetchStart = Date.now()
253+
const fetchStart = performance.timeOrigin + performance.now()
254254
const method = init?.method?.toUpperCase() || 'GET'
255255

256256
// Do create a new span trace for internal fetches in the

0 commit comments

Comments
 (0)