diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index a63d81080c..84d6e9d553 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -40,6 +40,7 @@ Use subheadings with the "=====" level for adding notes for unreleased changes: [float] ===== Bug fixes * Avoid another case where we might touch application exceptions for `safe_exceptions` - {pull}3553[#3553] +* More robust hostname detection on Windows - {pull}3556[#3556] [[release-notes-1.48.0]] ==== 1.48.0 - 2024/03/05 diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/SystemInfo.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/SystemInfo.java index baf8820d1b..68624213ef 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/SystemInfo.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/SystemInfo.java @@ -188,7 +188,10 @@ static String fallbackHostnameDiscovery(boolean isWindows) { static String discoverHostnameThroughCommand(boolean isWindows, long timeoutMillis) { String hostname; if (isWindows) { - hostname = executeHostnameDiscoveryCommand(Arrays.asList("powershell.exe", "[System.Net.Dns]::GetHostEntry($env:computerName).HostName"), timeoutMillis); + List powershellCmd = Arrays.asList("powershell.exe", + "-NoLogo", "-NonInteractive", "-NoProfile", "-ExecutionPolicy", "Bypass", + "-Command", "[System.Net.Dns]::GetHostEntry($env:computerName).HostName"); + hostname = executeHostnameDiscoveryCommand(powershellCmd, timeoutMillis); if (hostname == null || hostname.isEmpty()) { hostname = executeHostnameDiscoveryCommand(Arrays.asList("cmd.exe", "/c", "hostname"), timeoutMillis); }