From 3f4109b4416c80243a26f56cafc7c0db7a891003 Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Thu, 21 Aug 2025 12:10:26 +0200 Subject: [PATCH] Properly fall-back on UDS profiling URL (cherry picked from commit e3cf5b614c46a6f908bf4abc7de3f902410e15e4) --- .../src/main/java/datadog/trace/api/Config.java | 14 ++++++++++++-- .../groovy/datadog/trace/api/ConfigTest.groovy | 13 +++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/internal-api/src/main/java/datadog/trace/api/Config.java b/internal-api/src/main/java/datadog/trace/api/Config.java index aae53ec7e07..36a165ee1c3 100644 --- a/internal-api/src/main/java/datadog/trace/api/Config.java +++ b/internal-api/src/main/java/datadog/trace/api/Config.java @@ -4741,8 +4741,18 @@ public String getFinalProfilingUrl() { // when agentless profiling is turned on we send directly to our intake return "https://intake.profile." + site + "/api/v2/profile"; } else { - // when profilingUrl and agentless are not set we send to the dd trace agent running locally - return getAgentUrl() + "/profiling/v1/input"; + // When profilingUrl and agentless are not set we send to the dd trace agent running locally + // However, there are two gotchas: + // - the agentHost, agentPort split will trip on IPv6 addresses because of the colon -> we + // need to use the agentUrl + // - but the agentUrl can be unix socket and OKHttp doesn't support that so we fall back to + // http + // + // There is some magic behind the scenes where the http url will be converted to UDS if the + // target is a unix socket only + String baseUrl = + agentUrl.startsWith("unix:") ? "http://" + agentHost + ":" + agentPort : agentUrl; + return baseUrl + "/profiling/v1/input"; } } diff --git a/internal-api/src/test/groovy/datadog/trace/api/ConfigTest.groovy b/internal-api/src/test/groovy/datadog/trace/api/ConfigTest.groovy index 2905470f5c5..982fc856c6b 100644 --- a/internal-api/src/test/groovy/datadog/trace/api/ConfigTest.groovy +++ b/internal-api/src/test/groovy/datadog/trace/api/ConfigTest.groovy @@ -1665,6 +1665,19 @@ class ConfigTest extends DDSpecification { config.getFinalProfilingUrl() == configuredUrl + "/profiling/v1/input" } + def "uds profiling url"() { + setup: + def configuredUrl = "unix:///path/to/socket" + def props = new Properties() + props.setProperty(TRACE_AGENT_URL, configuredUrl) + + when: + Config config = Config.get(props) + + then: + config.getFinalProfilingUrl() == "http://" + config.getAgentHost() + ":" + config.getAgentPort() + "/profiling/v1/input" + } + def "fallback to DD_TAGS"() { setup: environmentVariables.set(DD_TAGS_ENV, "a:1,b:2,c:3")