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 0a7f1a5e7b3..52624b81353 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")