Skip to content

Commit 74d07f1

Browse files
authored
Database stable semconv tests and fixes (#12601)
1 parent 591cdf5 commit 74d07f1

File tree

109 files changed

+1554
-966
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+1554
-966
lines changed

instrumentation/aws-sdk/aws-sdk-2.2/javaagent/build.gradle.kts

+12
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,16 @@ tasks {
164164
include("software/amazon/awssdk/global/handlers/execution.interceptors")
165165
}
166166
}
167+
168+
val testStableSemconv by registering(Test::class) {
169+
filter {
170+
excludeTestsMatching("Aws2SqsSuppressReceiveSpansTest")
171+
}
172+
systemProperty("otel.instrumentation.messaging.experimental.receive-telemetry.enabled", "true")
173+
jvmArgs("-Dotel.semconv-stability.opt-in=database")
174+
}
175+
176+
check {
177+
dependsOn(testStableSemconv)
178+
}
167179
}

instrumentation/aws-sdk/aws-sdk-2.2/library-autoconfigure/build.gradle.kts

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@ dependencies {
2525
}
2626

2727
tasks {
28-
test {
28+
withType<Test>().configureEach {
2929
systemProperty("otel.instrumentation.aws-sdk.experimental-span-attributes", true)
3030
systemProperty("otel.instrumentation.aws-sdk.experimental-record-individual-http-error", true)
3131
systemProperty("otel.instrumentation.messaging.experimental.capture-headers", "test-message-header")
3232
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
3333
}
34+
35+
val testStableSemconv by registering(Test::class) {
36+
jvmArgs("-Dotel.semconv-stability.opt-in=database")
37+
}
38+
39+
check {
40+
dependsOn(testStableSemconv)
41+
}
3442
}

instrumentation/aws-sdk/aws-sdk-2.2/library/build.gradle.kts

+9-1
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,18 @@ testing {
6666
}
6767

6868
tasks {
69-
withType<Test> {
69+
withType<Test>().configureEach {
7070
// NB: If you'd like to change these, there is some cleanup work to be done, as most tests ignore this and
7171
// set the value directly (the "library" does not normally query it, only library-autoconfigure)
7272
systemProperty("otel.instrumentation.aws-sdk.experimental-span-attributes", true)
7373
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
7474
}
75+
76+
val testStableSemconv by registering(Test::class) {
77+
jvmArgs("-Dotel.semconv-stability.opt-in=database")
78+
}
79+
80+
check {
81+
dependsOn(testStableSemconv)
82+
}
7583
}

instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/internal/TracingExecutionInterceptor.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayPropagator;
1717
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
1818
import io.opentelemetry.instrumentation.api.internal.InstrumenterUtil;
19+
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
1920
import io.opentelemetry.instrumentation.api.internal.Timer;
2021
import io.opentelemetry.semconv.HttpAttributes;
2122
import java.io.BufferedReader;
@@ -50,6 +51,8 @@ public final class TracingExecutionInterceptor implements ExecutionInterceptor {
5051

5152
// copied from DbIncubatingAttributes
5253
private static final AttributeKey<String> DB_OPERATION = AttributeKey.stringKey("db.operation");
54+
private static final AttributeKey<String> DB_OPERATION_NAME =
55+
AttributeKey.stringKey("db.operation.name");
5356
private static final AttributeKey<String> DB_SYSTEM = AttributeKey.stringKey("db.system");
5457
// copied from DbIncubatingAttributes.DbSystemIncubatingValues
5558
private static final String DB_SYSTEM_DYNAMODB = "dynamodb";
@@ -331,7 +334,12 @@ private void populateRequestAttributes(
331334
span.setAttribute(DB_SYSTEM, DB_SYSTEM_DYNAMODB);
332335
String operation = attributes.getAttribute(SdkExecutionAttribute.OPERATION_NAME);
333336
if (operation != null) {
334-
span.setAttribute(DB_OPERATION, operation);
337+
if (SemconvStability.emitStableDatabaseSemconv()) {
338+
span.setAttribute(DB_OPERATION_NAME, operation);
339+
}
340+
if (SemconvStability.emitOldDatabaseSemconv()) {
341+
span.setAttribute(DB_OPERATION, operation);
342+
}
335343
}
336344
}
337345
}

instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientCoreTest.groovy

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ package io.opentelemetry.instrumentation.awssdk.v2_2
77

88
import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil
99
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
10-
import io.opentelemetry.semconv.incubating.RpcIncubatingAttributes
11-
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes
12-
import io.opentelemetry.semconv.incubating.AwsIncubatingAttributes
13-
import io.opentelemetry.semconv.ServerAttributes
1410
import io.opentelemetry.semconv.HttpAttributes
11+
import io.opentelemetry.semconv.ServerAttributes
1512
import io.opentelemetry.semconv.UrlAttributes
13+
import io.opentelemetry.semconv.incubating.AwsIncubatingAttributes
14+
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes
15+
import io.opentelemetry.semconv.incubating.RpcIncubatingAttributes
1616
import io.opentelemetry.testing.internal.armeria.common.HttpResponse
1717
import io.opentelemetry.testing.internal.armeria.common.HttpStatus
1818
import io.opentelemetry.testing.internal.armeria.common.MediaType
19+
import io.opentelemetry.testing.internal.armeria.testing.junit5.server.mock.MockWebServerExtension
1920
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials
2021
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider
2122
import software.amazon.awssdk.core.client.builder.SdkClientBuilder
@@ -24,15 +25,14 @@ import software.amazon.awssdk.regions.Region
2425
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient
2526
import software.amazon.awssdk.services.dynamodb.DynamoDbClient
2627
import software.amazon.awssdk.services.dynamodb.model.*
27-
import io.opentelemetry.testing.internal.armeria.testing.junit5.server.mock.MockWebServerExtension
2828
import spock.lang.Shared
2929
import spock.lang.Unroll
3030

3131
import java.util.concurrent.Future
3232

3333
import static com.google.common.collect.ImmutableMap.of
3434
import static io.opentelemetry.api.trace.SpanKind.CLIENT
35-
35+
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable
3636

3737
@Unroll
3838
abstract class AbstractAws2ClientCoreTest extends InstrumentationSpecification {
@@ -150,7 +150,7 @@ abstract class AbstractAws2ClientCoreTest extends InstrumentationSpecification {
150150
"$AwsIncubatingAttributes.AWS_REQUEST_ID" "$requestId"
151151
"aws.table.name" "sometable"
152152
"$DbIncubatingAttributes.DB_SYSTEM" "dynamodb"
153-
"$DbIncubatingAttributes.DB_OPERATION" "CreateTable"
153+
"${maybeStable(DbIncubatingAttributes.DB_OPERATION)}" "CreateTable"
154154
"aws.dynamodb.global_secondary_indexes" "[{\"IndexName\":\"globalIndex\",\"KeySchema\":[{\"AttributeName\":\"attribute\"}],\"ProvisionedThroughput\":{\"ReadCapacityUnits\":10,\"WriteCapacityUnits\":12}},{\"IndexName\":\"globalIndexSecondary\",\"KeySchema\":[{\"AttributeName\":\"attributeSecondary\"}],\"ProvisionedThroughput\":{\"ReadCapacityUnits\":7,\"WriteCapacityUnits\":8}}]"
155155
"aws.dynamodb.provisioned_throughput.read_capacity_units" "1"
156156
"aws.dynamodb.provisioned_throughput.write_capacity_units" "1"
@@ -183,7 +183,7 @@ abstract class AbstractAws2ClientCoreTest extends InstrumentationSpecification {
183183
"$AwsIncubatingAttributes.AWS_REQUEST_ID" "$requestId"
184184
"aws.table.name" "sometable"
185185
"$DbIncubatingAttributes.DB_SYSTEM" "dynamodb"
186-
"$DbIncubatingAttributes.DB_OPERATION" "Query"
186+
"${maybeStable(DbIncubatingAttributes.DB_OPERATION)}" "Query"
187187
"aws.dynamodb.limit" "10"
188188
"aws.dynamodb.select" "ALL_ATTRIBUTES"
189189
}
@@ -215,7 +215,7 @@ abstract class AbstractAws2ClientCoreTest extends InstrumentationSpecification {
215215
"$AwsIncubatingAttributes.AWS_REQUEST_ID" "$requestId"
216216
"aws.table.name" "sometable"
217217
"$DbIncubatingAttributes.DB_SYSTEM" "dynamodb"
218-
"$DbIncubatingAttributes.DB_OPERATION" "${operation}"
218+
"${maybeStable(DbIncubatingAttributes.DB_OPERATION)}" "${operation}"
219219
}
220220
}
221221
}

instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientRecordHttpErrorTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.instrumentation.awssdk.v2_2;
77

88
import static io.opentelemetry.api.common.AttributeKey.stringKey;
9+
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
910
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
1011
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1112
import static io.opentelemetry.semconv.HttpAttributes.HTTP_REQUEST_METHOD;
@@ -184,7 +185,7 @@ public void testSendDynamoDbRequestWithRetries() {
184185
equalTo(AwsIncubatingAttributes.AWS_REQUEST_ID, requestId),
185186
equalTo(stringKey("aws.table.name"), "sometable"),
186187
equalTo(DB_SYSTEM, "dynamodb"),
187-
equalTo(DB_OPERATION, operation));
188+
equalTo(maybeStable(DB_OPERATION), operation));
188189
if (isRecordIndividualHttpErrorEnabled()) {
189190
span.hasEventsSatisfyingExactly(
190191
event ->

instrumentation/camel-2.20/javaagent/build.gradle.kts

+8
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ tasks {
7979

8080
jvmArgs("-Dotel.instrumentation.common.experimental.controller-telemetry.enabled=true")
8181
}
82+
83+
val testStableSemconv by registering(Test::class) {
84+
jvmArgs("-Dotel.semconv-stability.opt-in=database")
85+
}
86+
87+
check {
88+
dependsOn(testStableSemconv)
89+
}
8290
}
8391

8492
configurations.testRuntimeClasspath {

instrumentation/camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/DbSpanDecorator.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import io.opentelemetry.api.common.AttributesBuilder;
2727
import io.opentelemetry.instrumentation.api.incubator.semconv.db.SqlStatementSanitizer;
28+
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
2829
import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig;
2930
import io.opentelemetry.javaagent.instrumentation.apachecamel.CamelDirection;
3031
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
@@ -126,11 +127,21 @@ public void pre(
126127
attributes.put(DbIncubatingAttributes.DB_SYSTEM, system);
127128
String statement = getStatement(exchange, endpoint);
128129
if (statement != null) {
129-
attributes.put(DbIncubatingAttributes.DB_STATEMENT, statement);
130+
if (SemconvStability.emitStableDatabaseSemconv()) {
131+
attributes.put(DbIncubatingAttributes.DB_QUERY_TEXT, statement);
132+
}
133+
if (SemconvStability.emitOldDatabaseSemconv()) {
134+
attributes.put(DbIncubatingAttributes.DB_STATEMENT, statement);
135+
}
130136
}
131137
String dbName = getDbName(endpoint);
132138
if (dbName != null) {
133-
attributes.put(DbIncubatingAttributes.DB_NAME, dbName);
139+
if (SemconvStability.emitStableDatabaseSemconv()) {
140+
attributes.put(DbIncubatingAttributes.DB_NAMESPACE, dbName);
141+
}
142+
if (SemconvStability.emitOldDatabaseSemconv()) {
143+
attributes.put(DbIncubatingAttributes.DB_NAME, dbName);
144+
}
134145
}
135146
}
136147
}

instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/CassandraTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.javaagent.instrumentation.apachecamel.decorators;
77

88
import static io.opentelemetry.api.common.AttributeKey.stringKey;
9+
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
910
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1011
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_NAME;
1112
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_STATEMENT;
@@ -119,9 +120,9 @@ void testCassandra() {
119120
equalTo(
120121
stringKey("camel.uri"),
121122
"cql://" + host + ":" + cassandraPort + "/test"),
122-
equalTo(DB_NAME, "test"),
123+
equalTo(maybeStable(DB_NAME), "test"),
123124
equalTo(
124-
DB_STATEMENT,
125+
maybeStable(DB_STATEMENT),
125126
"select * from test.users where id=? ALLOW FILTERING"),
126127
equalTo(DB_SYSTEM, "cassandra"))));
127128
}

instrumentation/cassandra/cassandra-3.0/javaagent/build.gradle.kts

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ dependencies {
4444
configurations.testRuntimeClasspath.get().resolutionStrategy.force("com.google.guava:guava:19.0")
4545

4646
tasks {
47-
val testStableSemconv by registering(Test::class) {
48-
jvmArgs("-Dotel.semconv-stability.opt-in=database")
49-
}
50-
5147
withType<Test>().configureEach {
5248
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service)
5349
}
5450

51+
val testStableSemconv by registering(Test::class) {
52+
jvmArgs("-Dotel.semconv-stability.opt-in=database")
53+
}
54+
5555
check {
5656
dependsOn(testStableSemconv)
5757
}

instrumentation/cassandra/cassandra-4.0/javaagent/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies {
2424
}
2525

2626
tasks {
27-
test {
27+
withType<Test>().configureEach {
2828
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service)
2929
}
3030

instrumentation/cassandra/cassandra-4.4/javaagent/build.gradle.kts

+9-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ dependencies {
2727
}
2828

2929
tasks {
30-
test {
30+
withType<Test>().configureEach {
3131
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service)
3232
}
33+
34+
val testStableSemconv by registering(Test::class) {
35+
jvmArgs("-Dotel.semconv-stability.opt-in=database")
36+
}
37+
38+
check {
39+
dependsOn(testStableSemconv)
40+
}
3341
}

instrumentation/cassandra/cassandra-4.4/library/build.gradle.kts

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ dependencies {
1212
}
1313

1414
tasks {
15+
withType<Test>().configureEach {
16+
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service)
17+
}
18+
1519
val testStableSemconv by registering(Test::class) {
1620
jvmArgs("-Dotel.semconv-stability.opt-in=database")
1721
}

instrumentation/clickhouse-client-0.5/javaagent/build.gradle.kts

+8
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,12 @@ tasks {
2525
test {
2626
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service)
2727
}
28+
29+
val testStableSemconv by registering(Test::class) {
30+
jvmArgs("-Dotel.semconv-stability.opt-in=database")
31+
}
32+
33+
check {
34+
dependsOn(testStableSemconv)
35+
}
2836
}

instrumentation/clickhouse-client-0.5/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/clickhouse/ClickHouseClientTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.javaagent.instrumentation.clickhouse;
77

8+
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
89
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
910
import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS;
1011
import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
@@ -341,10 +342,10 @@ void testParameterizedQueryInput() throws ClickHouseException {
341342
private static List<AttributeAssertion> attributeAssertions(String statement, String operation) {
342343
return asList(
343344
equalTo(DB_SYSTEM, DbIncubatingAttributes.DbSystemIncubatingValues.CLICKHOUSE),
344-
equalTo(DB_NAME, dbName),
345+
equalTo(maybeStable(DB_NAME), dbName),
345346
equalTo(SERVER_ADDRESS, host),
346347
equalTo(SERVER_PORT, port),
347-
equalTo(DB_STATEMENT, statement),
348-
equalTo(DB_OPERATION, operation));
348+
equalTo(maybeStable(DB_STATEMENT), statement),
349+
equalTo(maybeStable(DB_OPERATION), operation));
349350
}
350351
}

