Skip to content

Commit

Permalink
Use AdditionalIndexedClassesBuildItem for MongoTracingCommandListener
Browse files Browse the repository at this point in the history
  • Loading branch information
vkn committed Apr 29, 2024
1 parent 8e551cf commit 6d35887
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Default;
Expand Down Expand Up @@ -74,6 +73,7 @@
import io.quarkus.mongodb.runtime.MongodbConfig;
import io.quarkus.mongodb.runtime.dns.MongoDnsClient;
import io.quarkus.mongodb.runtime.dns.MongoDnsClientProvider;
import io.quarkus.mongodb.tracing.MongoTracingCommandListener;
import io.quarkus.runtime.metrics.MetricsFactory;
import io.quarkus.smallrye.health.deployment.spi.HealthBuildItem;
import io.quarkus.vertx.deployment.VertxBuildItem;
Expand All @@ -86,8 +86,6 @@ public class MongoClientProcessor {

private static final DotName MONGO_CLIENT_CUSTOMIZER = DotName.createSimple(MongoClientCustomizer.class.getName());

private static final String MONGODB_TRACING_COMMANDLISTENER_CLASSNAME = "io.quarkus.mongodb.tracing.MongoTracingCommandListener";

private static final String SERVICE_BINDING_INTERFACE_NAME = "io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter";

@BuildStep
Expand All @@ -114,6 +112,14 @@ AdditionalIndexedClassesBuildItem includeDnsTypesToIndex() {
MongoDnsClient.class.getName());
}

@BuildStep
AdditionalIndexedClassesBuildItem includeDnsTypesToIndex(MongoClientBuildTimeConfig buildTimeConfig) {
if (buildTimeConfig.tracingEnabled) {
return new AdditionalIndexedClassesBuildItem(MongoTracingCommandListener.class.getName());
}
return new AdditionalIndexedClassesBuildItem();
}

@BuildStep
public void registerDnsProvider(BuildProducer<NativeImageResourceBuildItem> nativeProducer) {
nativeProducer.produce(new NativeImageResourceBuildItem("META-INF/services/" + DnsClientProvider.class.getName()));
Expand Down Expand Up @@ -146,18 +152,13 @@ BsonDiscriminatorBuildItem collectBsonDiscriminators(CombinedIndexBuildItem inde
}

@BuildStep
CommandListenerBuildItem collectCommandListeners(CombinedIndexBuildItem indexBuildItem,
MongoClientBuildTimeConfig buildTimeConfig, Capabilities capabilities) {
CommandListenerBuildItem collectCommandListeners(CombinedIndexBuildItem indexBuildItem) {
Collection<ClassInfo> commandListenerClasses = indexBuildItem.getIndex()
.getAllKnownImplementors(DotName.createSimple(CommandListener.class.getName()));
Stream<String> names = commandListenerClasses.stream()
.map(ci -> ci.name().toString());
Stream<String> tracing = Stream.empty();
if (buildTimeConfig.tracingEnabled && capabilities.isPresent(Capability.OPENTELEMETRY_TRACER)) {
tracing = Stream.of(MONGODB_TRACING_COMMANDLISTENER_CLASSNAME);
}
var items = Stream.concat(names, tracing).toList();
return new CommandListenerBuildItem(items);
List<String> names = commandListenerClasses.stream()
.map(ci -> ci.name().toString())
.collect(Collectors.toList());
return new CommandListenerBuildItem(names);
}

@BuildStep
Expand Down

0 comments on commit 6d35887

Please sign in to comment.