feat: inc generic metric if error occurs #161
This commit is contained in:
@@ -6,6 +6,9 @@ import (
|
||||
"me-fit/types"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
type ContextKey string
|
||||
@@ -14,6 +17,24 @@ const (
|
||||
ContextKeyUser ContextKey = "user_id"
|
||||
)
|
||||
|
||||
var (
|
||||
errorMetric = promauto.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Name: "mefit_error_total",
|
||||
Help: "The total number of errors during processing",
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
func LogError(message string, err error) {
|
||||
slog.Error(message + ": " + err.Error())
|
||||
errorMetric.Inc()
|
||||
}
|
||||
func LogErrorMsg(message string) {
|
||||
slog.Error(message)
|
||||
errorMetric.Inc()
|
||||
}
|
||||
|
||||
func DoRedirect(w http.ResponseWriter, r *http.Request, url string) {
|
||||
isHtmx := r.Header.Get("HX-Request") == "true"
|
||||
if isHtmx {
|
||||
|
||||
Reference in New Issue
Block a user