From 71bf34b63febad26e9900fab9157d1717b27cfdd Mon Sep 17 00:00:00 2001 From: Eliott Bouhana Date: Fri, 17 Jan 2025 15:54:04 +0100 Subject: [PATCH] fix hostname resolution logic to match the previous telemetry client Signed-off-by: Eliott Bouhana --- internal/newtelemetry/internal/writer.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/newtelemetry/internal/writer.go b/internal/newtelemetry/internal/writer.go index 2a8cce2384..51dd9badda 100644 --- a/internal/newtelemetry/internal/writer.go +++ b/internal/newtelemetry/internal/writer.go @@ -13,6 +13,7 @@ import ( "io" "net" "net/http" + "os" "runtime" "sync" "time" @@ -47,9 +48,13 @@ var defaultHTTPClient = &http.Client{ } func newBody(config TracerConfig, debugMode bool) *transport.Body { - hostname := hostname.Get() - if hostname == "" { - hostname = "unknown" + osHostname, err := os.Hostname() + if err != nil { + osHostname = hostname.Get() + } + + if osHostname == "" { + osHostname = "unknown" // hostname field is not allowed to be empty } return &transport.Body{ @@ -65,7 +70,7 @@ func newBody(config TracerConfig, debugMode bool) *transport.Body { LanguageVersion: runtime.Version(), }, Host: transport.Host{ - Hostname: hostname, + Hostname: osHostname, OS: osinfo.OSName(), OSVersion: osinfo.OSVersion(), Architecture: osinfo.Architecture(),