diff --git a/instrumentation/runtime-telemetry/runtime-telemetry-java8/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/java8/Threads.java b/instrumentation/runtime-telemetry/runtime-telemetry-java8/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/java8/Threads.java index 245ada085a45..bc9ea0f7cc53 100644 --- a/instrumentation/runtime-telemetry/runtime-telemetry-java8/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/java8/Threads.java +++ b/instrumentation/runtime-telemetry/runtime-telemetry-java8/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/java8/Threads.java @@ -45,6 +45,20 @@ * process.runtime.jvm.threads.count{daemon=true} 2 * process.runtime.jvm.threads.count{daemon=false} 5 * + * + *

In case you enable the preview of stable JVM semantic conventions (e.g. by setting the {@code + * otel.semconv-stability.opt-in} system property to {@code jvm}), the metrics being exported will + * follow the + * most recent JVM semantic conventions. This is how the example above looks when stable JVM + * semconv is enabled: + * + *

+ *   jvm.thread.count{jvm.thread.daemon=true,jvm.thread.state="waiting"} 1
+ *   jvm.thread.count{jvm.thread.daemon=true,jvm.thread.state="runnable"} 2
+ *   jvm.thread.count{jvm.thread.daemon=false,jvm.thread.state="waiting"} 2
+ *   jvm.thread.count{jvm.thread.daemon=false,jvm.thread.state="runnable"} 3
+ * 
*/ public final class Threads { @@ -73,11 +87,11 @@ List registerObservers(OpenTelemetry openTelemetry, ThreadMXBean .setUnit("{thread}") .buildWithCallback( observableMeasurement -> { + int daemonThreadCount = threadBean.getDaemonThreadCount(); observableMeasurement.record( - threadBean.getDaemonThreadCount(), - Attributes.builder().put(DAEMON, true).build()); + daemonThreadCount, Attributes.builder().put(DAEMON, true).build()); observableMeasurement.record( - threadBean.getThreadCount() - threadBean.getDaemonThreadCount(), + threadBean.getThreadCount() - daemonThreadCount, Attributes.builder().put(DAEMON, false).build()); })); } @@ -117,11 +131,11 @@ private static boolean isJava9OrNewer() { private static Consumer java8Callback(ThreadMXBean threadBean) { return measurement -> { + int daemonThreadCount = threadBean.getDaemonThreadCount(); measurement.record( - threadBean.getDaemonThreadCount(), - Attributes.builder().put(JVM_THREAD_DAEMON, true).build()); + daemonThreadCount, Attributes.builder().put(JVM_THREAD_DAEMON, true).build()); measurement.record( - threadBean.getThreadCount() - threadBean.getDaemonThreadCount(), + threadBean.getThreadCount() - daemonThreadCount, Attributes.builder().put(JVM_THREAD_DAEMON, false).build()); }; }