Merge pull request #846 from DataDog/labbati/better-hostname

Avoid setting hostname tag on local root span if empty
This commit is contained in:
Luca Abbati 2019-05-17 22:44:37 +02:00 committed by GitHub
commit 7989098acc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 5 deletions

View File

@ -323,12 +323,15 @@ public class Config {
/** @return A map of tags to be applied only to the local application root span. */
public Map<String, String> getLocalRootSpanTags() {
final Map<String, String> runtimeTags = getRuntimeTags();
final Map<String, String> result =
newHashMap(reportHostName ? (runtimeTags.size() + 1) : runtimeTags.size());
result.putAll(runtimeTags);
final Map<String, String> result = new HashMap<>(runtimeTags);
if (reportHostName) {
result.put(INTERNAL_HOST_NAME, getHostname());
String hostName = getHostName();
if (null != hostName && !hostName.isEmpty()) {
result.put(INTERNAL_HOST_NAME, hostName);
}
}
return Collections.unmodifiableMap(result);
}
@ -668,7 +671,7 @@ public class Config {
* Returns the detected hostname. This operation is time consuming so if the usage changes and
* this method will be called several times then we should implement some sort of caching.
*/
private String getHostname() {
private String getHostName() {
try {
return InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {