Skip to content

Commit ab1039e

Browse files
authored
fix: use monotonic clock for measuring spans (#475)
1 parent 2274dca commit ab1039e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/server/trpc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ const t = initTRPC.context<Context>().create({
4545
// Setting outer context with tRPC will not get us correct path during request batching,
4646
// only by setting logger context in the middleware do we get the exact path to log
4747
const loggerMiddleware = t.middleware(async ({ path, next, ctx, type }) => {
48-
const start = Date.now()
48+
const start = performance.now()
4949
const logger = createBaseLogger({ path, clientIp: getIP(ctx.req) })
5050

5151
const result = await next({
5252
ctx: { logger },
5353
})
5454

55-
const durationInMs = Date.now() - start
55+
const durationInMs = Math.round(performance.now() - start)
5656

5757
if (result.ok) {
5858
logger.info({ durationInMs }, `[${type}]: ${path} - ${durationInMs}ms - OK`)

0 commit comments

Comments
 (0)