Skip to content

Commit f39cc0c

Browse files
committed
migrate debugAbandonedSpans
1 parent 7fe4066 commit f39cc0c

File tree

6 files changed

+29
-19
lines changed

6 files changed

+29
-19
lines changed

ddtrace/tracer/abandonedspans_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func TestReportAbandonedSpans(t *testing.T) {
132132
tracer, _, _, stop, err := startTestTracer(t, WithLogger(tp), WithDebugSpansMode(100*time.Millisecond))
133133
assert.Nil(err)
134134
defer stop()
135-
assert.True(tracer.config.debugAbandonedSpans)
135+
assert.True(tracer.config.internalConfig.DebugAbandonedSpans())
136136
assert.Equal(tracer.config.spanTimeout, 100*time.Millisecond)
137137
})
138138

@@ -350,7 +350,7 @@ func TestDebugAbandonedSpansOff(t *testing.T) {
350350

351351
t.Run("default", func(t *testing.T) {
352352
assert := assert.New(t)
353-
assert.False(tracer.config.debugAbandonedSpans)
353+
assert.False(tracer.config.internalConfig.DebugAbandonedSpans())
354354
assert.Equal(time.Duration(0), tracer.config.spanTimeout)
355355
expected := "Abandoned spans logs enabled."
356356
s := tracer.StartSpan("operation", StartTime(spanStartTime))

ddtrace/tracer/option.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,6 @@ type config struct {
250250
// peerServiceMappings holds a set of service mappings to dynamically rename peer.service values.
251251
peerServiceMappings map[string]string
252252

253-
// debugAbandonedSpans controls if the tracer should log when old, open spans are found
254-
debugAbandonedSpans bool
255-
256253
// spanTimeout represents how old a span can be before it should be logged as a possible
257254
// misconfiguration
258255
spanTimeout time.Duration
@@ -401,8 +398,7 @@ func newConfig(opts ...StartOption) (*config, error) {
401398
log.Warn("ignoring DD_TRACE_CLIENT_HOSTNAME_COMPAT, invalid version %q", compatMode)
402399
}
403400
}
404-
c.debugAbandonedSpans = internal.BoolEnv("DD_TRACE_DEBUG_ABANDONED_SPANS", false)
405-
if c.debugAbandonedSpans {
401+
if c.internalConfig.DebugAbandonedSpans() {
406402
c.spanTimeout = internal.DurationEnv("DD_TRACE_ABANDONED_SPAN_TIMEOUT", 10*time.Minute)
407403
}
408404
c.statsComputationEnabled = internal.BoolEnv("DD_TRACE_STATS_COMPUTATION_ENABLED", true)
@@ -1233,7 +1229,7 @@ func WithProfilerEndpoints(enabled bool) StartOption {
12331229
// be expensive, so it should only be enabled for debugging purposes.
12341230
func WithDebugSpansMode(timeout time.Duration) StartOption {
12351231
return func(c *config) {
1236-
c.debugAbandonedSpans = true
1232+
c.internalConfig.SetDebugAbandonedSpans(true, internalconfig.OriginCode)
12371233
c.spanTimeout = timeout
12381234
}
12391235
}

ddtrace/tracer/option_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -881,15 +881,15 @@ func TestTracerOptionsDefaults(t *testing.T) {
881881
t.Run("defaults", func(t *testing.T) {
882882
c, err := newTestConfig(WithAgentTimeout(2))
883883
assert.NoError(t, err)
884-
assert.Equal(t, false, c.debugAbandonedSpans)
884+
assert.Equal(t, false, c.internalConfig.DebugAbandonedSpans())
885885
assert.Equal(t, time.Duration(0), c.spanTimeout)
886886
})
887887

888888
t.Run("debug-on", func(t *testing.T) {
889889
t.Setenv("DD_TRACE_DEBUG_ABANDONED_SPANS", "true")
890890
c, err := newTestConfig(WithAgentTimeout(2))
891891
assert.NoError(t, err)
892-
assert.Equal(t, true, c.debugAbandonedSpans)
892+
assert.Equal(t, true, c.internalConfig.DebugAbandonedSpans())
893893
assert.Equal(t, 10*time.Minute, c.spanTimeout)
894894
})
895895

@@ -898,15 +898,15 @@ func TestTracerOptionsDefaults(t *testing.T) {
898898
t.Setenv("DD_TRACE_ABANDONED_SPAN_TIMEOUT", fmt.Sprint(time.Minute))
899899
c, err := newTestConfig(WithAgentTimeout(2))
900900
assert.NoError(t, err)
901-
assert.Equal(t, true, c.debugAbandonedSpans)
901+
assert.Equal(t, true, c.internalConfig.DebugAbandonedSpans())
902902
assert.Equal(t, time.Minute, c.spanTimeout)
903903
})
904904

905905
t.Run("with-function", func(t *testing.T) {
906906
c, err := newTestConfig(WithAgentTimeout(2))
907907
assert.NoError(t, err)
908908
WithDebugSpansMode(time.Second)(c)
909-
assert.Equal(t, true, c.debugAbandonedSpans)
909+
assert.Equal(t, true, c.internalConfig.DebugAbandonedSpans())
910910
assert.Equal(t, time.Second, c.spanTimeout)
911911
})
912912
})

ddtrace/tracer/span.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ func (s *Span) finish(finishTime int64) {
746746
// the agent supports dropping p0's in the client
747747
keep = shouldKeep(s)
748748
}
749-
if tracer.config.debugAbandonedSpans {
749+
if tracer.config.internalConfig.DebugAbandonedSpans() {
750750
// the tracer supports debugging abandoned spans
751751
tracer.submitAbandonedSpan(s, true)
752752
}

ddtrace/tracer/tracer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ func newTracer(opts ...StartOption) (*tracer, error) {
490490
t.reportRuntimeMetrics(defaultMetricsReportInterval)
491491
}()
492492
}
493-
if c.debugAbandonedSpans {
493+
if c.internalConfig.DebugAbandonedSpans() {
494494
log.Info("Abandoned spans logs enabled.")
495495
t.abandonedSpansDebugger = newAbandonedSpansDebugger()
496496
t.abandonedSpansDebugger.Start(t.config.spanTimeout)
@@ -806,7 +806,7 @@ func (t *tracer) StartSpan(operationName string, options ...StartSpanOption) *Sp
806806
} else {
807807
span.pprofCtxRestore = nil
808808
}
809-
if t.config.debugAbandonedSpans {
809+
if t.config.internalConfig.DebugAbandonedSpans() {
810810
select {
811811
case t.abandonedSpansDebugger.In <- newAbandonedSpanCandidate(span, false):
812812
// ok
@@ -972,7 +972,7 @@ func (t *tracer) TracerConf() TracerConf {
972972
return TracerConf{
973973
CanComputeStats: t.config.canComputeStats(),
974974
CanDropP0s: t.config.canDropP0s(),
975-
DebugAbandonedSpans: t.config.debugAbandonedSpans,
975+
DebugAbandonedSpans: t.config.internalConfig.DebugAbandonedSpans(),
976976
Disabled: !t.config.enabled.current,
977977
PartialFlush: t.config.internalConfig.PartialFlushEnabled(),
978978
PartialFlushMinSpans: t.config.internalConfig.PartialFlushMinSpans(),

internal/config/config.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ type Config struct {
5555
spanAttributeSchemaVersion int
5656
peerServiceDefaultsEnabled bool
5757
peerServiceMappings map[string]string
58-
debugAbandonedSpans bool
59-
spanTimeout time.Duration
60-
partialFlushMinSpans int
58+
// debugAbandonedSpans controls if the tracer should log when old, open spans are found
59+
debugAbandonedSpans bool
60+
spanTimeout time.Duration
61+
partialFlushMinSpans int
6162
// partialFlushEnabled specifices whether the tracer should enable partial flushing. Value
6263
// from DD_TRACE_PARTIAL_FLUSH_ENABLED, default false.
6364
partialFlushEnabled bool
@@ -326,3 +327,16 @@ func (c *Config) SetDynamicInstrumentationEnabled(enabled bool, origin telemetry
326327
c.dynamicInstrumentationEnabled = enabled
327328
telemetry.RegisterAppConfig("DD_DYNAMIC_INSTRUMENTATION_ENABLED", enabled, origin)
328329
}
330+
331+
func (c *Config) DebugAbandonedSpans() bool {
332+
c.mu.RLock()
333+
defer c.mu.RUnlock()
334+
return c.debugAbandonedSpans
335+
}
336+
337+
func (c *Config) SetDebugAbandonedSpans(enabled bool, origin telemetry.Origin) {
338+
c.mu.Lock()
339+
defer c.mu.Unlock()
340+
c.debugAbandonedSpans = enabled
341+
telemetry.RegisterAppConfig("DD_TRACE_DEBUG_ABANDONED_SPANS", enabled, origin)
342+
}

0 commit comments

Comments
 (0)