fix client context

pull/715/head v2.0.0-alpha3
chenzhihui 4 years ago
parent 7fb7347671
commit e25ebc73bc
  1. 11
      middleware/metrics/metrics.go

@ -92,17 +92,12 @@ func Client(opts ...Option) middleware.Middleware {
path string path string
code int32 code int32
) )
if info, ok := grpc.FromServerContext(ctx); ok { if info, ok := grpc.FromClientContext(ctx); ok {
method = "POST" method = "POST"
path = info.FullMethod path = info.FullMethod
} else if info, ok := http.FromServerContext(ctx); ok { } else if info, ok := http.FromClientContext(ctx); ok {
method = info.Request.Method method = info.Request.Method
if route := mux.CurrentRoute(info.Request); route != nil { path = info.Request.RequestURI
// /path/123 -> /path/{id}
path, _ = route.GetPathTemplate()
} else {
path = info.Request.RequestURI
}
} }
startTime := time.Now() startTime := time.Now()
reply, err := handler(ctx, req) reply, err := handler(ctx, req)

Loading…
Cancel
Save