diff --git a/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/java/CassandraClientTest.java b/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/java/CassandraClientTest.java index 15b8f19c06d7..3373c0e76277 100644 --- a/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/java/CassandraClientTest.java +++ b/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/java/CassandraClientTest.java @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS; import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_PORT; @@ -22,7 +23,6 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; -import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; @@ -108,9 +108,7 @@ void syncTest(Parameter parameter) { equalTo(NETWORK_PEER_ADDRESS, cassandraIp), equalTo(NETWORK_PEER_PORT, cassandraPort), equalTo(DB_SYSTEM, "cassandra"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), - "USE " + parameter.keyspace))), + equalTo(maybeStable(DB_STATEMENT), "USE " + parameter.keyspace))), trace -> trace.hasSpansSatisfyingExactly( span -> @@ -124,18 +122,10 @@ void syncTest(Parameter parameter) { equalTo(NETWORK_PEER_ADDRESS, cassandraIp), equalTo(NETWORK_PEER_PORT, cassandraPort), equalTo(DB_SYSTEM, "cassandra"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_NAME), - parameter.keyspace), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), - parameter.expectedStatement), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_OPERATION), - parameter.operation), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_CASSANDRA_TABLE), - parameter.table)))); + equalTo(maybeStable(DB_NAME), parameter.keyspace), + equalTo(maybeStable(DB_STATEMENT), parameter.expectedStatement), + equalTo(maybeStable(DB_OPERATION), parameter.operation), + equalTo(maybeStable(DB_CASSANDRA_TABLE), parameter.table)))); } else { testing.waitAndAssertTraces( trace -> @@ -151,15 +141,9 @@ void syncTest(Parameter parameter) { equalTo(NETWORK_PEER_ADDRESS, cassandraIp), equalTo(NETWORK_PEER_PORT, cassandraPort), equalTo(DB_SYSTEM, "cassandra"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), - parameter.expectedStatement), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_OPERATION), - parameter.operation), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_CASSANDRA_TABLE), - parameter.table)))); + equalTo(maybeStable(DB_STATEMENT), parameter.expectedStatement), + equalTo(maybeStable(DB_OPERATION), parameter.operation), + equalTo(maybeStable(DB_CASSANDRA_TABLE), parameter.table)))); } session.close(); @@ -196,9 +180,7 @@ void asyncTest(Parameter parameter) { equalTo(NETWORK_PEER_ADDRESS, cassandraIp), equalTo(NETWORK_PEER_PORT, cassandraPort), equalTo(DB_SYSTEM, "cassandra"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), - "USE " + parameter.keyspace))), + equalTo(maybeStable(DB_STATEMENT), "USE " + parameter.keyspace))), trace -> trace.hasSpansSatisfyingExactly( span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), @@ -213,18 +195,10 @@ void asyncTest(Parameter parameter) { equalTo(NETWORK_PEER_ADDRESS, cassandraIp), equalTo(NETWORK_PEER_PORT, cassandraPort), equalTo(DB_SYSTEM, "cassandra"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_NAME), - parameter.keyspace), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), - parameter.expectedStatement), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_OPERATION), - parameter.operation), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_CASSANDRA_TABLE), - parameter.table)), + equalTo(maybeStable(DB_NAME), parameter.keyspace), + equalTo(maybeStable(DB_STATEMENT), parameter.expectedStatement), + equalTo(maybeStable(DB_OPERATION), parameter.operation), + equalTo(maybeStable(DB_CASSANDRA_TABLE), parameter.table)), span -> span.hasName("callbackListener") .hasKind(SpanKind.INTERNAL) @@ -245,15 +219,9 @@ void asyncTest(Parameter parameter) { equalTo(NETWORK_PEER_ADDRESS, cassandraIp), equalTo(NETWORK_PEER_PORT, cassandraPort), equalTo(DB_SYSTEM, "cassandra"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), - parameter.expectedStatement), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_OPERATION), - parameter.operation), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_CASSANDRA_TABLE), - parameter.table)), + equalTo(maybeStable(DB_STATEMENT), parameter.expectedStatement), + equalTo(maybeStable(DB_OPERATION), parameter.operation), + equalTo(maybeStable(DB_CASSANDRA_TABLE), parameter.table)), span -> span.hasName("callbackListener") .hasKind(SpanKind.INTERNAL) diff --git a/instrumentation/cassandra/cassandra-4-common/testing/src/main/java/io/opentelemetry/cassandra/v4/common/AbstractCassandraTest.java b/instrumentation/cassandra/cassandra-4-common/testing/src/main/java/io/opentelemetry/cassandra/v4/common/AbstractCassandraTest.java index 61caa713d17f..b49fb7da01ab 100644 --- a/instrumentation/cassandra/cassandra-4-common/testing/src/main/java/io/opentelemetry/cassandra/v4/common/AbstractCassandraTest.java +++ b/instrumentation/cassandra/cassandra-4-common/testing/src/main/java/io/opentelemetry/cassandra/v4/common/AbstractCassandraTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.cassandra.v4.common; +import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS; @@ -33,7 +34,6 @@ import com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; -import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; @@ -113,15 +113,9 @@ void syncTest(Parameter parameter) { equalTo(NETWORK_PEER_ADDRESS, cassandraIp), equalTo(NETWORK_PEER_PORT, cassandraPort), equalTo(DB_SYSTEM, "cassandra"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_NAME), - parameter.keyspace), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), - parameter.expectedStatement), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_OPERATION), - parameter.operation), + equalTo(maybeStable(DB_NAME), parameter.keyspace), + equalTo(maybeStable(DB_STATEMENT), parameter.expectedStatement), + equalTo(maybeStable(DB_OPERATION), parameter.operation), equalTo(DB_CASSANDRA_CONSISTENCY_LEVEL, "LOCAL_ONE"), equalTo(DB_CASSANDRA_COORDINATOR_DC, "datacenter1"), satisfies( @@ -132,9 +126,7 @@ void syncTest(Parameter parameter) { val -> val.isInstanceOf(Boolean.class)), equalTo(DB_CASSANDRA_PAGE_SIZE, 5000), equalTo(DB_CASSANDRA_SPECULATIVE_EXECUTION_COUNT, 0), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_CASSANDRA_TABLE), - parameter.table)))); + equalTo(maybeStable(DB_CASSANDRA_TABLE), parameter.table)))); session.close(); } @@ -175,15 +167,9 @@ void asyncTest(Parameter parameter) throws Exception { equalTo(NETWORK_PEER_ADDRESS, cassandraIp), equalTo(NETWORK_PEER_PORT, cassandraPort), equalTo(DB_SYSTEM, "cassandra"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_NAME), - parameter.keyspace), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), - parameter.expectedStatement), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_OPERATION), - parameter.operation), + equalTo(maybeStable(DB_NAME), parameter.keyspace), + equalTo(maybeStable(DB_STATEMENT), parameter.expectedStatement), + equalTo(maybeStable(DB_OPERATION), parameter.operation), equalTo(DB_CASSANDRA_CONSISTENCY_LEVEL, "LOCAL_ONE"), equalTo(DB_CASSANDRA_COORDINATOR_DC, "datacenter1"), satisfies( @@ -194,9 +180,7 @@ void asyncTest(Parameter parameter) throws Exception { val -> val.isInstanceOf(Boolean.class)), equalTo(DB_CASSANDRA_PAGE_SIZE, 5000), equalTo(DB_CASSANDRA_SPECULATIVE_EXECUTION_COUNT, 0), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_CASSANDRA_TABLE), - parameter.table)), + equalTo(maybeStable(DB_CASSANDRA_TABLE), parameter.table)), span -> span.hasName("child") .hasKind(SpanKind.INTERNAL) diff --git a/instrumentation/cassandra/cassandra-4.4/testing/src/main/java/io/opentelemetry/testing/cassandra/v4_4/AbstractCassandra44Test.java b/instrumentation/cassandra/cassandra-4.4/testing/src/main/java/io/opentelemetry/testing/cassandra/v4_4/AbstractCassandra44Test.java index 1e393b692abf..a5319f49df4e 100644 --- a/instrumentation/cassandra/cassandra-4.4/testing/src/main/java/io/opentelemetry/testing/cassandra/v4_4/AbstractCassandra44Test.java +++ b/instrumentation/cassandra/cassandra-4.4/testing/src/main/java/io/opentelemetry/testing/cassandra/v4_4/AbstractCassandra44Test.java @@ -5,6 +5,7 @@ package io.opentelemetry.testing.cassandra.v4_4; +import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS; @@ -29,7 +30,6 @@ import com.datastax.oss.driver.api.core.CqlSession; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.cassandra.v4.common.AbstractCassandraTest; -import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil; import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -73,15 +73,9 @@ void reactiveTest(Parameter parameter) { equalTo(NETWORK_PEER_ADDRESS, cassandraIp), equalTo(NETWORK_PEER_PORT, cassandraPort), equalTo(DB_SYSTEM, "cassandra"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_NAME), - parameter.keyspace), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), - parameter.expectedStatement), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_OPERATION), - parameter.operation), + equalTo(maybeStable(DB_NAME), parameter.keyspace), + equalTo(maybeStable(DB_STATEMENT), parameter.expectedStatement), + equalTo(maybeStable(DB_OPERATION), parameter.operation), equalTo(DB_CASSANDRA_CONSISTENCY_LEVEL, "LOCAL_ONE"), equalTo(DB_CASSANDRA_COORDINATOR_DC, "datacenter1"), satisfies( @@ -92,9 +86,7 @@ void reactiveTest(Parameter parameter) { val -> val.isInstanceOf(Boolean.class)), equalTo(DB_CASSANDRA_PAGE_SIZE, 5000), equalTo(DB_CASSANDRA_SPECULATIVE_EXECUTION_COUNT, 0), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_CASSANDRA_TABLE), - parameter.table)), + equalTo(maybeStable(DB_CASSANDRA_TABLE), parameter.table)), span -> span.hasName("child") .hasKind(SpanKind.INTERNAL) diff --git a/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseAsyncClientTest.java b/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseAsyncClientTest.java index 4962dca118fe..0c6116f2bace 100644 --- a/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseAsyncClientTest.java +++ b/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseAsyncClientTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.couchbase; +import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION; import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM; @@ -23,7 +24,6 @@ import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; -import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; import java.util.Collections; import java.util.concurrent.CompletableFuture; @@ -93,9 +93,7 @@ void hasBucket(BucketSettings bucketSettings) equalTo( DB_SYSTEM, DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_OPERATION), - "Cluster.openBucket")), + equalTo(maybeStable(DB_OPERATION), "Cluster.openBucket")), span -> assertCouchbaseSpan(span, "ClusterManager.hasBucket") .hasParent(trace.getSpan(0)))); @@ -136,9 +134,7 @@ void upsert(BucketSettings bucketSettings) equalTo( DB_SYSTEM, DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_OPERATION), - "Cluster.openBucket")), + equalTo(maybeStable(DB_OPERATION), "Cluster.openBucket")), span -> assertCouchbaseSpan(span, "Bucket.upsert", bucketSettings.name()) .hasParent(trace.getSpan(1)))); @@ -186,9 +182,7 @@ void upsertAndGet(BucketSettings bucketSettings) equalTo( DB_SYSTEM, DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_OPERATION), - "Cluster.openBucket")), + equalTo(maybeStable(DB_OPERATION), "Cluster.openBucket")), span -> assertCouchbaseSpan(span, "Bucket.upsert", bucketSettings.name()) .hasParent(trace.getSpan(1)), @@ -233,9 +227,7 @@ void query() throws ExecutionException, InterruptedException, TimeoutException { equalTo( DB_SYSTEM, DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_OPERATION), - "Cluster.openBucket")), + equalTo(maybeStable(DB_OPERATION), "Cluster.openBucket")), span -> assertCouchbaseSpan( span, diff --git a/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseClientTest.java b/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseClientTest.java index 28995e26ec93..2c1db076ce39 100644 --- a/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseClientTest.java +++ b/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseClientTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.couchbase; +import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION; import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM; @@ -24,7 +25,6 @@ import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; -import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; import java.util.Collections; import java.util.concurrent.atomic.AtomicReference; @@ -112,9 +112,7 @@ void upsertAndGet(BucketSettings bucketSettings) { equalTo( DB_SYSTEM, DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_OPERATION), - "Cluster.openBucket"))), + equalTo(maybeStable(DB_OPERATION), "Cluster.openBucket"))), trace -> trace.hasSpansSatisfyingExactly( span -> span.hasName("someTrace").hasKind(SpanKind.INTERNAL).hasNoParent(), @@ -150,9 +148,7 @@ void query() { equalTo( DB_SYSTEM, DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_OPERATION), - "Cluster.openBucket"))), + equalTo(maybeStable(DB_OPERATION), "Cluster.openBucket"))), trace -> trace.hasSpansSatisfyingExactly( span -> diff --git a/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseTest.java b/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseTest.java index 62a5164259ea..719f8d037d91 100644 --- a/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseTest.java +++ b/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.couchbase; +import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_NAME; @@ -23,7 +24,6 @@ import com.couchbase.mock.httpio.HttpServer; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.test.utils.PortUtils; -import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil; import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; @@ -127,15 +127,13 @@ protected SpanDataAssert assertCouchbaseSpan( List assertions = new ArrayList<>(); assertions.add(equalTo(DB_SYSTEM, DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE)); if (operation != null) { - assertions.add(equalTo(SemconvStabilityUtil.getAttributeKey(DB_OPERATION), operation)); + assertions.add(equalTo(maybeStable(DB_OPERATION), operation)); } if (bucketName != null) { - assertions.add(equalTo(SemconvStabilityUtil.getAttributeKey(DB_NAME), bucketName)); + assertions.add(equalTo(maybeStable(DB_NAME), bucketName)); } if (statement != null) { - assertions.add( - satisfies( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), s -> s.startsWith(statement))); + assertions.add(satisfies(maybeStable(DB_STATEMENT), s -> s.startsWith(statement))); } assertions.addAll(couchbaseAttributes()); diff --git a/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonAsyncClientTest.java b/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonAsyncClientTest.java index d73414841ca0..219884a0415f 100644 --- a/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonAsyncClientTest.java +++ b/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonAsyncClientTest.java @@ -7,6 +7,7 @@ import static io.opentelemetry.api.trace.SpanKind.CLIENT; import static io.opentelemetry.api.trace.SpanKind.INTERNAL; +import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil.orderByRootSpanKind; import static io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil.orderByRootSpanName; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; @@ -22,7 +23,6 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; -import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil; import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.net.InetAddress; @@ -125,9 +125,8 @@ void futureSet() throws ExecutionException, InterruptedException, TimeoutExcepti equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), "SET foo ?"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_OPERATION), "SET")))); + equalTo(maybeStable(DB_STATEMENT), "SET foo ?"), + equalTo(maybeStable(DB_OPERATION), "SET")))); } @Test @@ -159,9 +158,8 @@ void futureWhenComplete() throws ExecutionException, InterruptedException, Timeo equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), "SADD set1 ?"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_OPERATION), "SADD")) + equalTo(maybeStable(DB_STATEMENT), "SADD set1 ?"), + equalTo(maybeStable(DB_OPERATION), "SADD")) .hasParent(trace.getSpan(0)), span -> span.hasName("callback").hasKind(INTERNAL).hasParent(trace.getSpan(0)))); } @@ -234,9 +232,7 @@ void atomicBatchCommand() throws ExecutionException, InterruptedException, Timeo equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), - "MULTI;SET batch1 ?")) + equalTo(maybeStable(DB_STATEMENT), "MULTI;SET batch1 ?")) .hasParent(trace.getSpan(0)), span -> span.hasName("SET") @@ -246,9 +242,8 @@ void atomicBatchCommand() throws ExecutionException, InterruptedException, Timeo equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), "SET batch2 ?"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_OPERATION), "SET")) + equalTo(maybeStable(DB_STATEMENT), "SET batch2 ?"), + equalTo(maybeStable(DB_OPERATION), "SET")) .hasParent(trace.getSpan(0)), span -> span.hasName("EXEC") @@ -258,8 +253,8 @@ void atomicBatchCommand() throws ExecutionException, InterruptedException, Timeo equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), "EXEC"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_OPERATION), "EXEC")) + equalTo(maybeStable(DB_STATEMENT), "EXEC"), + equalTo(maybeStable(DB_OPERATION), "EXEC")) .hasParent(trace.getSpan(0)), span -> span.hasName("callback").hasKind(INTERNAL).hasParent(trace.getSpan(0)))); } diff --git a/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonClientTest.java b/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonClientTest.java index b0cf6e659bf7..81360d8edb1c 100644 --- a/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonClientTest.java +++ b/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonClientTest.java @@ -7,6 +7,7 @@ import static io.opentelemetry.api.trace.SpanKind.CLIENT; import static io.opentelemetry.api.trace.SpanKind.INTERNAL; +import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil.orderByRootSpanKind; import static io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil.orderByRootSpanName; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; @@ -22,7 +23,6 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; -import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil; import io.opentelemetry.sdk.testing.assertj.TraceAssert; import java.lang.reflect.InvocationTargetException; import java.net.InetAddress; @@ -128,9 +128,8 @@ void stringCommand() { equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), "SET foo ?"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_OPERATION), "SET"))), + equalTo(maybeStable(DB_STATEMENT), "SET foo ?"), + equalTo(maybeStable(DB_OPERATION), "SET"))), trace -> trace.hasSpansSatisfyingExactly( span -> @@ -141,8 +140,8 @@ void stringCommand() { equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), "GET foo"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_OPERATION), "GET")))); + equalTo(maybeStable(DB_STATEMENT), "GET foo"), + equalTo(maybeStable(DB_OPERATION), "GET")))); } @Test @@ -167,9 +166,7 @@ void batchCommand() equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), - "SET batch1 ?;SET batch2 ?")))); + equalTo(maybeStable(DB_STATEMENT), "SET batch1 ?;SET batch2 ?")))); } private static void invokeExecute(RBatch batch) @@ -209,9 +206,7 @@ void atomicBatchCommand() { equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), - "MULTI;SET batch1 ?")) + equalTo(maybeStable(DB_STATEMENT), "MULTI;SET batch1 ?")) .hasParent(trace.getSpan(0)), span -> span.hasName("SET") @@ -221,9 +216,8 @@ void atomicBatchCommand() { equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), "SET batch2 ?"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_OPERATION), "SET")) + equalTo(maybeStable(DB_STATEMENT), "SET batch2 ?"), + equalTo(maybeStable(DB_OPERATION), "SET")) .hasParent(trace.getSpan(0)), span -> span.hasName("EXEC") @@ -233,8 +227,8 @@ void atomicBatchCommand() { equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), "EXEC"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_OPERATION), "EXEC")) + equalTo(maybeStable(DB_STATEMENT), "EXEC"), + equalTo(maybeStable(DB_OPERATION), "EXEC")) .hasParent(trace.getSpan(0)))); } @@ -255,10 +249,8 @@ void listCommand() { equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), - "RPUSH list1 ?"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_OPERATION), "RPUSH")) + equalTo(maybeStable(DB_STATEMENT), "RPUSH list1 ?"), + equalTo(maybeStable(DB_OPERATION), "RPUSH")) .hasNoParent())); } @@ -283,9 +275,9 @@ void hashCommand() { equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), + maybeStable(DB_STATEMENT), String.format("EVAL %s 1 map1 ? ?", script)), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_OPERATION), "EVAL"))), + equalTo(maybeStable(DB_OPERATION), "EVAL"))), trace -> trace.hasSpansSatisfyingExactly( span -> @@ -296,10 +288,8 @@ void hashCommand() { equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), - "HGET map1 key1"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_OPERATION), "HGET")))); + equalTo(maybeStable(DB_STATEMENT), "HGET map1 key1"), + equalTo(maybeStable(DB_OPERATION), "HGET")))); } @Test @@ -319,9 +309,8 @@ void setCommand() { equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), "SADD set1 ?"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_OPERATION), "SADD")))); + equalTo(maybeStable(DB_STATEMENT), "SADD set1 ?"), + equalTo(maybeStable(DB_OPERATION), "SADD")))); } @Test @@ -348,10 +337,8 @@ void sortedSetCommand() equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), - "ZADD sort_set1 ? ? ? ? ? ?"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_OPERATION), "ZADD")))); + equalTo(maybeStable(DB_STATEMENT), "ZADD sort_set1 ? ? ? ? ? ?"), + equalTo(maybeStable(DB_OPERATION), "ZADD")))); } private static void invokeAddAll(RScoredSortedSet object, Map arg) @@ -376,10 +363,8 @@ void atomicLongCommand() { equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), - "INCR AtomicLong"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_OPERATION), "INCR")))); + equalTo(maybeStable(DB_STATEMENT), "INCR AtomicLong"), + equalTo(maybeStable(DB_OPERATION), "INCR")))); } @Test @@ -404,9 +389,9 @@ void lockCommand() { equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_OPERATION), "EVAL"), + equalTo(maybeStable(DB_OPERATION), "EVAL"), satisfies( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), + maybeStable(DB_STATEMENT), stringAssert -> stringAssert.startsWith("EVAL"))))); traceAsserts.add( trace -> @@ -419,9 +404,9 @@ void lockCommand() { equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_OPERATION), "EVAL"), + equalTo(maybeStable(DB_OPERATION), "EVAL"), satisfies( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), + maybeStable(DB_STATEMENT), stringAssert -> stringAssert.startsWith("EVAL"))))); if (lockHas3Traces()) { traceAsserts.add( @@ -435,9 +420,9 @@ void lockCommand() { equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), - equalTo(SemconvStabilityUtil.getAttributeKey(DB_OPERATION), "DEL"), + equalTo(maybeStable(DB_OPERATION), "DEL"), satisfies( - SemconvStabilityUtil.getAttributeKey(DB_STATEMENT), + maybeStable(DB_STATEMENT), stringAssert -> stringAssert.startsWith("DEL"))))); } diff --git a/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientTest.java b/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientTest.java index 945e8f523828..b9fe12edad39 100644 --- a/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientTest.java +++ b/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.vertx.v4_0.redis; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS; import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_PORT; @@ -18,7 +19,6 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; @@ -209,7 +209,7 @@ void commandWithNoArguments() throws Exception { @SuppressWarnings("deprecation") // using deprecated semconv private static AttributeAssertion[] redisSpanAttributes(String operation, String statement) { // not testing database/dup - if (SemconvStability.emitStableDatabaseSemconv()) { + if (emitStableDatabaseSemconv()) { return new AttributeAssertion[] { equalTo(DB_SYSTEM, "redis"), equalTo(AttributeKey.stringKey("db.query.text"), statement), diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/db/SemconvStabilityUtil.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/db/SemconvStabilityUtil.java index 06d25bd9ec79..282bc92042c9 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/db/SemconvStabilityUtil.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/db/SemconvStabilityUtil.java @@ -6,7 +6,6 @@ package io.opentelemetry.instrumentation.testing.junit.db; import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_CASSANDRA_TABLE; -import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_COSMOSDB_CONTAINER; import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_MONGODB_COLLECTION; import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_NAME; import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION; @@ -39,14 +38,13 @@ private static Map, AttributeKey> buildMap() { map.put(DB_SQL_TABLE, DB_COLLECTION_NAME); map.put(DB_CASSANDRA_TABLE, DB_COLLECTION_NAME); map.put(DB_MONGODB_COLLECTION, DB_COLLECTION_NAME); - map.put(DB_COSMOSDB_CONTAINER, DB_COLLECTION_NAME); return map; } private SemconvStabilityUtil() {} @SuppressWarnings("unchecked") - public static AttributeKey getAttributeKey(AttributeKey oldKey) { + public static AttributeKey maybeStable(AttributeKey oldKey) { // not testing database/dup if (SemconvStability.emitStableDatabaseSemconv()) { return (AttributeKey) oldToNewMap.get(oldKey);