Frontend logging: Remove Sentry javascript agent support (#67493)
* remove Sentry * fix sourcemap resolve
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"golang.org/x/time/rate"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/frontendlogging"
|
||||
@@ -16,51 +15,8 @@ var frontendLogger = log.New("frontend")
|
||||
|
||||
type frontendLogMessageHandler func(hs *HTTPServer, c *web.Context)
|
||||
|
||||
const sentryLogEndpointPath = "/log"
|
||||
const grafanaJavascriptAgentEndpointPath = "/log-grafana-javascript-agent"
|
||||
|
||||
/** @deprecated will be removed in the next major version */
|
||||
func NewFrontendLogMessageHandler(store *frontendlogging.SourceMapStore) frontendLogMessageHandler {
|
||||
return func(hs *HTTPServer, c *web.Context) {
|
||||
event := frontendlogging.FrontendSentryEvent{}
|
||||
if err := web.Bind(c.Req, &event); err != nil {
|
||||
c.Resp.WriteHeader(http.StatusBadRequest)
|
||||
_, err = c.Resp.Write([]byte("bad request data"))
|
||||
if err != nil {
|
||||
hs.log.Error("could not write to response", "err", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var msg = "unknown"
|
||||
|
||||
if len(event.Message) > 0 {
|
||||
msg = event.Message
|
||||
} else if event.Exception != nil && len(event.Exception.Values) > 0 {
|
||||
msg = event.Exception.Values[0].FmtMessage()
|
||||
}
|
||||
|
||||
var ctx = event.ToLogContext(store)
|
||||
|
||||
switch event.Level {
|
||||
case sentry.LevelError:
|
||||
frontendLogger.Error(msg, ctx...)
|
||||
case sentry.LevelWarning:
|
||||
frontendLogger.Warn(msg, ctx...)
|
||||
case sentry.LevelDebug:
|
||||
frontendLogger.Debug(msg, ctx...)
|
||||
default:
|
||||
frontendLogger.Info(msg, ctx...)
|
||||
}
|
||||
|
||||
c.Resp.WriteHeader(http.StatusAccepted)
|
||||
_, err := c.Resp.Write([]byte("OK"))
|
||||
if err != nil {
|
||||
hs.log.Error("could not write to response", "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GrafanaJavascriptAgentLogMessageHandler(store *frontendlogging.SourceMapStore) frontendLogMessageHandler {
|
||||
return func(hs *HTTPServer, c *web.Context) {
|
||||
event := frontendlogging.FrontendGrafanaJavascriptAgentEvent{}
|
||||
@@ -143,9 +99,9 @@ func GrafanaJavascriptAgentLogMessageHandler(store *frontendlogging.SourceMapSto
|
||||
// this is to avoid reporting errors in case config was changes but there are browser
|
||||
// sessions still open with older config
|
||||
func (hs *HTTPServer) frontendLogEndpoints() web.Handler {
|
||||
if !(hs.Cfg.GrafanaJavascriptAgent.Enabled || hs.Cfg.Sentry.Enabled) {
|
||||
if !(hs.Cfg.GrafanaJavascriptAgent.Enabled) {
|
||||
return func(ctx *web.Context) {
|
||||
if ctx.Req.Method == http.MethodPost && (ctx.Req.URL.Path == sentryLogEndpointPath || ctx.Req.URL.Path == grafanaJavascriptAgentEndpointPath) {
|
||||
if ctx.Req.Method == http.MethodPost && ctx.Req.URL.Path == grafanaJavascriptAgentEndpointPath {
|
||||
ctx.Resp.WriteHeader(http.StatusAccepted)
|
||||
_, err := ctx.Resp.Write([]byte("OK"))
|
||||
if err != nil {
|
||||
@@ -156,33 +112,11 @@ func (hs *HTTPServer) frontendLogEndpoints() web.Handler {
|
||||
}
|
||||
|
||||
sourceMapStore := frontendlogging.NewSourceMapStore(hs.Cfg, hs.pluginStaticRouteResolver, frontendlogging.ReadSourceMapFromFS)
|
||||
|
||||
var rateLimiter *rate.Limiter
|
||||
var handler frontendLogMessageHandler
|
||||
handlerEndpoint := ""
|
||||
dummyEndpoint := ""
|
||||
|
||||
if hs.Cfg.GrafanaJavascriptAgent.Enabled {
|
||||
rateLimiter = rate.NewLimiter(rate.Limit(hs.Cfg.GrafanaJavascriptAgent.EndpointRPS), hs.Cfg.GrafanaJavascriptAgent.EndpointBurst)
|
||||
handler = GrafanaJavascriptAgentLogMessageHandler(sourceMapStore)
|
||||
handlerEndpoint = grafanaJavascriptAgentEndpointPath
|
||||
dummyEndpoint = sentryLogEndpointPath
|
||||
} else {
|
||||
rateLimiter = rate.NewLimiter(rate.Limit(hs.Cfg.Sentry.EndpointRPS), hs.Cfg.Sentry.EndpointBurst)
|
||||
handler = NewFrontendLogMessageHandler(sourceMapStore)
|
||||
handlerEndpoint = sentryLogEndpointPath
|
||||
dummyEndpoint = grafanaJavascriptAgentEndpointPath
|
||||
}
|
||||
rateLimiter := rate.NewLimiter(rate.Limit(hs.Cfg.GrafanaJavascriptAgent.EndpointRPS), hs.Cfg.GrafanaJavascriptAgent.EndpointBurst)
|
||||
handler := GrafanaJavascriptAgentLogMessageHandler(sourceMapStore)
|
||||
|
||||
return func(ctx *web.Context) {
|
||||
if ctx.Req.Method == http.MethodPost && ctx.Req.URL.Path == dummyEndpoint {
|
||||
ctx.Resp.WriteHeader(http.StatusAccepted)
|
||||
_, err := ctx.Resp.Write([]byte("OK"))
|
||||
if err != nil {
|
||||
hs.log.Error("could not write to response", "err", err)
|
||||
}
|
||||
}
|
||||
if ctx.Req.Method == http.MethodPost && ctx.Req.URL.Path == handlerEndpoint {
|
||||
if ctx.Req.Method == http.MethodPost && ctx.Req.URL.Path == grafanaJavascriptAgentEndpointPath {
|
||||
if !rateLimiter.AllowN(time.Now(), 1) {
|
||||
ctx.Resp.WriteHeader(http.StatusTooManyRequests)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user