Logger: Add feature toggle for errors in HTTP request logs (#64425)

This commit is contained in:
Emil Tullstedt
2023-03-31 15:38:09 +02:00
committed by GitHub
parent 977a7e9a55
commit be9361cb9e
19 changed files with 488 additions and 199 deletions
+6 -1
View File
@@ -27,6 +27,7 @@ type ReqContext struct {
AllowAnonymous bool
SkipCache bool
Logger log.Logger
Error error
// RequestNonce is a cryptographic request identifier for use with Content Security Policy.
RequestNonce string
IsPublicDashboardView bool
@@ -138,7 +139,11 @@ func (ctx *ReqContext) writeErrOrFallback(status int, message string, err error)
}
}
logger(logMessage, "error", err, "remote_addr", ctx.RemoteAddr(), "traceID", traceID)
if errutil.HasUnifiedLogging(ctx.Req.Context()) {
ctx.Error = err
} else {
logger(logMessage, "error", err, "remote_addr", ctx.RemoteAddr(), "traceID", traceID)
}
}
if _, ok := data["message"]; !ok && message != "" {
+6
View File
@@ -479,5 +479,11 @@ var (
State: FeatureStateAlpha,
Owner: grafanaAlertingSquad,
},
{
Name: "unifiedRequestLog",
Description: "Writes error logs to the request logger",
State: FeatureStateAlpha,
Owner: grafanaBackendPlatformSquad,
},
}
)
+1
View File
@@ -71,3 +71,4 @@ prometheusDataplane,alpha,@grafana/observability-metrics,false,false,false,false
alertStateHistoryLokiSecondary,alpha,@grafana/alerting-squad,false,false,false,false
alertStateHistoryLokiPrimary,alpha,@grafana/alerting-squad,false,false,false,false
alertStateHistoryLokiOnly,alpha,@grafana/alerting-squad,false,false,false,false
unifiedRequestLog,alpha,@grafana/backend-platform,false,false,false,false
1 Name State Owner requiresDevMode RequiresLicense RequiresRestart FrontendOnly
71 alertStateHistoryLokiSecondary alpha @grafana/alerting-squad false false false false
72 alertStateHistoryLokiPrimary alpha @grafana/alerting-squad false false false false
73 alertStateHistoryLokiOnly alpha @grafana/alerting-squad false false false false
74 unifiedRequestLog alpha @grafana/backend-platform false false false false
+4
View File
@@ -294,4 +294,8 @@ const (
// FlagAlertStateHistoryLokiOnly
// Disable Grafana alerts from emitting annotations when a remote Loki instance is available.
FlagAlertStateHistoryLokiOnly = "alertStateHistoryLokiOnly"
// FlagUnifiedRequestLog
// Writes error logs to the request logger
FlagUnifiedRequestLog = "unifiedRequestLog"
)
+1 -1
View File
@@ -565,7 +565,7 @@ func (g *GrafanaLive) handleOnRPC(client *centrifuge.Client, e centrifuge.RPCEve
if errors.Is(err, datasources.ErrDataSourceAccessDenied) {
return centrifuge.RPCReply{}, &centrifuge.Error{Code: uint32(http.StatusForbidden), Message: http.StatusText(http.StatusForbidden)}
}
var gfErr *errutil.Error
var gfErr errutil.Error
if errors.As(err, &gfErr) && gfErr.Reason.Status() == errutil.StatusBadRequest {
return centrifuge.RPCReply{}, &centrifuge.Error{Code: uint32(http.StatusBadRequest), Message: http.StatusText(http.StatusBadRequest)}
}