Intégration de Sentry
This commit is contained in:
@ -23,6 +23,7 @@ type Config struct {
|
||||
Auth AuthConfig `yaml:"auth"`
|
||||
SMTP SMTPConfig `yaml:"smtp"`
|
||||
Task TaskConfig `yaml:"task"`
|
||||
Sentry SentryConfig `ymal:"sentry"`
|
||||
}
|
||||
|
||||
// NewFromFile retrieves the configuration from the given file
|
||||
@ -101,6 +102,14 @@ type NewsletterTaskConfig struct {
|
||||
SubjectTemplate string `yaml:"subjectTemplate" env:"TASK_NEWSLETTER_SUBJECT_TEMPLATE"`
|
||||
}
|
||||
|
||||
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
|
||||
@ -209,6 +218,12 @@ func NewDefault() *Config {
|
||||
SubjectTemplate: `[Daddy] Évènements du {{ .From.Format "02/01/2006" }} au {{ .To.Format "02/01/2006" }}`,
|
||||
},
|
||||
},
|
||||
Sentry: SentryConfig{
|
||||
DSN: "",
|
||||
ServerSampleRate: 1,
|
||||
ServerFlushTimeout: 2 * time.Second,
|
||||
Environment: "",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,15 @@
|
||||
package route
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/99designs/gqlgen/graphql"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"forge.cadoles.com/Cadoles/daddy/internal/config"
|
||||
"forge.cadoles.com/Cadoles/daddy/internal/graph"
|
||||
"forge.cadoles.com/Cadoles/daddy/internal/graph/generated"
|
||||
@ -44,6 +49,19 @@ func Mount(r *chi.Mux, config *config.Config) error {
|
||||
generated.NewExecutableSchema(gqlConfig),
|
||||
)
|
||||
|
||||
gql.SetRecoverFunc(func(ctx context.Context, err interface{}) error {
|
||||
// Dispatch error to Sentry
|
||||
if realErr, ok := err.(error); ok {
|
||||
sentry.CaptureException(realErr)
|
||||
}
|
||||
|
||||
if strErr, ok := err.(string); ok {
|
||||
sentry.CaptureException(errors.New(strErr))
|
||||
}
|
||||
|
||||
return graphql.DefaultRecover(ctx, err)
|
||||
})
|
||||
|
||||
gql.AddTransport(transport.POST{})
|
||||
gql.AddTransport(&transport.Websocket{
|
||||
KeepAlivePingInterval: 10 * time.Second,
|
||||
|
Reference in New Issue
Block a user