Add sentry init

This commit is contained in:
kolaente 2020-06-18 19:53:10 +02:00
parent e62c35b2db
commit db74b79498
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 12 additions and 5 deletions

View File

@ -59,6 +59,7 @@ import (
"code.vikunja.io/api/pkg/routes/caldav"
_ "code.vikunja.io/api/pkg/swagger" // To generate swagger docs
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/api/pkg/version"
"code.vikunja.io/web"
"code.vikunja.io/web/handler"
"github.com/asaskevich/govalidator"
@ -67,6 +68,7 @@ import (
"github.com/labstack/echo/v4/middleware"
elog "github.com/labstack/gommon/log"
"strings"
"time"
)
// CustomValidator is a dummy struct to use govalidator with echo
@ -118,12 +120,17 @@ func NewEcho() *echo.Echo {
}
if config.ServiceSentryDsn.GetString() != "" {
if err := sentry.Init(sentry.ClientOptions{
Dsn: config.ServiceSentryDsn.GetString(),
AttachStacktrace: true,
Release: version.Version,
}); err != nil {
log.Criticalf("Sentry init failed: %s", err)
}
defer sentry.Flush(5 * time.Second)
e.HTTPErrorHandler = func(err error, c echo.Context) {
sentry.Init(sentry.ClientOptions{
Dsn: config.ServiceSentryDsn.GetString(),
})
sentry.CaptureException(err)
e.DefaultHTTPErrorHandler(err, c)
}
}