Skip to content

Commit

Permalink
Use perf_hooks for fetch metrics timers
Browse files Browse the repository at this point in the history
These are better for telemetry and Date.now() will start to be dynamic in prerenders
  • Loading branch information
gnoff committed Oct 7, 2024
1 parent 8a513eb commit d34e6c2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/next/src/server/dev/log-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function logFetchMetric(

writeLine(
white(
`${method} ${url} ${status} in ${end - start}ms ${formatCacheStatus(cacheStatus)}`
`${method} ${url} ${status} in ${Math.round(end - start)}ms ${formatCacheStatus(cacheStatus)}`
),
1
)
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/server/lib/patch-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function trackFetchMetric(

workStore.fetchMetrics.push({
...ctx,
end: Date.now(),
end: performance.timeOrigin + performance.now(),
idx: workStore.nextFetchId || 0,
})
}
Expand Down Expand Up @@ -250,7 +250,7 @@ export function createPatchedFetcher(
url = undefined
}
const fetchUrl = url?.href ?? ''
const fetchStart = Date.now()
const fetchStart = performance.timeOrigin + performance.now()
const method = init?.method?.toUpperCase() || 'GET'

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

0 comments on commit d34e6c2

Please sign in to comment.