jochen-schweizer / express-prom-bundle

express middleware with standard prometheus metrics in one bundle
MIT License
310 stars 68 forks source link

adding support for prisma metrics #106

Closed obh closed 2 years ago

obh commented 2 years ago

Hi I wanted to see if we can add support for prisma metrics in this library. If one doesn't add support to the library, you can still hack it around something like this. But obviously not a clean solution.

app.use(async function(req, res, next) {
    if(req.url == '/metrics-all'){
      let prismaMetrics = await prisma.$metrics.prometheus();
      let appMetrics = await promBundle.promClient.register.metrics();
      res.end(prismaMetrics + appMetrics);
    }
    next();
  })
disjunction commented 2 years ago

I understand that it would be convenient for you just to pass prismaClient, but it breaks the concept of this library - just a helper for delivering basic metrics for an express application application http_request_duration_seconds.

If we add prisma then why not all other possible 3d party metrics?

I actually find your "hack around" to be a much cleaner solution! It will be present only in your application that uses a specific version of prisma that in the current version has prisma.$metrics.prometheus(). Who knows, maybe in the next version they will change $metrics to getMetrics() or something? But if the code you provided is part of your app, then you remain in full control of it.

Adding a dependency (even in a form of interface "contract") and maintaining it is just too much for this library. Sorry