Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
lib/getRoute
.npmignore
.npmrc
CHANGELOG.md
README.md
index.js
package.json
spec.js

README.md

@routes/time

middleware to report route time

Accepts a callback function which will be called after the response has ended with the following named arguments:

name type role
method String HTTP Request method
route String Express route (including base for routers)
status Number Status Code
duration Number The duration of handling the request in milliseconds (in floating point nanoseconds accuracy)

If a no route pattern matches the request - the route will equal *

const time = require('@routes/time');

// Pass in the callback function
const measure = time(
	({
		method,
		route,
		status,
		duration,
	}) => statsdClient.time('my_service.time', duration, {
		method,
		route: route.replace(/\W/g, '_'),
		status,
	})
);

app.use(measure);

Example output:

my_service.time:76.641332|ms#method:post,route:_api_v1_users__user_id,status:200
You can’t perform that action at this time.