feat: sentry integration
All checks were successful
arcad/emissary/pipeline/head This commit looks good

This commit is contained in:
2023-10-13 12:30:52 +02:00
parent 9068203e71
commit e756a60373
27 changed files with 272 additions and 67 deletions

View File

@ -7,8 +7,11 @@ import (
"sort"
"time"
"forge.cadoles.com/Cadoles/emissary/internal/command/common"
"github.com/getsentry/sentry-go"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"gitlab.com/wpetit/goweb/logger"
)
func Main(buildDate, projectVersion, gitRef, defaultConfigPath string, commands ...*cli.Command) {
@ -46,6 +49,23 @@ func Main(buildDate, projectVersion, gitRef, defaultConfigPath string, commands
return errors.WithStack(err)
}
conf, err := common.LoadConfig(ctx)
if err != nil {
return errors.Wrap(err, "Could not load configuration")
}
if conf.Sentry.DSN != "" {
err = sentry.Init(sentry.ClientOptions{
Dsn: string(conf.Sentry.DSN),
Debug: ctx.Bool("debug"),
AttachStacktrace: true,
Environment: string(conf.Sentry.Environment),
})
if err != nil {
logger.Error(ctx.Context, "could not initialize sentry", logger.E(errors.WithStack(err)))
}
}
return nil
},
Flags: []cli.Flag{
@ -84,11 +104,15 @@ func Main(buildDate, projectVersion, gitRef, defaultConfigPath string, commands
},
}
defer sentry.Flush(2 * time.Second)
app.ExitErrHandler = func(ctx *cli.Context, err error) {
if err == nil {
return
}
sentry.CaptureException(err)
debug := ctx.Bool("debug")
if !debug {

View File

@ -5,6 +5,7 @@ import (
"forge.cadoles.com/Cadoles/emissary/internal/command/common"
"github.com/getsentry/sentry-go"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"gitlab.com/wpetit/goweb/logger"
@ -32,7 +33,9 @@ func PingCommand() *cli.Command {
defer func() {
if err := db.Close(); err != nil {
logger.Error(ctx.Context, "error while closing database connection", logger.E(errors.WithStack(err)))
err = errors.WithStack(err)
logger.Error(ctx.Context, "error while closing database connection", logger.E(err))
sentry.CaptureException(err)
}
}()