willsoto / nestjs-prometheus

NestJS module for Prometheus
Apache License 2.0
526 stars 28 forks source link

How to add Prisma metrics #2364

Closed andreasciamanna closed 1 month ago

andreasciamanna commented 1 month ago

Either I need help understanding the docs or this scenario is not covered.

Prisma provides an experimental feature for metrics.

How can I merge the default nestjs-prometheus metrics with the Prisma ones without adding a dedicated controller for the latter?

willsoto commented 1 month ago

Taking a look at the docs, you are probably going to need to override the controller and merge the results of the two calls somehow. The docs seem to have that case covered.

andreasciamanna commented 1 month ago

I usually don't ask questions that have already been answered elsewhere.

The documentation does not cover this use case, and if it does, it's not clear where and how it explains my use case. Sure, it mentions using custom controllers (which, to be honest, do not seem to fit my case) and custom metrics.

merge the results of the two calls

Which calls? I know I can use await prisma.$metrics.json() or prisma.$metrics.prometheus(), but what would be the other call? And where to use them?

The example of injecting custom metrics needs to be improved. It shows how to inject a class, and it shows that class with the @InjectMetric("metric_name") public counter: Counter<string> in the constructor, but it doesn't show how actually to add the metrics.

All these questions would not be necessary if the docs covered the use case.

willsoto commented 1 month ago

It's right here in the docs: https://www.prisma.io/docs/orm/prisma-client/observability-and-logging/metrics#use-prisma-client-metrics-with-the-prometheus-metrics-system

Screenshot 2024-09-25 at 7 26 50 AM

So yes, you will need to override the controller in order to merge the results of the two calls to be available on the single endpoint being scraped.