grpc-ecosystem / go-grpc-middleware

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

WithDecider gone but referenced on documentation #710

Open JosemyDuarte opened 6 months ago

JosemyDuarte commented 6 months ago

Hi!

I'm migrating from 1.4.0 to 2.1.0 and we were using WithDecider. I see it still referenced on the documentation https://github.com/grpc-ecosystem/go-grpc-middleware/blob/7da22cf3f3d3ae190467d9c7a3ea749b3d0e63b5/interceptors/logging/doc.go#L12-L14 But is not implemented anywhere, what is the advisable way to accomplish similar results with v2 API? I would be happy to update the docs with this information as well.

JosemyDuarte commented 6 months ago

Somehow I missed this from the README

All "deciders", so functions that decide what to do based on gRPC service name and method (aka "fullMethodName") are removed (!). Use github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/selector interceptor to select what method, type or service should use what interceptor.

I guess the doc should be updated with it, but I'm still about to investigate how to use the Selector as a replacement of WithDecider since I don't see err on CallMeta.

This is what I'm trying to translate to Selector approach:

loggingOpts := []grpczap.Option{
        grpczap.WithDecider(func(fullMethodName string, err error) bool {
            // Only log errors
            return err != nil
        }),
}