From 430a5f8581bc5c2ea9759808192b5d96dee31e83 Mon Sep 17 00:00:00 2001 From: Albin Kerouanton Date: Sat, 23 Sep 2023 16:03:39 +0200 Subject: [PATCH] api: Add method and path to trace operation string Currently, all traces coming from the API have an empty operation string, which make them indistinguishable from each other without looking at the logs of the root span, and prevent proper filtering on Jaeger UI. With this change, traces get the route pattern as the operation string. Signed-off-by: Albin Kerouanton --- api/server/server.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/server/server.go b/api/server/server.go index 7d62dd504a..fdd49aed1e 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -30,7 +30,7 @@ func (s *Server) UseMiddleware(m middleware.Middleware) { s.middlewares = append(s.middlewares, m) } -func (s *Server) makeHTTPHandler(handler httputils.APIFunc) http.HandlerFunc { +func (s *Server) makeHTTPHandler(handler httputils.APIFunc, operation string) http.HandlerFunc { return otelhttp.NewHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Define the context that we'll pass around to share info // like the docker-request-id. @@ -59,7 +59,7 @@ func (s *Server) makeHTTPHandler(handler httputils.APIFunc) http.HandlerFunc { } makeErrorHandler(err)(w, r) } - }), "").ServeHTTP + }), operation).ServeHTTP } type pageNotFoundError struct{} @@ -77,7 +77,7 @@ func (s *Server) CreateMux(routers ...router.Router) *mux.Router { log.G(context.TODO()).Debug("Registering routers") for _, apiRouter := range routers { for _, r := range apiRouter.Routes() { - f := s.makeHTTPHandler(r.Handler()) + f := s.makeHTTPHandler(r.Handler(), r.Method()+" "+r.Path()) log.G(context.TODO()).Debugf("Registering %s, %s", r.Method(), r.Path()) m.Path(versionMatcher + r.Path()).Methods(r.Method()).Handler(f) @@ -87,7 +87,7 @@ func (s *Server) CreateMux(routers ...router.Router) *mux.Router { debugRouter := debug.NewRouter() for _, r := range debugRouter.Routes() { - f := s.makeHTTPHandler(r.Handler()) + f := s.makeHTTPHandler(r.Handler(), r.Method()+" "+r.Path()) m.Path("/debug" + r.Path()).Handler(f) }