Skip to content

Commit

Permalink
Fix all middlewares being dropped due to Prometheus middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
federicotdn committed Dec 11, 2024
1 parent 637d641 commit c34bf2c
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions pkg/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func NewServer() *Server {
logger := slog.New(logging.NewContextLogger(slog.Default().Handler()))

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

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

return s
Expand Down

0 comments on commit c34bf2c

Please sign in to comment.