diff --git a/metrics.go b/metrics.go index 1f75b06..6adc8ff 100644 --- a/metrics.go +++ b/metrics.go @@ -4,6 +4,7 @@ import ( "log" "net/http" "strconv" + "strings" "time" "github.com/gin-gonic/gin" @@ -115,7 +116,7 @@ func MetricsMiddleware() gin.HandlerFunc { httpRequestDuration.WithLabelValues(method, path).Observe(duration) // Record API-specific metrics for API routes - if c.Request.URL.Path[:4] == "/api" { + if strings.HasPrefix(c.Request.URL.Path, "/api") { apiRequestsTotal.WithLabelValues(path, method).Inc() } }