Logger: Add feature toggle for errors in HTTP request logs (#64425)
This commit is contained in:
@@ -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 != "" {
|
||||
|
||||
@@ -479,5 +479,11 @@ var (
|
||||
State: FeatureStateAlpha,
|
||||
Owner: grafanaAlertingSquad,
|
||||
},
|
||||
{
|
||||
Name: "unifiedRequestLog",
|
||||
Description: "Writes error logs to the request logger",
|
||||
State: FeatureStateAlpha,
|
||||
Owner: grafanaBackendPlatformSquad,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
@@ -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"
|
||||
)
|
||||
|
||||
@@ -565,7 +565,7 @@ func (g *GrafanaLive) handleOnRPC(client *centrifuge.Client, e centrifuge.RPCEve
|
||||
if errors.Is(err, datasources.ErrDataSourceAccessDenied) {
|
||||
return centrifuge.RPCReply{}, ¢rifuge.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{}, ¢rifuge.Error{Code: uint32(http.StatusBadRequest), Message: http.StatusText(http.StatusBadRequest)}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user