Skip to content

Commit a33e3a9

Browse files
Merge pull request #403 from pace/add_env_var_SENTRY_ENABLE_TRACING
make enabling sentry tracing configurable; default is true
2 parents 6b8db36 + 4c67529 commit a33e3a9

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

maintenance/tracing/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ Property| Description
88
--- | ---
99
`SENTRY_DSN` | The DSN to use.
1010
`ENVIRONMENT` | The environment to be sent with events.
11-
`SENTRY_TRACES_SAMPLE_RATE` | The tracing sample rate to use (default 0.1).
11+
`SENTRY_TRACES_SAMPLE_RATE` | The tracing sample rate to use (default: 0.1).
12+
`SENTRY_ENABLE_TRACING` | Enable or disable tracing (default: true).

maintenance/tracing/tracing.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import (
1515
)
1616

1717
func init() {
18-
var tracesSampleRate float64 = 0.1
18+
var (
19+
tracesSampleRate = 0.1
20+
enableTracing = true
21+
)
1922

2023
val := strings.TrimSpace(os.Getenv("SENTRY_TRACES_SAMPLE_RATE"))
2124
if val != "" {
@@ -27,10 +30,20 @@ func init() {
2730
}
2831
}
2932

33+
valEnableTracing := strings.TrimSpace(os.Getenv("SENTRY_ENABLE_TRACING"))
34+
if valEnableTracing != "" {
35+
var err error
36+
37+
enableTracing, err = strconv.ParseBool(valEnableTracing)
38+
if err != nil {
39+
log.Fatalf("failed to parse SENTRY_ENABLE_TRACING: %v", err)
40+
}
41+
}
42+
3043
err := sentry.Init(sentry.ClientOptions{
3144
Dsn: os.Getenv("SENTRY_DSN"),
3245
Environment: os.Getenv("ENVIRONMENT"),
33-
EnableTracing: true,
46+
EnableTracing: enableTracing,
3447
TracesSampleRate: tracesSampleRate,
3548
BeforeSendTransaction: func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event {
3649
// Drop request body.

0 commit comments

Comments
 (0)