Observability
Logger
Usage
ts
import { App } from 'https://deno.land/x/toruk/mod.ts'
import { logger } from 'https://deno.land/x/toruk/middlewares/mod.ts'
new App({
routes: [ /* ... */ ],
use: [
logger(),
]
}).serve()
Output
[GET] / 200 OK 5ms
[POST] / 200 OK 1ms
[DELETE] / 200 OK 3ms
[GET] /users 404 Not Found 0ms
[OPTIONS] /users 404 Not Found 0ms
[DELETE] /users/1 404 Not Found 0ms
Timing
The Server-Timing middleware provides performance metrics in the response headers.
🚧 WIP
This feature is under development.
Usage
ts
import { App } from 'https://deno.land/x/toruk/mod.ts'
import { timing } from 'https://deno.land/x/toruk/middlewares/mod.ts'
new App({
routes: [{
path: '/',
handler: ({ timing: { startTime, endTime, setMetric } }) => {
// Start a timer
startTime('db')
const data = await db.findMany(/* ... */)
endTime('db')
// Set a custom metric
setMetric('region', 'europe-west3')
// Custom metrics measured in milliseconds
setMetric('custom', 23.8, 'My custom Metric')
return Response.json({ data })
}
}],
use: [
timing(),
]
}).serve()
Output
--