Skip to content

Commit b5a2351

Browse files
authored
Avoid hard-reference to Config in RemoteHostnameAdder because it causes issues with Quarkus builds using GraalVM. (#7480)
Instead we use the Supplier API to keep the hostname lookup lazy while avoiding eager analysis of the Config class. Note we deliberately avoid using a method-reference to Config because that can also lead to unexpected resolution.
1 parent 63ccd4c commit b5a2351

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

dd-trace-core/src/main/java/datadog/trace/core/tagprocessor/RemoteHostnameAdder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
package datadog.trace.core.tagprocessor;
22

3-
import datadog.trace.api.Config;
43
import datadog.trace.api.DDTags;
54
import datadog.trace.core.DDSpanContext;
65
import java.util.Map;
6+
import java.util.function.Supplier;
77

88
public class RemoteHostnameAdder implements TagsPostProcessor {
9-
private final Config config;
9+
private final Supplier<String> hostnameSupplier;
1010

11-
public RemoteHostnameAdder(Config config) {
12-
this.config = config;
11+
public RemoteHostnameAdder(Supplier<String> hostnameSupplier) {
12+
this.hostnameSupplier = hostnameSupplier;
1313
}
1414

1515
@Override
1616
public Map<String, Object> processTags(
1717
Map<String, Object> unsafeTags, DDSpanContext spanContext) {
1818
if (spanContext.getSpanId() == spanContext.getRootSpanId()) {
19-
unsafeTags.put(DDTags.TRACER_HOST, config.getHostName());
19+
unsafeTags.put(DDTags.TRACER_HOST, hostnameSupplier.get());
2020
}
2121
return unsafeTags;
2222
}

dd-trace-core/src/main/java/datadog/trace/core/tagprocessor/TagsPostProcessorFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private static TagsPostProcessor create() {
1717
}
1818
processors.add(new QueryObfuscator(Config.get().getObfuscationQueryRegexp()));
1919
if (addRemoteHostname) {
20-
processors.add(new RemoteHostnameAdder(Config.get()));
20+
processors.add(new RemoteHostnameAdder(Config.get().getHostNameSupplier()));
2121
}
2222
return new PostProcessorChain(
2323
processors.toArray(processors.toArray(new TagsPostProcessor[0])));

internal-api/src/main/java/datadog/trace/api/Config.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@
540540
import java.util.UUID;
541541
import java.util.concurrent.TimeUnit;
542542
import java.util.function.Function;
543+
import java.util.function.Supplier;
543544
import java.util.regex.Matcher;
544545
import java.util.regex.Pattern;
545546
import javax.annotation.Nonnull;
@@ -585,6 +586,10 @@ static class RuntimeIdHolder {
585586

586587
static class HostNameHolder {
587588
static final String hostName = initHostName();
589+
590+
public static String getHostName() {
591+
return hostName;
592+
}
588593
}
589594

590595
private final boolean runtimeIdEnabled;
@@ -2272,6 +2277,10 @@ public String getHostName() {
22722277
return HostNameHolder.hostName;
22732278
}
22742279

2280+
public Supplier<String> getHostNameSupplier() {
2281+
return HostNameHolder::getHostName;
2282+
}
2283+
22752284
public String getServiceName() {
22762285
return serviceName;
22772286
}

0 commit comments

Comments
 (0)