Server Timing
Bun
Start by installing @bit-js/web-utils
:
bun add @bit-js/web-utils
Use it like so:
import { serverTiming } from '@bit-js/web-utils';
// Set the resolve timeapp.set('resolveTime', serverTiming.metric('resolveTime'));
// Set the result laterapp.defer((res, ctx) => { if(!(res instanceof Response)) return ctx.end(); ctx.resolveTime.append(res.headers);});
// Do route handling normallyapp.post('/new', (ctx) => { // Do something resolveSomething(ctx);});
Deno
Use it like so:
import { serverTiming } from 'npm:@bit-js/web-utils';
// Set the resolve timeapp.set('resolveTime', serverTiming.metric('resolveTime'));
// Set the result laterapp.defer((res, ctx) => { if(!(res instanceof Response)) return ctx.end(); ctx.resolveTime.append(res.headers);});
// Do route handling normallyapp.post('/new', (ctx) => { // Do something resolveSomething(ctx);});
To specify a description for the metric:
serverTiming.metric('db_query', 'The time taken to finish a database query');