Skip to content

Commit 20c6a3d

Browse files
committed
Introduce cache for peer.hostname lookup
1 parent fe9f968 commit 20c6a3d

File tree

1 file changed

+15
-3
lines changed
  • dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator

1 file changed

+15
-3
lines changed

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator/BaseDecorator.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import datadog.trace.api.Config;
77
import datadog.trace.api.DDTags;
88
import datadog.trace.api.Functions;
9+
import datadog.trace.api.cache.DDCache;
10+
import datadog.trace.api.cache.DDCaches;
911
import datadog.trace.api.cache.QualifiedClassNameCache;
1012
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
1113
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
@@ -37,6 +39,8 @@ public String apply(Class<?> clazz) {
3739
},
3840
Functions.PrefixJoin.of("."));
3941

42+
private static final DDCache<String, String> HOSTNAME_CACHE = DDCaches.newFixedSizeCache(64);
43+
4044
protected final boolean traceAnalyticsEnabled;
4145
protected final Double traceAnalyticsSampleRate;
4246

@@ -114,13 +118,14 @@ public AgentSpan onPeerConnection(final AgentSpan span, final InetAddress remote
114118

115119
public AgentSpan onPeerConnection(AgentSpan span, InetAddress remoteAddress, boolean resolved) {
116120
if (remoteAddress != null) {
121+
String ip = remoteAddress.getHostAddress();
117122
if (resolved) {
118-
span.setTag(Tags.PEER_HOSTNAME, remoteAddress.getHostName());
123+
span.setTag(Tags.PEER_HOSTNAME, hostName(remoteAddress, ip));
119124
}
120125
if (remoteAddress instanceof Inet4Address) {
121-
span.setTag(Tags.PEER_HOST_IPV4, remoteAddress.getHostAddress());
126+
span.setTag(Tags.PEER_HOST_IPV4, ip);
122127
} else if (remoteAddress instanceof Inet6Address) {
123-
span.setTag(Tags.PEER_HOST_IPV6, remoteAddress.getHostAddress());
128+
span.setTag(Tags.PEER_HOST_IPV6, ip);
124129
}
125130
}
126131
return span;
@@ -187,4 +192,11 @@ public CharSequence className(final Class<?> clazz) {
187192
String simpleName = clazz.getSimpleName();
188193
return simpleName.isEmpty() ? CLASS_NAMES.getClassName(clazz) : simpleName;
189194
}
195+
196+
private static String hostName(InetAddress remoteAddress, String ip) {
197+
if (null != ip) {
198+
return HOSTNAME_CACHE.computeIfAbsent(ip, _ip -> remoteAddress.getHostName());
199+
}
200+
return remoteAddress.getHostName();
201+
}
190202
}

0 commit comments

Comments
 (0)