Skip to content

Commit

Permalink
fix dynamic lookup in CompoundMetricsProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladicek committed Nov 14, 2024
1 parent 1b56940 commit be77b2a
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import jakarta.annotation.Priority;
import jakarta.enterprise.inject.Alternative;
import jakarta.enterprise.inject.spi.CDI;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;

Expand All @@ -32,15 +32,15 @@ public class CompoundMetricsProvider implements MetricsProvider {

@Inject
CompoundMetricsProvider(
Instance<MetricsProvider> lookup,
@ConfigProperty(name = "MP_Fault_Tolerance_Metrics_Enabled", defaultValue = "true") boolean metricsEnabled) {
CDI<Object> cdi = CDI.current();
List<Class<? extends MetricsProvider>> allProviders = List.of(MicroProfileMetricsProvider.class,
OpenTelemetryProvider.class, MicrometerProvider.class);

List<MetricsProvider> providers = new ArrayList<>();
for (Class<? extends MetricsProvider> clazz : allProviders) {
try {
providers.add(cdi.select(clazz).get());
providers.add(lookup.select(clazz).get());
} catch (Exception ignored) {
// either the bean does not exist, or some of its dependencies does not exist
}
Expand Down

0 comments on commit be77b2a

Please sign in to comment.