willsoto/nestjs-prometheus

How the custom controller works?

devvaneio opened this issue · 4 comments

I would like to create a middleware with default metrics instead of annotating every endpoint.

Default metrics are enabled out of the box and you don't need to annotate every endpoint. See the docs. If this isn't what you mean, please elaborate or provide an example what you want to achieve.

Sry. I have "custom" metrics that I would like to create as default metrics:

If you have the time, checkout the example from Django: https://github.com/korfuri/django-prometheus/blob/master/django_prometheus/middleware.py

This metrics apply to every endpoint. I don't know it's works that way in this project.

All you need to do is create a middleware as described in the Nest.js docs. You would then inject whatever metrics you want into the middleware - similar to this. All that would be needed at that point is to annotate your controllers with that middleware you created.

Great. That's exactly what I was thinking about. I just didn't wanna do something already done. Thks.