Skip to content

Commit c34bf2c

Browse files
committed
Fix all middlewares being dropped due to Prometheus middleware
1 parent 637d641 commit c34bf2c

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

pkg/http/http.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func NewServer() *Server {
115115
logger := slog.New(logging.NewContextLogger(slog.Default().Handler()))
116116

117117
router := chi.NewRouter()
118+
router.Use(PrometheusMiddleware)
118119
router.Use(middleware.Recoverer)
119120
router.Use(cors.New(cors.Options{
120121
AllowedOrigins: []string{"*"},
@@ -139,8 +140,6 @@ func (s *Server) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
139140

140141
// WithPrometheus adds a /metrics endpoint and instrument subsequently enabled groups with general http-level metrics.
141142
func (s *Server) WithPrometheus() *Server {
142-
// Add MW with .With instead of .Use, as .Use does not allow registering MWs after routes.
143-
s.router = s.router.With(PrometheusMiddleware)
144143
s.router.Handle("/metrics", promhttp.Handler())
145144

146145
return s

0 commit comments

Comments
 (0)