(middleware, relativePath)
| 2 | import statsd from './statsd.js' |
| 3 | |
| 4 | export default function instrumentMiddleware(middleware, relativePath) { |
| 5 | // Requires the file as if it were being required from '../middleware/index.js'. |
| 6 | // This is a little wonky, but let's us write `app.use(instrument(path))` and |
| 7 | // maintain the name of the file, instead of hard-coding it for each middleware. |
| 8 | |
| 9 | // Check if the middleware is an async function, to use the appropriate timer |
| 10 | const isAsyncFunction = middleware.constructor.name === 'AsyncFunction' |
| 11 | |
| 12 | // Add a tag so we can see all middleware together |
| 13 | const tags = { middleware: path.basename(relativePath) } |
| 14 | |
| 15 | return isAsyncFunction |
| 16 | ? statsd.asyncTimer(middleware, 'middleware', tags) |
| 17 | : statsd.timer(middleware, 'middleware', tags) |
| 18 | } |
nothing calls this directly
no outgoing calls
no test coverage detected