feat(observabillity): #115 migrate to otel
Some checks failed
Build Docker Image / Build-Docker-Image (push) Failing after 3m59s

This commit is contained in:
2025-05-29 22:34:30 +02:00
parent 889672fefd
commit 587de563f9
26 changed files with 411 additions and 317 deletions

View File

@@ -2,23 +2,8 @@ package middleware
import (
"net/http"
"strconv"
"time"
"spend-sparrow/internal/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var (
metrics = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "mefit_request_total",
Help: "The total number of requests processed",
},
[]string{"path", "method", "status"},
)
"time"
)
type WrappedWriter struct {
@@ -41,7 +26,11 @@ func Log(next http.Handler) http.Handler {
}
next.ServeHTTP(wrapped, r)
log.Info(r.RemoteAddr + " " + strconv.Itoa(wrapped.StatusCode) + " " + r.Method + " " + r.URL.Path + " " + time.Since(start).String())
metrics.WithLabelValues(r.URL.Path, r.Method, http.StatusText(wrapped.StatusCode)).Inc()
log.L.Info("request",
"remoteAddr", r.RemoteAddr,
"status", wrapped.StatusCode,
"method", r.Method,
"path", r.URL.Path,
"duration", time.Since(start).String())
})
}