Last active
August 6, 2021 11:37
-
-
Save percybolmer/0ce15331953dae0f67f96b1ddd54fbf8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UnaryClientInterceptor returns a new unary client interceptor that optionally logs the execution of external gRPC calls. | |
func UnaryClientInterceptor(logger *zap.Logger, opts ...Option) grpc.UnaryClientInterceptor { | |
o := evaluateClientOpt(opts) | |
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { | |
fields := newClientLoggerFields(ctx, method) | |
startTime := time.Now() | |
err := invoker(ctx, method, req, reply, cc, opts...) | |
newCtx := ctxzap.ToContext(ctx, logger.With(fields...)) | |
logFinalClientLine(newCtx, o, startTime, err, "finished client unary call") | |
return err | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment