|
6 | 6 | import datadog.trace.api.Config; |
7 | 7 | import datadog.trace.api.DDTags; |
8 | 8 | import datadog.trace.api.Functions; |
| 9 | +import datadog.trace.api.cache.DDCache; |
| 10 | +import datadog.trace.api.cache.DDCaches; |
9 | 11 | import datadog.trace.api.cache.QualifiedClassNameCache; |
10 | 12 | import datadog.trace.bootstrap.instrumentation.api.AgentScope; |
11 | 13 | import datadog.trace.bootstrap.instrumentation.api.AgentSpan; |
@@ -37,6 +39,8 @@ public String apply(Class<?> clazz) { |
37 | 39 | }, |
38 | 40 | Functions.PrefixJoin.of(".")); |
39 | 41 |
|
| 42 | + private static final DDCache<String, String> HOSTNAME_CACHE = DDCaches.newFixedSizeCache(64); |
| 43 | + |
40 | 44 | protected final boolean traceAnalyticsEnabled; |
41 | 45 | protected final Double traceAnalyticsSampleRate; |
42 | 46 |
|
@@ -114,13 +118,14 @@ public AgentSpan onPeerConnection(final AgentSpan span, final InetAddress remote |
114 | 118 |
|
115 | 119 | public AgentSpan onPeerConnection(AgentSpan span, InetAddress remoteAddress, boolean resolved) { |
116 | 120 | if (remoteAddress != null) { |
| 121 | + String ip = remoteAddress.getHostAddress(); |
117 | 122 | if (resolved) { |
118 | | - span.setTag(Tags.PEER_HOSTNAME, remoteAddress.getHostName()); |
| 123 | + span.setTag(Tags.PEER_HOSTNAME, hostName(remoteAddress, ip)); |
119 | 124 | } |
120 | 125 | if (remoteAddress instanceof Inet4Address) { |
121 | | - span.setTag(Tags.PEER_HOST_IPV4, remoteAddress.getHostAddress()); |
| 126 | + span.setTag(Tags.PEER_HOST_IPV4, ip); |
122 | 127 | } else if (remoteAddress instanceof Inet6Address) { |
123 | | - span.setTag(Tags.PEER_HOST_IPV6, remoteAddress.getHostAddress()); |
| 128 | + span.setTag(Tags.PEER_HOST_IPV6, ip); |
124 | 129 | } |
125 | 130 | } |
126 | 131 | return span; |
@@ -187,4 +192,11 @@ public CharSequence className(final Class<?> clazz) { |
187 | 192 | String simpleName = clazz.getSimpleName(); |
188 | 193 | return simpleName.isEmpty() ? CLASS_NAMES.getClassName(clazz) : simpleName; |
189 | 194 | } |
| 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 | + } |
190 | 202 | } |
0 commit comments