|
9 | 9 | import io.opentelemetry.instrumentation.spring.autoconfigure.internal.ConditionalOnEnabledInstrumentation;
|
10 | 10 | import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.ConfigPropertiesBridge;
|
11 | 11 | import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
|
| 12 | +import java.util.Comparator; |
| 13 | +import java.util.Optional; |
12 | 14 | import javax.annotation.PreDestroy;
|
13 | 15 | import org.slf4j.Logger;
|
14 | 16 | import org.slf4j.LoggerFactory;
|
@@ -46,16 +48,17 @@ public void handleApplicationReadyEvent(ApplicationReadyEvent event) {
|
46 | 48 | ConfigPropertiesBridge config =
|
47 | 49 | new ConfigPropertiesBridge(applicationContext.getBean(ConfigProperties.class));
|
48 | 50 |
|
49 |
| - if (Double.parseDouble(System.getProperty("java.specification.version")) >= 17) { |
50 |
| - logger.debug("Use runtime metrics instrumentation for Java 17+"); |
51 |
| - io.opentelemetry.instrumentation.runtimemetrics.java17.RuntimeMetrics.builder(openTelemetry) |
52 |
| - .setShutdownHook(runnable -> shutdownHook = runnable) |
53 |
| - .startFromInstrumentationConfig(config); |
| 51 | + double version = Double.parseDouble(System.getProperty("java.specification.version")); |
| 52 | + Optional<RuntimeMetricsProvider> metricsProvider = |
| 53 | + applicationContext.getBeanProvider(RuntimeMetricsProvider.class).stream() |
| 54 | + .sorted(Comparator.comparing(RuntimeMetricsProvider::minJavaVersion).reversed()) |
| 55 | + .filter(provider -> provider.minJavaVersion() <= version) |
| 56 | + .findFirst(); |
| 57 | + |
| 58 | + if (metricsProvider.isPresent()) { |
| 59 | + metricsProvider.get().start(openTelemetry, runnable -> shutdownHook = runnable, config); |
54 | 60 | } else {
|
55 |
| - logger.debug("Use runtime metrics instrumentation for Java 8"); |
56 |
| - io.opentelemetry.instrumentation.runtimemetrics.java8.RuntimeMetrics.builder(openTelemetry) |
57 |
| - .setShutdownHook(runnable -> shutdownHook = runnable) |
58 |
| - .startFromInstrumentationConfig(config); |
| 61 | + logger.debug("No runtime metrics instrumentation available for Java {}", version); |
59 | 62 | }
|
60 | 63 | }
|
61 | 64 | }
|
0 commit comments