instrumentation/couchbase/couchbase-2.0/javaagent/build.gradle.kts

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ dependencies {
3232
}
3333

3434
tasks {
35-
val testStableSemconv by registering(Test::class) {
36-
jvmArgs("-Dotel.semconv-stability.opt-in=database")
37-
}
38-
3935
withType<Test>().configureEach {
4036
// required on jdk17
4137
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
4238
jvmArgs("--add-opens=java.base/java.lang.invoke=ALL-UNNAMED")
4339
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
4440
}
4541

42+
val testStableSemconv by registering(Test::class) {
43+
jvmArgs("-Dotel.semconv-stability.opt-in=database")
44+
}
45+
4646
check {
4747
dependsOn(testStableSemconv)
4848
}

instrumentation/couchbase/couchbase-2.6/javaagent/build.gradle.kts

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ dependencies {
3535
}
3636

3737
tasks {
38-
val testStableSemconv by registering(Test::class) {
39-
jvmArgs("-Dotel.semconv-stability.opt-in=database")
40-
}
41-
4238
withType<Test>().configureEach {
4339
// TODO run tests both with and without experimental span attributes
4440
jvmArgs("-Dotel.instrumentation.couchbase.experimental-span-attributes=true")
@@ -48,6 +44,10 @@ tasks {
4844
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
4945
}
5046

47+
val testStableSemconv by registering(Test::class) {
48+
jvmArgs("-Dotel.semconv-stability.opt-in=database")
49+
}
50+
5151
check {
5252
dependsOn(testStableSemconv)
5353
}

instrumentation/couchbase/couchbase-3.1.6/javaagent/build.gradle.kts

+9-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ dependencies {
3939
}
4040

4141
tasks {
42-
test {
42+
withType<Test>().configureEach {
4343
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service)
4444
}
45+
46+
val testStableSemconv by registering(Test::class) {
47+
jvmArgs("-Dotel.semconv-stability.opt-in=database")
48+
}
49+
50+
check {
51+
dependsOn(testStableSemconv)
52+
}
4553
}

0 commit comments

Comments
 (0)