Instrumentation: log the total number of db queries per request (#54647)
Signed-off-by: bergquist <carl.bergquist@gmail.com> Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com> Co-authored-by: Dave Henderson <dave.henderson@grafana.com>
This commit is contained in:
co-authored by
Emil Tullstedt
Dave Henderson
parent
7e53bd107c
commit
78978048c3
@@ -20,9 +20,11 @@ import (
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/contexthandler"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
@@ -32,6 +34,9 @@ func Logger(cfg *setting.Cfg) web.Middleware {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
start := time.Now()
|
||||
|
||||
// we have to init the context with the counter here to update the request
|
||||
r = r.WithContext(log.InitCounter(r.Context()))
|
||||
|
||||
rw := web.Rw(w, r)
|
||||
next.ServeHTTP(rw, r)
|
||||
|
||||
@@ -61,6 +66,14 @@ func Logger(cfg *setting.Cfg) web.Middleware {
|
||||
"referer", SanitizeURL(ctx, r.Referer()),
|
||||
}
|
||||
|
||||
if cfg.IsFeatureToggleEnabled(featuremgmt.FlagDatabaseMetrics) {
|
||||
logParams = append(logParams, "db_call_count", log.TotalDBCallCount(ctx.Req.Context()))
|
||||
}
|
||||
|
||||
if handler, exist := routeOperationName(ctx.Req); exist {
|
||||
logParams = append(logParams, "handler", handler)
|
||||
}
|
||||
|
||||
traceID := tracing.TraceIDFromContext(ctx.Req.Context(), false)
|
||||
if traceID != "" {
|
||||
logParams = append(logParams, "traceID", traceID)
|
||||
|
||||
Reference in New Issue
Block a user