From 5daa37e782069aa767c3fc7ba3baf916b93ac2c1 Mon Sep 17 00:00:00 2001 From: jason plumb <75337021+breedx-splk@users.noreply.github.com> Date: Sat, 14 Dec 2024 01:55:58 -0800 Subject: [PATCH] Rename "db.client.connections.usage" to "db.client.connection.count" (#12886) --- .../api/incubator/semconv/db/DbConnectionPoolMetrics.java | 5 ++++- .../alibabadruid/AbstractDruidInstrumentationTest.java | 5 ++++- .../apachedbcp/AbstractApacheDbcpInstrumentationTest.java | 5 ++++- .../c3p0/AbstractC3p0InstrumentationTest.java | 7 ++++++- .../hikaricp/AbstractHikariInstrumentationTest.java | 5 ++++- .../oracleucp/AbstractOracleUcpInstrumentationTest.java | 5 ++++- .../tomcat/jdbc/TomcatJdbcInstrumentationTest.java | 3 ++- .../viburdbcp/AbstractViburInstrumentationTest.java | 5 ++++- .../junit/db/DbConnectionPoolMetricsAssertions.java | 3 ++- 9 files changed, 34 insertions(+), 9 deletions(-) diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbConnectionPoolMetrics.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbConnectionPoolMetrics.java index be70b9562edc..96eb6246f702 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbConnectionPoolMetrics.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbConnectionPoolMetrics.java @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.api.incubator.semconv.db; import static io.opentelemetry.api.common.AttributeKey.stringKey; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.common.AttributeKey; @@ -56,8 +57,10 @@ public static DbConnectionPoolMetrics create( } public ObservableLongMeasurement connections() { + String metricName = + emitStableDatabaseSemconv() ? "db.client.connection.count" : "db.client.connections.usage"; return meter - .upDownCounterBuilder("db.client.connections.usage") + .upDownCounterBuilder(metricName) .setUnit("{connections}") .setDescription( "The number of connections that are currently in state described by the state attribute.") diff --git a/instrumentation/alibaba-druid-1.0/testing/src/main/java/io/opentelemetry/instrumentation/alibabadruid/AbstractDruidInstrumentationTest.java b/instrumentation/alibaba-druid-1.0/testing/src/main/java/io/opentelemetry/instrumentation/alibabadruid/AbstractDruidInstrumentationTest.java index 947a7aa095f2..b57a473ef3a3 100644 --- a/instrumentation/alibaba-druid-1.0/testing/src/main/java/io/opentelemetry/instrumentation/alibabadruid/AbstractDruidInstrumentationTest.java +++ b/instrumentation/alibaba-druid-1.0/testing/src/main/java/io/opentelemetry/instrumentation/alibabadruid/AbstractDruidInstrumentationTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.alibabadruid; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static org.assertj.core.api.Assertions.assertThat; import com.alibaba.druid.pool.DruidDataSource; @@ -73,7 +74,9 @@ void shouldReportMetrics() throws Exception { Set metricNames = new HashSet<>( Arrays.asList( - "db.client.connections.usage", + emitStableDatabaseSemconv() + ? "db.client.connection.count" + : "db.client.connections.usage", "db.client.connections.idle.min", "db.client.connections.idle.max", "db.client.connections.max", diff --git a/instrumentation/apache-dbcp-2.0/testing/src/main/java/io/opentelemetry/instrumentation/apachedbcp/AbstractApacheDbcpInstrumentationTest.java b/instrumentation/apache-dbcp-2.0/testing/src/main/java/io/opentelemetry/instrumentation/apachedbcp/AbstractApacheDbcpInstrumentationTest.java index bf637e7b6401..e01dcc23eff6 100644 --- a/instrumentation/apache-dbcp-2.0/testing/src/main/java/io/opentelemetry/instrumentation/apachedbcp/AbstractApacheDbcpInstrumentationTest.java +++ b/instrumentation/apache-dbcp-2.0/testing/src/main/java/io/opentelemetry/instrumentation/apachedbcp/AbstractApacheDbcpInstrumentationTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.apachedbcp; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; @@ -75,7 +76,9 @@ void shouldReportMetrics() throws Exception { Set metricNames = new HashSet<>( Arrays.asList( - "db.client.connections.usage", + emitStableDatabaseSemconv() + ? "db.client.connection.count" + : "db.client.connections.usage", "db.client.connections.idle.min", "db.client.connections.idle.max", "db.client.connections.max")); diff --git a/instrumentation/c3p0-0.9/testing/src/main/java/io/opentelemetry/instrumentation/c3p0/AbstractC3p0InstrumentationTest.java b/instrumentation/c3p0-0.9/testing/src/main/java/io/opentelemetry/instrumentation/c3p0/AbstractC3p0InstrumentationTest.java index bdee186cae54..75d6331a42a8 100644 --- a/instrumentation/c3p0-0.9/testing/src/main/java/io/opentelemetry/instrumentation/c3p0/AbstractC3p0InstrumentationTest.java +++ b/instrumentation/c3p0-0.9/testing/src/main/java/io/opentelemetry/instrumentation/c3p0/AbstractC3p0InstrumentationTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.c3p0; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static org.assertj.core.api.Assertions.assertThat; import com.mchange.v2.c3p0.ComboPooledDataSource; @@ -66,7 +67,11 @@ void shouldReportMetrics() throws Exception { // then Set metricNames = new HashSet<>( - Arrays.asList("db.client.connections.usage", "db.client.connections.pending_requests")); + Arrays.asList( + emitStableDatabaseSemconv() + ? "db.client.connection.count" + : "db.client.connections.usage", + "db.client.connections.pending_requests")); assertThat(testing().metrics()) .filteredOn( metricData -> diff --git a/instrumentation/hikaricp-3.0/testing/src/main/java/io/opentelemetry/instrumentation/hikaricp/AbstractHikariInstrumentationTest.java b/instrumentation/hikaricp-3.0/testing/src/main/java/io/opentelemetry/instrumentation/hikaricp/AbstractHikariInstrumentationTest.java index d6d93e3604a2..82d14f11f6f8 100644 --- a/instrumentation/hikaricp-3.0/testing/src/main/java/io/opentelemetry/instrumentation/hikaricp/AbstractHikariInstrumentationTest.java +++ b/instrumentation/hikaricp-3.0/testing/src/main/java/io/opentelemetry/instrumentation/hikaricp/AbstractHikariInstrumentationTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.hikaricp; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchException; import static org.mockito.ArgumentMatchers.anyLong; @@ -81,7 +82,9 @@ void shouldReportMetrics() throws SQLException, InterruptedException { testing() .waitAndAssertMetrics( "io.opentelemetry.hikaricp-3.0", - "db.client.connections.usage", + emitStableDatabaseSemconv() + ? "db.client.connection.count" + : "db.client.connections.usage", AbstractIterableAssert::isEmpty); testing() .waitAndAssertMetrics( diff --git a/instrumentation/oracle-ucp-11.2/testing/src/main/java/io/opentelemetry/instrumentation/oracleucp/AbstractOracleUcpInstrumentationTest.java b/instrumentation/oracle-ucp-11.2/testing/src/main/java/io/opentelemetry/instrumentation/oracleucp/AbstractOracleUcpInstrumentationTest.java index 548c8eb17ecd..507b301421a6 100644 --- a/instrumentation/oracle-ucp-11.2/testing/src/main/java/io/opentelemetry/instrumentation/oracleucp/AbstractOracleUcpInstrumentationTest.java +++ b/instrumentation/oracle-ucp-11.2/testing/src/main/java/io/opentelemetry/instrumentation/oracleucp/AbstractOracleUcpInstrumentationTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.oracleucp; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; @@ -117,7 +118,9 @@ void shouldReportMetrics(boolean setExplicitPoolName) throws Exception { Set metricNames = new HashSet<>( Arrays.asList( - "db.client.connections.usage", + emitStableDatabaseSemconv() + ? "db.client.connection.count" + : "db.client.connections.usage", "db.client.connections.max", "db.client.connections.pending_requests")); assertThat(testing().metrics()) diff --git a/instrumentation/tomcat/tomcat-jdbc/src/test/java/io/opentelemetry/javaagent/instrumentation/tomcat/jdbc/TomcatJdbcInstrumentationTest.java b/instrumentation/tomcat/tomcat-jdbc/src/test/java/io/opentelemetry/javaagent/instrumentation/tomcat/jdbc/TomcatJdbcInstrumentationTest.java index 9c95a1c1d21b..b8e90c6f6652 100644 --- a/instrumentation/tomcat/tomcat-jdbc/src/test/java/io/opentelemetry/javaagent/instrumentation/tomcat/jdbc/TomcatJdbcInstrumentationTest.java +++ b/instrumentation/tomcat/tomcat-jdbc/src/test/java/io/opentelemetry/javaagent/instrumentation/tomcat/jdbc/TomcatJdbcInstrumentationTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.jdbc; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @@ -77,7 +78,7 @@ private static void assertConnectionPoolMetrics(String poolName) { private static void assertNoConnectionPoolMetrics() { testing.waitAndAssertMetrics( "io.opentelemetry.tomcat-jdbc", - "db.client.connections.usage", + emitStableDatabaseSemconv() ? "db.client.connection.count" : "db.client.connections.usage", AbstractIterableAssert::isEmpty); testing.waitAndAssertMetrics( "io.opentelemetry.tomcat-jdbc", diff --git a/instrumentation/vibur-dbcp-11.0/testing/src/main/java/io/opentelemetry/instrumentation/viburdbcp/AbstractViburInstrumentationTest.java b/instrumentation/vibur-dbcp-11.0/testing/src/main/java/io/opentelemetry/instrumentation/viburdbcp/AbstractViburInstrumentationTest.java index dc9020e3af5e..21dfe26f4263 100644 --- a/instrumentation/vibur-dbcp-11.0/testing/src/main/java/io/opentelemetry/instrumentation/viburdbcp/AbstractViburInstrumentationTest.java +++ b/instrumentation/vibur-dbcp-11.0/testing/src/main/java/io/opentelemetry/instrumentation/viburdbcp/AbstractViburInstrumentationTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.viburdbcp; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static org.mockito.Mockito.when; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; @@ -72,9 +73,11 @@ void shouldReportMetrics() throws SQLException, InterruptedException { Thread.sleep(100); // then + String countMetricName = + emitStableDatabaseSemconv() ? "db.client.connection.count" : "db.client.connections.usage"; testing() .waitAndAssertMetrics( - INSTRUMENTATION_NAME, "db.client.connections.usage", AbstractIterableAssert::isEmpty); + INSTRUMENTATION_NAME, countMetricName, AbstractIterableAssert::isEmpty); testing() .waitAndAssertMetrics( INSTRUMENTATION_NAME, "db.client.connections.max", AbstractIterableAssert::isEmpty); diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/db/DbConnectionPoolMetricsAssertions.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/db/DbConnectionPoolMetricsAssertions.java index 1d1dfc9d504f..4ed89c7061fc 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/db/DbConnectionPoolMetricsAssertions.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/db/DbConnectionPoolMetricsAssertions.java @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.testing.junit.db; import static io.opentelemetry.api.common.AttributeKey.stringKey; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; @@ -126,7 +127,7 @@ public void assertConnectionPoolEmitsMetrics() { private void verifyConnectionUsage() { testing.waitAndAssertMetrics( instrumentationName, - "db.client.connections.usage", + emitStableDatabaseSemconv() ? "db.client.connection.count" : "db.client.connections.usage", metrics -> metrics.anySatisfy(this::verifyUsageMetric)); }