MCPcopy Create free account
hub / github.com/github/docs / instrumentMiddleware

Function instrumentMiddleware

lib/instrument-middleware.js:4–18  ·  view source on GitHub ↗
(middleware, relativePath)

Source from the content-addressed store, hash-verified

2import statsd from './statsd.js'
3
4export 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected