Skip to content

Commit

Permalink
Merge pull request #394 from pace/sentry-trace-sample-rate
Browse files Browse the repository at this point in the history
tracing: Lower trace sample rate and make it configurable
  • Loading branch information
monstermunchkin authored Jan 8, 2025
2 parents e3ebcdb + 528cb1c commit c943684
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions maintenance/tracing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Property| Description
--- | ---
`SENTRY_DSN` | The DSN to use.
`ENVIRONMENT` | The environment to be sent with events.
`SENTRY_TRACES_SAMPLE_RATE` | The tracing sample rate to use (default 0.1).
15 changes: 14 additions & 1 deletion maintenance/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package tracing
import (
"net/http"
"os"
"strconv"
"strings"

"github.com/getsentry/sentry-go"
Expand All @@ -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 {
Expand Down

0 comments on commit c943684

Please sign in to comment.