Add sentry wrapper, improve recover() logic
This commit is contained in:
@@ -5,8 +5,6 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/internal/auth"
|
||||
"github.com/cortezaproject/corteza-server/internal/http"
|
||||
"github.com/cortezaproject/corteza-server/internal/mail"
|
||||
@@ -22,29 +20,6 @@ func InitGeneralServices(smtpOpt *options.SMTPOpt, jwtOpt *options.JWTOpt, httpC
|
||||
)
|
||||
}
|
||||
|
||||
func InitSentry(sentryOpt *options.SentryOpt) error {
|
||||
if sentryOpt.DSN == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return sentry.Init(sentry.ClientOptions{
|
||||
Dsn: sentryOpt.DSN,
|
||||
Debug: sentryOpt.Debug,
|
||||
AttachStacktrace: sentryOpt.AttachStacktrace,
|
||||
SampleRate: sentryOpt.SampleRate,
|
||||
MaxBreadcrumbs: sentryOpt.MaxBreadcrumbs,
|
||||
IgnoreErrors: nil,
|
||||
BeforeSend: nil,
|
||||
BeforeBreadcrumb: nil,
|
||||
Integrations: nil,
|
||||
Transport: nil,
|
||||
ServerName: sentryOpt.ServerName,
|
||||
Release: sentryOpt.Release,
|
||||
Dist: sentryOpt.Dist,
|
||||
Environment: sentryOpt.Environment,
|
||||
})
|
||||
}
|
||||
|
||||
func HandleError(err error) {
|
||||
if err == nil {
|
||||
return
|
||||
|
||||
@@ -3,7 +3,6 @@ package cli
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -13,6 +12,7 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/pkg/api"
|
||||
"github.com/cortezaproject/corteza-server/pkg/cli/options"
|
||||
"github.com/cortezaproject/corteza-server/pkg/logger"
|
||||
"github.com/cortezaproject/corteza-server/pkg/sentry"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -220,11 +220,12 @@ func (c *Config) MakeCLI(ctx context.Context) (cmd *cobra.Command) {
|
||||
Use: c.RootCommandName,
|
||||
TraverseChildren: true,
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
if err = InitSentry(c.SentryOpt); err != nil {
|
||||
if err = sentry.Init(c.SentryOpt); err != nil {
|
||||
c.Log.Error("could not initialize Sentry", zap.Error(err))
|
||||
}
|
||||
|
||||
defer sentry.Recover()
|
||||
|
||||
InitGeneralServices(c.SmtpOpt, c.JwtOpt, c.HttpClientOpt)
|
||||
|
||||
err = c.RootCommandDBSetup.Run(ctx, cmd, c)
|
||||
|
||||
Reference in New Issue
Block a user