Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

instrument-middleware.js 863 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  1. const path = require('path')
  2. const statsd = require('./statsd')
  3. module.exports = function instrumentMiddleware (relativePath) {
  4. // Requires the file as if it were being required from '../middleware/index.js'.
  5. // This is a little wonky, but let's us write `app.use(instrument(path))` and
  6. // maintain the name of the file, instead of hard-coding it for each middleware.
  7. const middleware = require(path.resolve(__dirname, '../middleware', relativePath))
  8. // Check if the middleware is an async function, to use the appropriate timer
  9. const isAsyncFunction = middleware.constructor.name === 'AsyncFunction'
  10. // Add a tag so we can see all middleware together
  11. const tags = { middleware: path.basename(relativePath) }
  12. return isAsyncFunction
  13. ? statsd.asyncTimer(middleware, 'middleware', tags)
  14. : statsd.timer(middleware, 'middleware', tags)
  15. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...