pragmaticivan / nestjs-otel

OpenTelemetry (Tracing + Metrics) module for Nest framework (node.js) 🔭
Apache License 2.0
540 stars 49 forks source link

How to track gRPC requests? #494

Closed gigi closed 1 month ago

gigi commented 1 month ago

Hello. Could you please provide an example how this module can help to collect gRPC endpoints' metrics.

Thank you

pragmaticivan commented 1 month ago

This is more of a opentelemetry question: https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node

^ if you use auto instrumentations, grpc is included automatically.

ex: https://github.com/pragmaticivan/nestjs-otel-prom-grafana-tempo/blob/main/services/actor/src/instrumentation.ts#L31

gigi commented 1 month ago

Yes. @pragmaticivan thanks for your reply.

We use GrpcInstrumentation for traces, but it doesn't add any metrics to exporters like described here https://github.com/pragmaticivan/nestjs-otel?tab=readme-ov-file#api-metrics-with-middleware

It seems that apiMetrics.enable: true works only for http (not Nest microservice) endpoints, right? So there is no way to do it automatically.

pragmaticivan commented 1 month ago

Ohhh I see, no, se don't instrument grpc as part of this lib like we do with REST because there were no settled conventions in opentelemetry yet

pragmaticivan commented 1 month ago

Note that you can simply implement a middleware yourself and set metrics as you see fit for grpc

gigi commented 1 month ago

Ok Thank you!

pragmaticivan commented 1 month ago

I will keep an eye and check if they finally had established a semantic convention for metric names and attributes soon