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>
(cherry picked from commit 78978048c3)
This commit is contained in:
@@ -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"
|
||||
)
|
||||
@@ -31,6 +33,9 @@ func Logger(cfg *setting.Cfg) web.Handler {
|
||||
return func(res http.ResponseWriter, req *http.Request, c *web.Context) {
|
||||
start := time.Now()
|
||||
|
||||
// we have to init the context with the counter here to update the request
|
||||
c.Req = c.Req.WithContext(log.InitCounter(c.Req.Context()))
|
||||
|
||||
rw := res.(web.ResponseWriter)
|
||||
c.Next()
|
||||
|
||||
@@ -65,6 +70,14 @@ func Logger(cfg *setting.Cfg) web.Handler {
|
||||
logParams = append(logParams, "traceID", traceID)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
if status >= 500 {
|
||||
ctx.Logger.Error("Request Completed", logParams...)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user