44
55import datadog .trace .api .Config ;
66import java .util .ArrayList ;
7- import java .util .HashSet ;
87import java .util .List ;
9- import java .util .Locale ;
108import java .util .Set ;
9+ import java .util .TreeSet ;
1110import java .util .concurrent .ConcurrentHashMap ;
1211import javax .annotation .Nullable ;
1312import org .slf4j .Logger ;
@@ -19,9 +18,6 @@ public class ServiceNameCollector {
1918
2019 private static final int MAX_EXTRA_SERVICE = Config .get ().getRemoteConfigMaxExtraServices ();
2120
22- private static final String SERVICE_NAME_LOWERCASE =
23- Config .get ().getServiceName ().toLowerCase (Locale .ROOT );
24-
2521 // This is not final to allow mocking it on tests
2622 private static ServiceNameCollector INSTANCE = new ServiceNameCollector ();
2723
@@ -67,16 +63,10 @@ public List<String> getServices() {
6763 if (services .isEmpty ()) {
6864 return null ;
6965 }
70- final Set <String > uniques = new HashSet <>(services .size ());
71- // avoids reiterating again to convert a set to a list
72- final ArrayList <String > ret = new ArrayList <>(services .size ());
73- for (String current : services .keySet ()) {
74- String lowerCase = current .toLowerCase (Locale .ROOT );
75- if (!SERVICE_NAME_LOWERCASE .equals (lowerCase ) && uniques .add (lowerCase )) {
76- ret .add (current );
77- }
78- }
79- return ret .isEmpty () ? null : ret ;
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 );
8070 }
8171
8272 public void clear () {
0 commit comments