@@ -37,6 +37,7 @@ import (
37
37
"gopkg.in/DataDog/dd-trace-go.v1/internal/version"
38
38
39
39
"github.com/DataDog/datadog-go/v5/statsd"
40
+ "github.com/darccio/knobs"
40
41
)
41
42
42
43
var contribIntegrations = map [string ]struct {
@@ -115,6 +116,8 @@ var (
115
116
116
117
// config holds the tracer configuration.
117
118
type config struct {
119
+ * knobs.Scope
120
+
118
121
// debug, when true, writes details to logs.
119
122
debug bool
120
123
@@ -252,15 +255,6 @@ type config struct {
252
255
// misconfiguration
253
256
spanTimeout time.Duration
254
257
255
- // partialFlushMinSpans is the number of finished spans in a single trace to trigger a
256
- // partial flush, or 0 if partial flushing is disabled.
257
- // Value from DD_TRACE_PARTIAL_FLUSH_MIN_SPANS, default 1000.
258
- partialFlushMinSpans int
259
-
260
- // partialFlushEnabled specifices whether the tracer should enable partial flushing. Value
261
- // from DD_TRACE_PARTIAL_FLUSH_ENABLED, default false.
262
- partialFlushEnabled bool
263
-
264
258
// statsComputationEnabled enables client-side stats computation (aka trace metrics).
265
259
statsComputationEnabled bool
266
260
@@ -297,6 +291,39 @@ type config struct {
297
291
logDirectory string
298
292
}
299
293
294
+ var (
295
+ // partialFlushEnabled specifices whether the tracer should enable partial flushing. Value
296
+ // from DD_TRACE_PARTIAL_FLUSH_ENABLED, default false.
297
+ partialFlushEnabled = knobs .Register (& knobs.Definition [bool ]{
298
+ Default : false ,
299
+ EnvVars : []knobs.EnvVar {{Key : "DD_TRACE_PARTIAL_FLUSH_ENABLED" }},
300
+ Parse : knobs .ToBool ,
301
+ })
302
+
303
+ // partialFlushMinSpans is the number of finished spans in a single trace to trigger a
304
+ // partial flush, or 0 if partial flushing is disabled.
305
+ // Value from DD_TRACE_PARTIAL_FLUSH_MIN_SPANS, default 1000.
306
+ partialFlushMinSpans = knobs .Register (& knobs.Definition [int ]{
307
+ // TODO(partialFlush): consider logging a warning if DD_TRACE_PARTIAL_FLUSH_MIN_SPANS
308
+ // is set, but DD_TRACE_PARTIAL_FLUSH_ENABLED is not true. Or just assume it should be enabled
309
+ // if it's explicitly set, and don't require both variables to be configured.
310
+ Default : 1000 ,
311
+ EnvVars : []knobs.EnvVar {{Key : "DD_TRACE_PARTIAL_FLUSH_MIN_SPANS" }},
312
+ Requires : []any {partialFlushEnabled },
313
+ Parse : func (v string ) (int , error ) {
314
+ i , _ := strconv .Atoi (v )
315
+ if i <= 0 {
316
+ log .Warn ("DD_TRACE_PARTIAL_FLUSH_MIN_SPANS=%d is not a valid value, setting to default %d" , i , 1000 )
317
+ return 0 , knobs .ErrInvalidValue
318
+ } else if i >= traceMaxSize {
319
+ log .Warn ("DD_TRACE_PARTIAL_FLUSH_MIN_SPANS=%d is above the max number of spans that can be kept in memory for a single trace (%d spans), so partial flushing will never trigger, setting to default %d" , i , traceMaxSize , 1000 )
320
+ return 0 , knobs .ErrInvalidValue
321
+ }
322
+ return i , nil
323
+ },
324
+ })
325
+ )
326
+
300
327
// orchestrionConfig contains Orchestrion configuration.
301
328
type orchestrionConfig struct {
302
329
// Enabled indicates whether this tracer was instanciated via Orchestrion.
@@ -318,13 +345,11 @@ type StartOption func(*config)
318
345
// maxPropagatedTagsLength limits the size of DD_TRACE_X_DATADOG_TAGS_MAX_LENGTH to prevent HTTP 413 responses.
319
346
const maxPropagatedTagsLength = 512
320
347
321
- // partialFlushMinSpansDefault is the default number of spans for partial flushing, if enabled.
322
- const partialFlushMinSpansDefault = 1000
323
-
324
348
// newConfig renders the tracer configuration based on defaults, environment variables
325
349
// and passed user opts.
326
350
func newConfig (opts ... StartOption ) * config {
327
351
c := new (config )
352
+ c .Scope = knobs .NewScope ()
328
353
c .sampler = NewAllSampler ()
329
354
sampleRate := math .NaN ()
330
355
if r := getDDorOtelConfig ("sampleRate" ); r != "" {
@@ -419,19 +444,6 @@ func newConfig(opts ...StartOption) *config {
419
444
}
420
445
c .statsComputationEnabled = internal .BoolEnv ("DD_TRACE_STATS_COMPUTATION_ENABLED" , false )
421
446
c .dataStreamsMonitoringEnabled = internal .BoolEnv ("DD_DATA_STREAMS_ENABLED" , false )
422
- c .partialFlushEnabled = internal .BoolEnv ("DD_TRACE_PARTIAL_FLUSH_ENABLED" , false )
423
- c .partialFlushMinSpans = internal .IntEnv ("DD_TRACE_PARTIAL_FLUSH_MIN_SPANS" , partialFlushMinSpansDefault )
424
- if c .partialFlushMinSpans <= 0 {
425
- log .Warn ("DD_TRACE_PARTIAL_FLUSH_MIN_SPANS=%d is not a valid value, setting to default %d" , c .partialFlushMinSpans , partialFlushMinSpansDefault )
426
- c .partialFlushMinSpans = partialFlushMinSpansDefault
427
- } else if c .partialFlushMinSpans >= traceMaxSize {
428
- log .Warn ("DD_TRACE_PARTIAL_FLUSH_MIN_SPANS=%d is above the max number of spans that can be kept in memory for a single trace (%d spans), so partial flushing will never trigger, setting to default %d" , c .partialFlushMinSpans , traceMaxSize , partialFlushMinSpansDefault )
429
- c .partialFlushMinSpans = partialFlushMinSpansDefault
430
- }
431
- // TODO(partialFlush): consider logging a warning if DD_TRACE_PARTIAL_FLUSH_MIN_SPANS
432
- // is set, but DD_TRACE_PARTIAL_FLUSH_ENABLED is not true. Or just assume it should be enabled
433
- // if it's explicitly set, and don't require both variables to be configured.
434
-
435
447
c .dynamicInstrumentationEnabled = internal .BoolEnv ("DD_DYNAMIC_INSTRUMENTATION_ENABLED" , false )
436
448
437
449
schemaVersionStr := os .Getenv ("DD_TRACE_SPAN_ATTRIBUTE_SCHEMA" )
@@ -1192,8 +1204,8 @@ func WithDebugSpansMode(timeout time.Duration) StartOption {
1192
1204
// is disabled by default.
1193
1205
func WithPartialFlushing (numSpans int ) StartOption {
1194
1206
return func (c * config ) {
1195
- c . partialFlushEnabled = true
1196
- c . partialFlushMinSpans = numSpans
1207
+ knobs . SetScope ( c . Scope , partialFlushEnabled , knobs . Code , true )
1208
+ knobs . SetScope ( c . Scope , partialFlushMinSpans , knobs . Code , numSpans )
1197
1209
}
1198
1210
}
1199
1211
0 commit comments