Fix metric units
Follow-up to
MODIFY
docs/contributing/using-instrumenter-api.md
docs/contributing/using-instrumenter-api.md
@@ -349,7 +349,7 @@ class MyOperationMetrics implements OperationListener {
MyOperationMetrics(Meter meter) {
activeRequests = meter
.upDownCounterBuilder("mylib.active_requests")
- .setUnit("requests")
+ .setUnit("{requests}")
.build();
}

MODIFY
instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java
instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java
@@ -57,7 +57,7 @@ public final class HttpServerMetrics implements OperationListener {
activeRequests =
meter
.upDownCounterBuilder("http.server.active_requests")
- .setUnit("requests")
+ .setUnit("{requests}")
.setDescription("The number of concurrent HTTP requests that are currently in-flight")
.build();

MODIFY
instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/metrics/db/DbConnectionPoolMetrics.java
instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/metrics/db/DbConnectionPoolMetrics.java
@@ -58,7 +58,7 @@ public final class DbConnectionPoolMetrics {
public ObservableLongMeasurement connections() {
return meter
.upDownCounterBuilder("db.client.connections.usage")
- .setUnit("connections")
+ .setUnit("{connections}")
.setDescription(
"The number of connections that are currently in state described by the state attribute.")
.buildObserver();
@@ -67,7 +67,7 @@ public final class DbConnectionPoolMetrics {
public ObservableLongMeasurement minIdleConnections() {
return meter
.upDownCounterBuilder("db.client.connections.idle.min")
- .setUnit("connections")
+ .setUnit("{connections}")
.setDescription("The minimum number of idle open connections allowed.")
.buildObserver();
}
@@ -75,7 +75,7 @@ public final class DbConnectionPoolMetrics {
public ObservableLongMeasurement maxIdleConnections() {
return meter
.upDownCounterBuilder("db.client.connections.idle.max")
- .setUnit("connections")
+ .setUnit("{connections}")
.setDescription("The maximum number of idle open connections allowed.")
.buildObserver();
}
@@ -83,7 +83,7 @@ public final class DbConnectionPoolMetrics {
public ObservableLongMeasurement maxConnections() {
return meter
.upDownCounterBuilder("db.client.connections.max")
- .setUnit("connections")
+ .setUnit("{connections}")
.setDescription("The maximum number of open connections allowed.")
.buildObserver();
}
@@ -91,7 +91,7 @@ public final class DbConnectionPoolMetrics {
public ObservableLongMeasurement pendingRequestsForConnection() {
return meter
.upDownCounterBuilder("db.client.connections.pending_requests")
- .setUnit("requests")
+ .setUnit("{requests}")
.setDescription(
"The number of pending requests for an open connection, cumulative for the entire pool.")
.buildObserver();

MODIFY
instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java
instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java
@@ -79,7 +79,7 @@ class HttpServerMetricsTest {
.hasName("http.server.active_requests")
.hasDescription(
"The number of concurrent HTTP requests that are currently in-flight")
- .hasUnit("requests")
+ .hasUnit("{requests}")
.hasLongSumSatisfying(
sum ->
sum.hasPointsSatisfying(

MODIFY
instrumentation/micrometer/micrometer-1.5/library/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/OpenTelemetryLongTaskTimer.java
instrumentation/micrometer/micrometer-1.5/library/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/OpenTelemetryLongTaskTimer.java
@@ -44,7 +44,7 @@ final class OpenTelemetryLongTaskTimer extends DefaultLongTaskTimer implements R
otelMeter
.upDownCounterBuilder(name + ".active")
.setDescription(Bridging.description(id))
- .setUnit("tasks")
+ .setUnit("{tasks}")
.buildWithCallback(
new LongMeasurementRecorder<>(this, DefaultLongTaskTimer::activeTasks, attributes));
this.observableDuration =

MODIFY
instrumentation/micrometer/micrometer-1.5/testing/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/AbstractLongTaskTimerHistogramTest.java
instrumentation/micrometer/micrometer-1.5/testing/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/AbstractLongTaskTimerHistogramTest.java
@@ -52,7 +52,7 @@ public abstract class AbstractLongTaskTimerHistogramTest {
metric ->
assertThat(metric)
.hasDescription("This is a test timer")
- .hasUnit("tasks")
+ .hasUnit("{tasks}")
.hasLongSumSatisfying(
sum ->
sum.isNotMonotonic()
@@ -118,7 +118,7 @@ public abstract class AbstractLongTaskTimerHistogramTest {
metric ->
assertThat(metric)
.hasDescription("This is a test timer")
- .hasUnit("tasks")
+ .hasUnit("{tasks}")
.hasLongSumSatisfying(
sum ->
sum.isNotMonotonic()

MODIFY
instrumentation/micrometer/micrometer-1.5/testing/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/AbstractLongTaskTimerSecondsTest.java
instrumentation/micrometer/micrometer-1.5/testing/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/AbstractLongTaskTimerSecondsTest.java
@@ -42,7 +42,7 @@ public abstract class AbstractLongTaskTimerSecondsTest {
metric ->
assertThat(metric)
.hasDescription("This is a test long task timer")
- .hasUnit("tasks")
+ .hasUnit("{tasks}")
.hasLongSumSatisfying(
sum ->
sum.isNotMonotonic()

MODIFY
instrumentation/micrometer/micrometer-1.5/testing/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/AbstractLongTaskTimerTest.java
instrumentation/micrometer/micrometer-1.5/testing/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/AbstractLongTaskTimerTest.java
@@ -42,7 +42,7 @@ public abstract class AbstractLongTaskTimerTest {
metric ->
assertThat(metric)
.hasDescription("This is a test long task timer")
- .hasUnit("tasks")
+ .hasUnit("{tasks}")
.hasLongSumSatisfying(
sum ->
sum.isNotMonotonic()

MODIFY
instrumentation/micrometer/micrometer-1.5/testing/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/AbstractPrometheusModeTest.java
instrumentation/micrometer/micrometer-1.5/testing/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/AbstractPrometheusModeTest.java
@@ -220,7 +220,7 @@ public abstract class AbstractPrometheusModeTest {
metric ->
assertThat(metric)
.hasDescription("This is a test long task timer")
- .hasUnit("tasks")
+ .hasUnit("{tasks}")
.hasLongSumSatisfying(
sum ->
sum.isNotMonotonic()

MODIFY
instrumentation/oshi/library/src/main/java/io/opentelemetry/instrumentation/oshi/SystemMetrics.java
instrumentation/oshi/library/src/main/java/io/opentelemetry/instrumentation/oshi/SystemMetrics.java
@@ -76,7 +76,7 @@ public class SystemMetrics {
meter
.counterBuilder("system.network.packets")
.setDescription("System network packets")
- .setUnit("packets")
+ .setUnit("{packets}")
.buildWithCallback(
r -> {
for (NetworkIF networkIf : hal.getNetworkIFs()) {
@@ -92,7 +92,7 @@ public class SystemMetrics {
meter
.counterBuilder("system.network.errors")
.setDescription("System network errors")
- .setUnit("errors")
+ .setUnit("{errors}")
.buildWithCallback(
r -> {
for (NetworkIF networkIf : hal.getNetworkIFs()) {
@@ -123,7 +123,7 @@ public class SystemMetrics {
meter
.counterBuilder("system.disk.operations")
.setDescription("System disk operations")
- .setUnit("operations")
+ .setUnit("{operations}")
.buildWithCallback(
r -> {
for (HWDiskStore diskStore : hal.getDiskStores()) {

MODIFY
instrumentation/oshi/testing/src/main/java/io/opentelemetry/instrumentation/oshi/AbstractSystemMetricsTest.java
instrumentation/oshi/testing/src/main/java/io/opentelemetry/instrumentation/oshi/AbstractSystemMetricsTest.java
@@ -66,7 +66,7 @@ public abstract class AbstractSystemMetricsTest {
metrics ->
metrics.anySatisfy(
metric ->
- assertThat(metric).hasUnit("packets").hasLongSumSatisfying(sum -> {})));
+ assertThat(metric).hasUnit("{packets}").hasLongSumSatisfying(sum -> {})));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.oshi",
@@ -74,7 +74,7 @@ public abstract class AbstractSystemMetricsTest {
metrics ->
metrics.anySatisfy(
metric ->
- assertThat(metric).hasUnit("errors").hasLongSumSatisfying(sum -> {})));
+ assertThat(metric).hasUnit("{errors}").hasLongSumSatisfying(sum -> {})));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.oshi",
@@ -89,6 +89,8 @@ public abstract class AbstractSystemMetricsTest {
metrics ->
metrics.anySatisfy(
metric ->
- assertThat(metric).hasUnit("operations").hasLongSumSatisfying(sum -> {})));
+ assertThat(metric)
+ .hasUnit("{operations}")
+ .hasLongSumSatisfying(sum -> {})));
}
}

MODIFY
instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/BufferPools.java
instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/BufferPools.java
@@ -59,7 +59,7 @@ public final class BufferPools {
meter
.upDownCounterBuilder("process.runtime.jvm.buffer.count")
.setDescription("The number of buffers in the pool")
- .setUnit("buffers")
+ .setUnit("{buffers}")
.buildWithCallback(callback(bufferBeans, BufferPoolMXBean::getCount));
}

MODIFY
testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/db/DbConnectionPoolMetricsAssertions.java
testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/db/DbConnectionPoolMetricsAssertions.java
@@ -132,7 +132,7 @@ public final class DbConnectionPoolMetricsAssertions {
private void verifyUsageMetric(MetricData metric) {
assertThat(metric)
- .hasUnit("connections")
+ .hasUnit("{connections}")
.hasDescription(
"The number of connections that are currently in state described by the state attribute.")
.hasLongSumSatisfying(
@@ -156,7 +156,7 @@ public final class DbConnectionPoolMetricsAssertions {
private void verifyMaxConnectionsMetric(MetricData metric) {
assertThat(metric)
- .hasUnit("connections")
+ .hasUnit("{connections}")
.hasDescription("The maximum number of open connections allowed.")
.hasLongSumSatisfying(this::verifyPoolName);
}
@@ -170,7 +170,7 @@ public final class DbConnectionPoolMetricsAssertions {
private void verifyMinIdleConnectionsMetric(MetricData metric) {
assertThat(metric)
- .hasUnit("connections")
+ .hasUnit("{connections}")
.hasDescription("The minimum number of idle open connections allowed.")
.hasLongSumSatisfying(this::verifyPoolName);
}
@@ -184,7 +184,7 @@ public final class DbConnectionPoolMetricsAssertions {
private void verifyMaxIdleConnectionsMetric(MetricData metric) {
assertThat(metric)
- .hasUnit("connections")
+ .hasUnit("{connections}")
.hasDescription("The maximum number of idle open connections allowed.")
.hasLongSumSatisfying(this::verifyPoolName);
}
@@ -203,7 +203,7 @@ public final class DbConnectionPoolMetricsAssertions {
private void verifyPendingRequestsMetric(MetricData metric) {
assertThat(metric)
- .hasUnit("requests")
+ .hasUnit("{requests}")
.hasDescription(
"The number of pending requests for an open connection, cumulative for the entire pool.")
.hasLongSumSatisfying(this::verifyPoolName);
@@ -218,7 +218,7 @@ public final class DbConnectionPoolMetricsAssertions {
private void verifyTimeoutsMetric(MetricData metric) {
assertThat(metric)
- .hasUnit("timeouts")
+ .hasUnit("{timeouts}")
.hasDescription(
"The number of connection timeouts that have occurred trying to obtain a connection from the pool.")
.hasLongSumSatisfying(

Fix metric units (#6931)

Follow-up to #6930