Merge pull request #46544 from akerouanton/api-otel-operation

api: Add method and path to trace operation string
This commit is contained in:
Bjorn Neergaard 2023-09-26 13:07:03 -06:00 committed by GitHub
commit 97e28de7e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)
}