Skip to content

Commit 8de3f0e

Browse files
authored
Fix jmx-metrics on wildfly (#11151)
1 parent 5737f1d commit 8de3f0e

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

instrumentation/jmx-metrics/javaagent/src/main/java/io/opentelemetry/instrumentation/javaagent/jmx/JmxMetricInsightInstaller.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,22 @@ public void afterAgent(AutoConfiguredOpenTelemetrySdk autoConfiguredSdk) {
3333

3434
if (config.getBoolean("otel.jmx.enabled", true)) {
3535
JmxMetricInsight service =
36-
JmxMetricInsight.createService(GlobalOpenTelemetry.get(), beanDiscoveryDelay(config));
36+
JmxMetricInsight.createService(
37+
GlobalOpenTelemetry.get(), beanDiscoveryDelay(config).toMillis());
3738
MetricConfiguration conf = buildMetricConfiguration(config);
3839
service.start(conf);
3940
}
4041
}
4142

42-
private static long beanDiscoveryDelay(ConfigProperties configProperties) {
43-
Long discoveryDelay = configProperties.getLong("otel.jmx.discovery.delay");
43+
private static Duration beanDiscoveryDelay(ConfigProperties configProperties) {
44+
Duration discoveryDelay = configProperties.getDuration("otel.jmx.discovery.delay");
4445
if (discoveryDelay != null) {
4546
return discoveryDelay;
4647
}
4748

4849
// If discovery delay has not been configured, have a peek at the metric export interval.
4950
// It makes sense for both of these values to be similar.
50-
return configProperties
51-
.getDuration("otel.metric.export.interval", Duration.ofMinutes(1))
52-
.toMillis();
51+
return configProperties.getDuration("otel.metric.export.interval", Duration.ofMinutes(1));
5352
}
5453

5554
private static String resourceFor(String platform) {

instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/BeanFinder.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,18 @@ class BeanFinder {
3939
void discoverBeans(MetricConfiguration conf) {
4040
this.conf = conf;
4141

42-
if (!conf.isEmpty()) {
43-
// Issue 9336: Corner case: PlatformMBeanServer will remain unitialized until a direct
44-
// reference to it is made. This call makes sure that the PlatformMBeanServer will be in
45-
// the set of MBeanServers reported by MBeanServerFactory.
46-
ManagementFactory.getPlatformMBeanServer();
47-
}
42+
exec.schedule(
43+
() -> {
44+
// Issue 9336: Corner case: PlatformMBeanServer will remain unitialized until a direct
45+
// reference to it is made. This call makes sure that the PlatformMBeanServer will be in
46+
// the set of MBeanServers reported by MBeanServerFactory.
47+
// Issue 11143: This call initializes java.util.logging.LogManager. We should not call it
48+
// before application has had a chance to configure custom log manager. This is needed for
49+
// wildfly.
50+
ManagementFactory.getPlatformMBeanServer();
51+
},
52+
discoveryDelay,
53+
TimeUnit.MILLISECONDS);
4854

4955
exec.schedule(
5056
new Runnable() {

0 commit comments

Comments
 (0)