Skip to content

Commit 06f13fd

Browse files
committed
Simplify how we calculate local root span tags
1 parent 7a9d54d commit 06f13fd

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

  • dd-trace-api/src/main/java/datadog/trace/api

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -323,19 +323,13 @@ private Config(final Properties properties, final Config parent) {
323323
/** @return A map of tags to be applied only to the local application root span. */
324324
public Map<String, String> getLocalRootSpanTags() {
325325
final Map<String, String> runtimeTags = getRuntimeTags();
326+
final Map<String, String> result = new HashMap<>(runtimeTags);
326327

327-
String hostname = "";
328328
if (reportHostName) {
329-
hostname = getHostname();
330-
}
331-
boolean hostNameIsValid = null != hostname && !hostname.isEmpty();
332-
333-
final Map<String, String> result =
334-
newHashMap(hostNameIsValid ? (runtimeTags.size() + 1) : runtimeTags.size());
335-
result.putAll(runtimeTags);
336-
337-
if (hostNameIsValid) {
338-
result.put(INTERNAL_HOST_NAME, getHostname());
329+
String hostName = getHostName();
330+
if (null != hostName && !hostName.isEmpty()) {
331+
result.put(INTERNAL_HOST_NAME, hostName);
332+
}
339333
}
340334

341335
return Collections.unmodifiableMap(result);
@@ -677,7 +671,7 @@ private static <V extends Enum<V>> Set<V> convertStringSetToEnumSet(
677671
* Returns the detected hostname. This operation is time consuming so if the usage changes and
678672
* this method will be called several times then we should implement some sort of caching.
679673
*/
680-
private String getHostname() {
674+
private String getHostName() {
681675
try {
682676
return InetAddress.getLocalHost().getHostName();
683677
} catch (UnknownHostException e) {

0 commit comments

Comments
 (0)