Skip to content

Commit 30bb13b

Browse files
amarzialimcculls
andauthored
Improves ServiceNameCollector (#8109)
* Improves ServiceNameCollector * Update internal-api/src/main/java/datadog/trace/api/remoteconfig/ServiceNameCollector.java Co-authored-by: Stuart McCulloch <[email protected]> * apply suggestions --------- Co-authored-by: Stuart McCulloch <[email protected]>
1 parent 88c493c commit 30bb13b

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

internal-api/src/main/java/datadog/trace/api/remoteconfig/ServiceNameCollector.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import datadog.trace.api.Config;
66
import java.util.ArrayList;
77
import java.util.List;
8-
import java.util.Locale;
8+
import java.util.Set;
9+
import java.util.TreeSet;
910
import java.util.concurrent.ConcurrentHashMap;
1011
import javax.annotation.Nullable;
1112
import org.slf4j.Logger;
@@ -48,14 +49,24 @@ public void addService(final String serviceName) {
4849
}
4950
return;
5051
}
51-
if (!Config.get().getServiceName().equalsIgnoreCase(serviceName)) {
52-
services.put(serviceName.toLowerCase(Locale.ROOT), serviceName);
53-
}
52+
services.putIfAbsent(serviceName, serviceName);
5453
}
5554

55+
/**
56+
* Get the list of unique services deduplicated by case. There is no locking on the addService map
57+
* so, the method is not thread safe.
58+
*
59+
* @return
60+
*/
5661
@Nullable
5762
public List<String> getServices() {
58-
return services.isEmpty() ? null : new ArrayList<>(services.values());
63+
if (services.isEmpty()) {
64+
return null;
65+
}
66+
final Set<String> uniqueNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
67+
uniqueNames.addAll(services.keySet());
68+
uniqueNames.remove(Config.get().getServiceName());
69+
return uniqueNames.isEmpty() ? null : new ArrayList<>(uniqueNames);
5970
}
6071

6172
public void clear() {

0 commit comments

Comments
 (0)