Skip to content

Commit

Permalink
ddtrace/tracer: put hostname detection behind a compat environment va…
Browse files Browse the repository at this point in the history
…riable (#2786)
  • Loading branch information
darccio authored Jul 16, 2024
1 parent d3a6549 commit 1c67ac3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 8 additions & 2 deletions ddtrace/tracer/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"
"time"

"golang.org/x/mod/semver"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/internal"
Expand Down Expand Up @@ -384,7 +385,13 @@ func newConfig(opts ...StartOption) *config {
}
c.profilerEndpoints = internal.BoolEnv(traceprof.EndpointEnvVar, true)
c.profilerHotspots = internal.BoolEnv(traceprof.CodeHotspotsEnvVar, true)
c.enableHostnameDetection = internal.BoolEnv("DD_CLIENT_HOSTNAME_ENABLED", true)
if compatMode := os.Getenv("DD_TRACE_CLIENT_HOSTNAME_COMPAT"); compatMode != "" {
if semver.IsValid(compatMode) {
c.enableHostnameDetection = semver.Compare(semver.MajorMinor(compatMode), "v1.66") <= 0
} else {
log.Warn("ignoring DD_TRACE_CLIENT_HOSTNAME_COMPAT, invalid version %q", compatMode)
}
}
c.debugAbandonedSpans = internal.BoolEnv("DD_TRACE_DEBUG_ABANDONED_SPANS", false)
if c.debugAbandonedSpans {
c.spanTimeout = internal.DurationEnv("DD_TRACE_ABANDONED_SPAN_TIMEOUT", 10*time.Minute)
Expand Down Expand Up @@ -438,7 +445,6 @@ func newConfig(opts ...StartOption) *config {
if c.agentURL.Scheme == "unix" {
// If we're connecting over UDS we can just rely on the agent to provide the hostname
log.Debug("connecting to agent over unix, do not set hostname on any traces")
c.enableHostnameDetection = false
c.httpClient = udsClient(c.agentURL.Path, c.httpClientTimeout)
c.agentURL = &url.URL{
Scheme: "http",
Expand Down
11 changes: 3 additions & 8 deletions ddtrace/tracer/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1438,20 +1438,15 @@ func TestWithHeaderTags(t *testing.T) {
}

func TestHostnameDisabled(t *testing.T) {
t.Run("DisabledWithUDS", func(t *testing.T) {
t.Setenv("DD_TRACE_AGENT_URL", "unix://somefakesocket")
t.Run("Default", func(t *testing.T) {
c := newConfig()
assert.False(t, c.enableHostnameDetection)
})
t.Run("Default", func(t *testing.T) {
t.Run("EnableViaEnv", func(t *testing.T) {
t.Setenv("DD_TRACE_CLIENT_HOSTNAME_COMPAT", "v1.66")
c := newConfig()
assert.True(t, c.enableHostnameDetection)
})
t.Run("DisableViaEnv", func(t *testing.T) {
t.Setenv("DD_CLIENT_HOSTNAME_ENABLED", "false")
c := newConfig()
assert.False(t, c.enableHostnameDetection)
})
}

func TestPartialFlushing(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion ddtrace/tracer/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@ func TestSpanProfilingTags(t *testing.T) {
}

func TestSpanError(t *testing.T) {
t.Setenv("DD_CLIENT_HOSTNAME_ENABLED", "false") // the host name is inconsistently returning a value, causing the test to flake.
assert := assert.New(t)
tracer := newTracer(withTransport(newDefaultTransport()))
internal.SetGlobalTracer(tracer)
Expand Down

0 comments on commit 1c67ac3

Please sign in to comment.