From 5d26fa0403533f4ac01dd2d15a02aa71e248df2a Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 4 May 2021 14:28:48 +0200 Subject: [PATCH] gproxy: add sentry integration Signed-off-by: Jens Langhammer --- .bumpversion.cfg | 2 ++ cmd/server/main.go | 16 ++++++++++++++++ internal/config/config.go | 3 +++ internal/config/struct.go | 15 +++++++++++---- internal/constants/constants.go | 3 +++ internal/web/web.go | 5 ++++- 6 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 internal/constants/constants.go diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 0fc6c7c25..08e3c773e 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -33,6 +33,8 @@ values = [bumpversion:file:authentik/__init__.py] +[bumpversion:file:internal/constants/constants.go] + [bumpversion:file:outpost/pkg/version.go] [bumpversion:file:web/src/constants.ts] diff --git a/cmd/server/main.go b/cmd/server/main.go index 4f44e942b..f6c450d33 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -1,10 +1,14 @@ package main import ( + "fmt" "sync" + "time" + "github.com/getsentry/sentry-go" log "github.com/sirupsen/logrus" "goauthentik.io/internal/config" + "goauthentik.io/internal/constants" "goauthentik.io/internal/gounicorn" "goauthentik.io/internal/web" ) @@ -16,6 +20,18 @@ func main() { config.LoadConfig("./local.env.yml") config.ConfigureLogger() + if config.G.ErrorReporting.Enabled { + sentry.Init(sentry.ClientOptions{ + Dsn: "https://a579bb09306d4f8b8d8847c052d3a1d3@sentry.beryju.org/8", + AttachStacktrace: true, + TracesSampleRate: 0.6, + Release: fmt.Sprintf("authentik@%s", constants.VERSION), + Environment: config.G.ErrorReporting.Environment, + }) + defer sentry.Flush(time.Second * 5) + defer sentry.Recover() + } + rl := log.WithField("logger", "authentik.g") wg := sync.WaitGroup{} wg.Add(2) diff --git a/internal/config/config.go b/internal/config/config.go index cdf66bccf..c1811dd5c 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -23,6 +23,9 @@ func DefaultConfig() { Media: "./media", }, LogLevel: "info", + ErrorReporting: ErrorReportingConfig{ + Enabled: false, + }, } } diff --git a/internal/config/struct.go b/internal/config/struct.go index 683b6d5c7..155e7f702 100644 --- a/internal/config/struct.go +++ b/internal/config/struct.go @@ -1,10 +1,11 @@ package config type Config struct { - Debug bool `yaml:"debug"` - Web WebConfig `yaml:"web"` - Paths PathsConfig `yaml:"paths"` - LogLevel string `yaml:"log_level"` + Debug bool `yaml:"debug"` + Web WebConfig `yaml:"web"` + Paths PathsConfig `yaml:"paths"` + LogLevel string `yaml:"log_level"` + ErrorReporting ErrorReportingConfig `yaml:"error_reporting"` } type WebConfig struct { @@ -15,3 +16,9 @@ type WebConfig struct { type PathsConfig struct { Media string `yaml:"media"` } + +type ErrorReportingConfig struct { + Enabled bool `yaml:"enabled"` + Environment string `yaml:"environment"` + SendPII bool `yaml:"send_pii"` +} diff --git a/internal/constants/constants.go b/internal/constants/constants.go new file mode 100644 index 000000000..cae501e05 --- /dev/null +++ b/internal/constants/constants.go @@ -0,0 +1,3 @@ +package constants + +const VERSION = "2021.4.5" diff --git a/internal/web/web.go b/internal/web/web.go index 316a67c83..3c08e10a7 100644 --- a/internal/web/web.go +++ b/internal/web/web.go @@ -28,11 +28,14 @@ type WebServer struct { func NewWebServer() *WebServer { mainHandler := mux.NewRouter() - mainHandler.Use(recoveryMiddleware()) + if config.G.ErrorReporting.Enabled { + mainHandler.Use(recoveryMiddleware()) + } mainHandler.Use(handlers.ProxyHeaders) mainHandler.Use(handlers.CompressHandler) logginRouter := mainHandler.NewRoute().Subrouter() logginRouter.Use(loggingMiddleware) + ws := &WebServer{ LegacyProxy: true,