make sentry optional and panic on error

This commit is contained in:
Roman Useinov
2022-01-14 20:47:19 +00:00
parent 7af5b2c54b
commit 2b0c36ef3f

View File

@@ -7,6 +7,7 @@ import (
"os/signal"
"time"
"github.com/getsentry/sentry-go"
"github.com/go-playground/validator/v10"
"github.com/joho/godotenv"
"github.com/labstack/echo/v4"
@@ -34,13 +35,20 @@ func main() {
return
}
err = sentry.Init(sentry.ClientOptions{
Dsn: os.Getenv("SENTRY_DSN"),
})
if err != nil {
logrus.Errorf("sentry init error: %v", err)
sentryDsn := os.Getenv("SENTRY_DSN")
switch sentryDsn {
case "":
//ignore
break
default:
if err = sentry.Init(sentry.ClientOptions{
Dsn: os.Getenv("SENTRY_DSN"),
}); err != nil {
logrus.Fatalf("sentry init error: %v", err)
}
defer sentry.Flush(2 * time.Second)
}
defer sentry.Flush(2 * time.Second)
e := echo.New()