Skip to content

Commit

Permalink
Rename "db.client.connections.usage" to "db.client.connection.count" (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
breedx-splk authored Dec 14, 2024
1 parent 4a17266 commit 5daa37e
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,7 +74,9 @@ void shouldReportMetrics() throws Exception {
Set<String> 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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,7 +76,9 @@ void shouldReportMetrics() throws Exception {
Set<String> 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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -66,7 +67,11 @@ void shouldReportMetrics() throws Exception {
// then
Set<String> 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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -117,7 +118,9 @@ void shouldReportMetrics(boolean setExplicitPoolName) throws Exception {
Set<String> 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}

Expand Down

0 comments on commit 5daa37e

Please sign in to comment.