From ce73ae1468b614c943b46d003aee111bb51ec82e Mon Sep 17 00:00:00 2001 From: Peter Findeisen Date: Thu, 31 Aug 2023 14:19:33 -0700 Subject: [PATCH] Issue 9336: Auto-instrumentation with JMX not working without a trigger Forcing initialization of PlatformMBeanServer. --- .../instrumentation/jmx/engine/BeanFinder.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/BeanFinder.java b/instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/BeanFinder.java index fa44f293cc4e..8b0fd636bed3 100644 --- a/instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/BeanFinder.java +++ b/instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/BeanFinder.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.jmx.engine; +import java.lang.management.ManagementFactory; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -38,6 +39,13 @@ class BeanFinder { void discoverBeans(MetricConfiguration conf) { this.conf = conf; + if (!conf.isEmpty()) { + // Issue 9336: Corner case: PlatformMBeanServer will remain unitialized until a direct + // reference to it is made. This call makes sure that the PlatformMBeanServer will be in + // the set of MBeanServers reported by MBeanServerFactory. + ManagementFactory.getPlatformMBeanServer(); + } + exec.schedule( new Runnable() { @Override