grpc-ecosystem / go-grpc-middleware

Golang gRPC Middlewares: interceptor chaining, auth, logging, retries and more.
Apache License 2.0
6.26k stars 690 forks source link

Dynamic labels for go-grpc-prometheus middleware #445

Open jzelinskie opened 3 years ago

jzelinskie commented 3 years ago

I hope this is the right place for this issue, as I know the repositories are in-flight.

We're implementing customer-facing metrics, so we'd like to be able to label requests with the customer associated with the request.

My naive suggestion is that the middleware take a callback for calculating additional labels.

@bwplotka recommended a workaround that might be possible: using wrapped registries with the middleware.

johanbrandhorst commented 3 years ago

I'm not sure I follow exactly, do you have an example or POC PR? I think we're still pretty open to changing things since v2 isn't finalized yet.

jzelinskie commented 3 years ago

The idea would be to have an upstream-blessed way to add additional labels (that may have to be computed) to the metrics exposed by the middleware.

For example, we wanted to add a label "tenant" to the histogram labels so that we could show our users performance graphs of their own requests against our service.

Our solution is that we use this middleware without the histogram metrics, then we implemented our own histogram with the same name and labels (plus tenant) and a middleware which times the request and populates the tenant label with a value from the context.Context.