Skip to content

Commit

Permalink
Improves ServiceNameCollector (#8109)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
amarziali and mcculls authored Dec 20, 2024
1 parent 88c493c commit 30bb13b
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import datadog.trace.api.Config;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable;
import org.slf4j.Logger;
Expand Down Expand Up @@ -48,14 +49,24 @@ public void addService(final String serviceName) {
}
return;
}
if (!Config.get().getServiceName().equalsIgnoreCase(serviceName)) {
services.put(serviceName.toLowerCase(Locale.ROOT), serviceName);
}
services.putIfAbsent(serviceName, serviceName);
}

/**
* Get the list of unique services deduplicated by case. There is no locking on the addService map
* so, the method is not thread safe.
*
* @return
*/
@Nullable
public List<String> getServices() {
return services.isEmpty() ? null : new ArrayList<>(services.values());
if (services.isEmpty()) {
return null;
}
final Set<String> uniqueNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
uniqueNames.addAll(services.keySet());
uniqueNames.remove(Config.get().getServiceName());
return uniqueNames.isEmpty() ? null : new ArrayList<>(uniqueNames);
}

public void clear() {
Expand Down

0 comments on commit 30bb13b

Please sign in to comment.