From ab75d30ed1414476d2ffa9b26487f9324c689d2c Mon Sep 17 00:00:00 2001 From: Kamil Marut Date: Sun, 18 Feb 2024 09:58:28 +0100 Subject: [PATCH] feat(server): Make Sentry traces sample rate configurable --- cmd/runserver.go | 7 ++++++- server/server.go | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/runserver.go b/cmd/runserver.go index 2a1c22c..012d4d5 100644 --- a/cmd/runserver.go +++ b/cmd/runserver.go @@ -80,13 +80,18 @@ var serverCmd = &cli.Command{ Value: "undefined", EnvVars: []string{"SENTRY_ENVIRONMENT"}, }, + &cli.Float64Flag{ + Name: "sentry-traces-sample-rate", + Value: 0, + EnvVars: []string{"SENTRY_TRACES_SAMPLE_RATE"}, + }, }, Action: func(cCtx *cli.Context) error { serverOptions := []server.OptionFn{ server.Port(cCtx.Int("port")), server.MaxUploadSize(cCtx.Int64("max-upload-size")), server.MaxRequests(cCtx.Int("rate-limit")), - server.Sentry(cCtx.String("sentry-dsn"), cCtx.String("sentry-environment")), + server.Sentry(cCtx.String("sentry-dsn"), cCtx.String("sentry-environment"), cCtx.Float64("sentry-traces-sample-rate")), server.ExtraFooterText(cCtx.String("extra-footer")), server.SitePassword(cCtx.String("site-password")), } diff --git a/server/server.go b/server/server.go index 970e8f7..525180a 100644 --- a/server/server.go +++ b/server/server.go @@ -42,7 +42,7 @@ func UseStorage(storage storage.Storage) OptionFn { } } -func Sentry(sentryDSN, sentryEnvironment string) OptionFn { +func Sentry(sentryDSN, sentryEnvironment string, sentryTracesSampleRate float64) OptionFn { return func(s *Server) { if sentryDSN == "" { return @@ -51,8 +51,8 @@ func Sentry(sentryDSN, sentryEnvironment string) OptionFn { err := sentry.Init(sentry.ClientOptions{ Dsn: sentryDSN, Environment: sentryEnvironment, - EnableTracing: true, - TracesSampleRate: 0.05, + EnableTracing: sentryTracesSampleRate > 0, + TracesSampleRate: sentryTracesSampleRate, }) if err != nil { s.logger.Error(err)