Sentry integration

This commit is contained in:
2020-10-13 10:35:41 +02:00
parent 38ac4422dd
commit 41748363d1
5 changed files with 185 additions and 1 deletions

View File

@ -12,10 +12,12 @@ import (
)
type Config struct {
Debug bool `yaml:"debug"`
HTTP HTTPConfig `yaml:"http"`
SMTP SMTPConfig `yaml:"smtp"`
Hydra HydraConfig `yaml:"hydra"`
Session SessionConfig `yaml:"session"`
Sentry SentryConfig `yaml:"sentry"`
}
// NewFromFile retrieves the configuration from the given file
@ -73,6 +75,14 @@ type SessionConfig struct {
RememberMeDuration int `yaml:"rememberMeDuration" env:"HYDRA_SESSION_REMEMBER_ME_DURATION"`
}
type SentryConfig struct {
DSN string `yaml:"dsn" env:"SENTRY_DSN"`
// Server events sampling rate, see https://docs.sentry.io/platforms/go/configuration/options/
ServerSampleRate float64 `yaml:"serverSampleRate" env:"SENTRY_SERVER_SAMPLE_RATE"`
ServerFlushTimeout time.Duration `yaml:"serverFlushTimeout" env:"SENTRY_SERVER_FLUSH_TIMEOUT"`
Environment string `yaml:"environment" env:"SENTRY_ENVIRONMENT"`
}
func NewDumpDefault() *Config {
config := NewDefault()
return config
@ -80,6 +90,7 @@ func NewDumpDefault() *Config {
func NewDefault() *Config {
return &Config{
Debug: false,
HTTP: HTTPConfig{
Address: ":3000",
CookieAuthenticationKey: "",
@ -109,6 +120,12 @@ func NewDefault() *Config {
DefaultDuration: int((time.Hour * 1).Seconds()), // 1 hour
RememberMeDuration: int((time.Hour * 24 * 30).Seconds()), // 30 days
},
Sentry: SentryConfig{
DSN: "",
ServerSampleRate: 1,
ServerFlushTimeout: 2 * time.Second,
Environment: "",
},
}
}

View File

@ -6,6 +6,7 @@ import (
"forge.cadoles.com/wpetit/hydra-passwordless/internal/config"
"forge.cadoles.com/wpetit/hydra-passwordless/internal/hydra"
"forge.cadoles.com/wpetit/hydra-passwordless/internal/query"
"github.com/getsentry/sentry-go"
"github.com/pkg/errors"
"gitlab.com/wpetit/goweb/cqrs"
"gitlab.com/wpetit/goweb/logger"
@ -32,6 +33,7 @@ func handleVerification(w http.ResponseWriter, r *http.Request) {
result, err := bus.Query(ctx, qry)
if err != nil {
sentry.CaptureException(err)
logger.Error(ctx, "could not verify token", logger.E(err))
err := renderErrorPage(
@ -49,7 +51,9 @@ func handleVerification(w http.ResponseWriter, r *http.Request) {
verifyUserData, ok := result.Data().(*query.VerifyUserData)
if !ok {
panic(errors.New("unexpected result data"))
err := errors.New("unexpected result data")
sentry.CaptureException(err)
panic(err)
}
hydr := hydra.Must(ctn)
@ -70,6 +74,7 @@ func handleVerification(w http.ResponseWriter, r *http.Request) {
res, err := hydr.AcceptLoginRequest(verifyUserData.Challenge, accept)
if err != nil {
sentry.CaptureException(err)
logger.Error(ctx, "could not retrieve hydra accept response", logger.E(err))
err := renderErrorPage(