Skip to content

Commit

Permalink
feat(server): Make Sentry traces sample rate configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
exler committed Feb 18, 2024
1 parent 0b8b2d8 commit ab75d30
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion cmd/runserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
}
Expand Down
6 changes: 3 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit ab75d30

Please sign in to comment.