Small daemon threads implementation clean up
MODIFY
instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/Threads.java
instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/Threads.java
package io.opentelemetry.instrumentation.runtimemetrics;
import io.opentelemetry.api.OpenTelemetry;
+import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.Meter;
import java.lang.management.ManagementFactory;
@@ -32,7 +33,7 @@ public final class Threads {
// Visible for testing
static final Threads INSTANCE = new Threads();
- static final String DAEMON_KEY = "daemon";
+ static final AttributeKey<Boolean> DAEMON = AttributeKey.booleanKey("daemon");
/** Register observers for java runtime class metrics. */
public static void registerObservers(OpenTelemetry openTelemetry) {
@@ -51,10 +52,10 @@ public final class Threads {
observableMeasurement -> {
observableMeasurement.record(
threadBean.getDaemonThreadCount(),
- Attributes.builder().put(DAEMON_KEY, true).build());
+ Attributes.builder().put(DAEMON, true).build());
observableMeasurement.record(
threadBean.getThreadCount() - threadBean.getDaemonThreadCount(),
- Attributes.builder().put(DAEMON_KEY, false).build());
+ Attributes.builder().put(DAEMON, false).build());
});
}

MODIFY
instrumentation/runtime-metrics/library/src/test/java/io/opentelemetry/instrumentation/runtimemetrics/ThreadsTest.java
instrumentation/runtime-metrics/library/src/test/java/io/opentelemetry/instrumentation/runtimemetrics/ThreadsTest.java
package io.opentelemetry.instrumentation.runtimemetrics;
-import static io.opentelemetry.instrumentation.runtimemetrics.Threads.DAEMON_KEY;
+import static io.opentelemetry.instrumentation.runtimemetrics.Threads.DAEMON;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
+import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static org.mockito.Mockito.when;
-import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
import java.lang.management.ThreadMXBean;
@@ -50,16 +50,11 @@ class ThreadsTest {
point ->
point
.hasValue(2)
- .hasAttributes(
- Attributes.builder()
- .put(DAEMON_KEY, true)
- .build()),
+ .hasAttributesSatisfying(equalTo(DAEMON, true)),
point ->
point
.hasValue(5)
- .hasAttributes(
- Attributes.builder()
- .put(DAEMON_KEY, false)
- .build())))));
+ .hasAttributesSatisfying(
+ equalTo(DAEMON, false))))));
}
}

Small daemon threads implementation clean up (#6740)