From e25ebc73bceaea2b5257bfaeb9f818437ba1e2ba Mon Sep 17 00:00:00 2001 From: chenzhihui Date: Sat, 20 Feb 2021 23:04:59 +0800 Subject: [PATCH] fix client context --- middleware/metrics/metrics.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/middleware/metrics/metrics.go b/middleware/metrics/metrics.go index c054ae97803..d27fe7bb03a 100644 --- a/middleware/metrics/metrics.go +++ b/middleware/metrics/metrics.go @@ -92,17 +92,12 @@ func Client(opts ...Option) middleware.Middleware { path string code int32 ) - if info, ok := grpc.FromServerContext(ctx); ok { + if info, ok := grpc.FromClientContext(ctx); ok { method = "POST" path = info.FullMethod - } else if info, ok := http.FromServerContext(ctx); ok { + } else if info, ok := http.FromClientContext(ctx); ok { method = info.Request.Method - if route := mux.CurrentRoute(info.Request); route != nil { - // /path/123 -> /path/{id} - path, _ = route.GetPathTemplate() - } else { - path = info.Request.RequestURI - } + path = info.Request.RequestURI } startTime := time.Now() reply, err := handler(ctx, req)