Skip to content

Commit 483315d

Browse files
authored
Merge branch 'main' into main
2 parents dc0db31 + ec9b4ab commit 483315d

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

internal/config/config.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,24 +166,24 @@ func loadConfig() *Config {
166166
}
167167
}
168168

169-
hostname, err := os.Hostname()
170-
if err != nil {
171-
log.Warn("unable to look up hostname: %s", err.Error())
172-
cfg.hostnameLookupError = err
169+
// Hostname lookup, if DD_TRACE_REPORT_HOSTNAME is true
170+
// If the hostname lookup fails, an error is set and the hostname is not reported
171+
// The tracer will fail to start if the hostname lookup fails when it is explicitly configured
172+
// to report the hostname.
173+
if provider.getBool("DD_TRACE_REPORT_HOSTNAME", false) {
174+
hostname, err := os.Hostname()
175+
if err != nil {
176+
log.Warn("unable to look up hostname: %s", err.Error())
177+
cfg.hostnameLookupError = err
178+
}
179+
cfg.hostname = hostname
180+
cfg.reportHostname = true
173181
}
174-
175-
// Always read DD_TRACE_REPORT_HOSTNAME for telemetry tracking
176-
reportHostnameFromEnv := provider.getBool("DD_TRACE_REPORT_HOSTNAME", false)
177-
178-
// Check if DD_TRACE_SOURCE_HOSTNAME was explicitly set
182+
// Check if DD_TRACE_SOURCE_HOSTNAME was explicitly set, it takes precedence over the hostname lookup
179183
if sourceHostname, ok := env.Lookup("DD_TRACE_SOURCE_HOSTNAME"); ok {
180184
// Explicitly configured hostname - always report it
181185
cfg.hostname = sourceHostname
182186
cfg.reportHostname = true
183-
} else if err == nil {
184-
// Auto-detected hostname - only report if DD_TRACE_REPORT_HOSTNAME=true
185-
cfg.hostname = hostname
186-
cfg.reportHostname = reportHostnameFromEnv
187187
}
188188

189189
return cfg

0 commit comments

Comments
 (0)