From 191e5a1d33ddc6c9723a25b6e962c31b083f00b1 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Fri, 6 Jan 2023 18:43:04 +0100 Subject: [PATCH] Split sentry config as described in the docs --- main.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 6918dde..5bbc7f4 100644 --- a/main.go +++ b/main.go @@ -92,6 +92,19 @@ func main() { logger.Fatalf("Error migrating database: %v", err) } + // Setup exception tracking with Sentry if configured + // sentry init needs to happen before the echo middlewares are added + if c.SentryDSN != "" { + if err = sentry.Init(sentry.ClientOptions{ + Dsn: c.SentryDSN, + IgnoreErrors: []string{"401"}, + EnableTracing: c.SentryTracesSampleRate > 0, + TracesSampleRate: c.SentryTracesSampleRate, + }); err != nil { + logger.Errorf("sentry init error: %v", err) + } + } + // New Echo app e := echo.New() e.HideBanner = true @@ -110,16 +123,8 @@ func main() { })) // Setup exception tracking with Sentry if configured + // sentry init needs to happen before the echo middlewares are added if c.SentryDSN != "" { - if err = sentry.Init(sentry.ClientOptions{ - Dsn: c.SentryDSN, - IgnoreErrors: []string{"401"}, - EnableTracing: c.SentryTracesSampleRate > 0, - TracesSampleRate: c.SentryTracesSampleRate, - }); err != nil { - logger.Errorf("sentry init error: %v", err) - } - defer sentry.Flush(2 * time.Second) e.Use(sentryecho.New(sentryecho.Options{})) }