From 1c82592ef1bce8d63e6c38916c67892ed0c84782 Mon Sep 17 00:00:00 2001 From: Thomas Hipp Date: Wed, 8 Jan 2025 10:11:19 +0100 Subject: [PATCH] tracing: Lower trace sample rate and make it configurable --- maintenance/tracing/tracing.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/maintenance/tracing/tracing.go b/maintenance/tracing/tracing.go index 09326711..ea4ed5e6 100755 --- a/maintenance/tracing/tracing.go +++ b/maintenance/tracing/tracing.go @@ -5,6 +5,7 @@ package tracing import ( "net/http" "os" + "strconv" "strings" "github.com/getsentry/sentry-go" @@ -14,11 +15,23 @@ import ( ) func init() { + var tracesSampleRate float64 = 0.1 + + val := strings.TrimSpace(os.Getenv("SENTRY_TRACES_SAMPLE_RATE")) + if val != "" { + var err error + + tracesSampleRate, err = strconv.ParseFloat(val, 64) + if err != nil { + log.Fatalf("failed to parse SENTRY_TRACES_SAMPLE_RATE: %v", err) + } + } + err := sentry.Init(sentry.ClientOptions{ Dsn: os.Getenv("SENTRY_DSN"), Environment: os.Getenv("ENVIRONMENT"), EnableTracing: true, - TracesSampleRate: 1.0, + TracesSampleRate: tracesSampleRate, BeforeSendTransaction: func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event { // Drop request body. if event.Request != nil {