Skip to content

Commit 7989098

Browse files
authored
Merge pull request #846 from DataDog/labbati/better-hostname
Avoid setting hostname tag on local root span if empty
2 parents 429fb67 + 06f13fd commit 7989098

1 file changed

Lines changed: 8 additions & 5 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: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,15 @@ 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 =
327-
newHashMap(reportHostName ? (runtimeTags.size() + 1) : runtimeTags.size());
328-
result.putAll(runtimeTags);
326+
final Map<String, String> result = new HashMap<>(runtimeTags);
327+
329328
if (reportHostName) {
330-
result.put(INTERNAL_HOST_NAME, getHostname());
329+
String hostName = getHostName();
330+
if (null != hostName && !hostName.isEmpty()) {
331+
result.put(INTERNAL_HOST_NAME, hostName);
332+
}
331333
}
334+
332335
return Collections.unmodifiableMap(result);
333336
}
334337

@@ -668,7 +671,7 @@ private static <V extends Enum<V>> Set<V> convertStringSetToEnumSet(
668671
* Returns the detected hostname. This operation is time consuming so if the usage changes and
669672
* this method will be called several times then we should implement some sort of caching.
670673
*/
671-
private String getHostname() {
674+
private String getHostName() {
672675
try {
673676
return InetAddress.getLocalHost().getHostName();
674677
} catch (UnknownHostException e) {

0 commit comments

Comments
 (0)