Skip to content

Commit

Permalink
fix hostname resolution logic to match the previous telemetry client
Browse files Browse the repository at this point in the history
Signed-off-by: Eliott Bouhana <eliott.bouhana@datadoghq.com>
  • Loading branch information
eliottness committed Jan 17, 2025
1 parent bb03bc5 commit 71bf34b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions internal/newtelemetry/internal/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"io"
"net"
"net/http"
"os"
"runtime"
"sync"
"time"
Expand Down Expand Up @@ -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{
Expand All @@ -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(),
Expand Down

0 comments on commit 71bf34b

Please sign in to comment.