Skip to content

Commit e691bd2

Browse files
committed
database/dup tests aren't running and fixes
1 parent 30bb310 commit e691bd2

File tree

3 files changed

+102
-82
lines changed

3 files changed

+102
-82
lines changed

instrumentation-api-incubator/build.gradle.kts

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,6 @@ dependencies {
2424
testImplementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating")
2525
}
2626

27-
testing {
28-
suites {
29-
val testStableDatabaseSemconv by registering(JvmTestSuite::class) {
30-
dependencies {
31-
implementation(project())
32-
implementation(project(":testing-common"))
33-
implementation("io.opentelemetry:opentelemetry-sdk")
34-
implementation("io.opentelemetry:opentelemetry-sdk-testing")
35-
}
36-
targets {
37-
all {
38-
testTask.configure {
39-
jvmArgs("-Dotel.semconv-stability.opt-in=database")
40-
}
41-
}
42-
}
43-
}
44-
val testBothDatabaseSemconv by registering(JvmTestSuite::class) {
45-
dependencies {
46-
implementation(project())
47-
implementation(project(":testing-common"))
48-
implementation("io.opentelemetry:opentelemetry-sdk")
49-
implementation("io.opentelemetry:opentelemetry-sdk-testing")
50-
}
51-
targets {
52-
all {
53-
testTask.configure {
54-
jvmArgs("-Dotel.semconv-stability.opt-in=database/dup")
55-
}
56-
}
57-
}
58-
}
59-
}
60-
}
61-
6227
tasks {
6328
// exclude auto-generated code
6429
named<Checkstyle>("checkstyleMain") {
@@ -76,7 +41,16 @@ tasks {
7641
dependsOn("generateJflex")
7742
}
7843

44+
val testStableSemconv by registering(Test::class) {
45+
jvmArgs("-Dotel.semconv-stability.opt-in=database")
46+
}
47+
48+
val testBothSemconv by registering(Test::class) {
49+
jvmArgs("-Dotel.semconv-stability.opt-in=database/dup")
50+
}
51+
7952
check {
80-
dependsOn(testing.suites)
53+
dependsOn(testStableSemconv)
54+
dependsOn(testBothSemconv)
8155
}
8256
}

instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesExtractorTest.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
99
import static org.assertj.core.api.Assertions.entry;
1010

11+
import io.opentelemetry.api.common.AttributeKey;
1112
import io.opentelemetry.api.common.Attributes;
1213
import io.opentelemetry.api.common.AttributesBuilder;
1314
import io.opentelemetry.context.Context;
1415
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
15-
import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil;
16+
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
1617
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
1718
import java.util.Collections;
1819
import java.util.HashMap;
@@ -80,18 +81,35 @@ void shouldExtractAllAvailableAttributes() {
8081
underTest.onEnd(endAttributes, context, request, null, null);
8182

8283
// then
83-
assertThat(startAttributes.build())
84-
.containsOnly(
85-
entry(DbIncubatingAttributes.DB_SYSTEM, "myDb"),
86-
entry(DbIncubatingAttributes.DB_USER, "username"),
87-
entry(SemconvStabilityUtil.getAttributeKey(DbIncubatingAttributes.DB_NAME), "potatoes"),
88-
entry(DbIncubatingAttributes.DB_CONNECTION_STRING, "mydb:///potatoes"),
89-
entry(
90-
SemconvStabilityUtil.getAttributeKey(DbIncubatingAttributes.DB_STATEMENT),
91-
"SELECT * FROM potato"),
92-
entry(
93-
SemconvStabilityUtil.getAttributeKey(DbIncubatingAttributes.DB_OPERATION),
94-
"SELECT"));
84+
if (SemconvStability.emitStableDatabaseSemconv() && SemconvStability.emitOldDatabaseSemconv()) {
85+
assertThat(startAttributes.build())
86+
.containsOnly(
87+
entry(DbIncubatingAttributes.DB_SYSTEM, "myDb"),
88+
entry(DbIncubatingAttributes.DB_USER, "username"),
89+
entry(DbIncubatingAttributes.DB_NAME, "potatoes"),
90+
entry(DbIncubatingAttributes.DB_CONNECTION_STRING, "mydb:///potatoes"),
91+
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM potato"),
92+
entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"),
93+
entry(AttributeKey.stringKey("db.namespace"), "potatoes"),
94+
entry(AttributeKey.stringKey("db.query.text"), "SELECT * FROM potato"),
95+
entry(AttributeKey.stringKey("db.operation.name"), "SELECT"));
96+
} else if (SemconvStability.emitOldDatabaseSemconv()) {
97+
assertThat(startAttributes.build())
98+
.containsOnly(
99+
entry(DbIncubatingAttributes.DB_SYSTEM, "myDb"),
100+
entry(DbIncubatingAttributes.DB_USER, "username"),
101+
entry(DbIncubatingAttributes.DB_NAME, "potatoes"),
102+
entry(DbIncubatingAttributes.DB_CONNECTION_STRING, "mydb:///potatoes"),
103+
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM potato"),
104+
entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"));
105+
} else if (SemconvStability.emitStableDatabaseSemconv()) {
106+
assertThat(startAttributes.build())
107+
.containsOnly(
108+
entry(DbIncubatingAttributes.DB_SYSTEM, "myDb"),
109+
entry(AttributeKey.stringKey("db.namespace"), "potatoes"),
110+
entry(AttributeKey.stringKey("db.query.text"), "SELECT * FROM potato"),
111+
entry(AttributeKey.stringKey("db.operation.name"), "SELECT"));
112+
}
95113

96114
assertThat(endAttributes.build().isEmpty()).isTrue();
97115
}

instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractorTest.java

Lines changed: 61 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.instrumentation.api.incubator.semconv.db;
77

8+
import static io.opentelemetry.api.common.AttributeKey.stringKey;
89
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
910
import static org.assertj.core.api.Assertions.entry;
1011

@@ -13,7 +14,6 @@
1314
import io.opentelemetry.context.Context;
1415
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
1516
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
16-
import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil;
1717
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
1818
import java.util.Collections;
1919
import java.util.HashMap;
@@ -77,7 +77,21 @@ void shouldExtractAllAttributes() {
7777
underTest.onEnd(endAttributes, context, request, null, null);
7878

7979
// then
80-
if (SemconvStability.emitOldDatabaseSemconv()) {
80+
if (SemconvStability.emitStableDatabaseSemconv() && SemconvStability.emitOldDatabaseSemconv()) {
81+
assertThat(startAttributes.build())
82+
.containsOnly(
83+
entry(DbIncubatingAttributes.DB_SYSTEM, "myDb"),
84+
entry(DbIncubatingAttributes.DB_USER, "username"),
85+
entry(DbIncubatingAttributes.DB_NAME, "potatoes"),
86+
entry(DbIncubatingAttributes.DB_CONNECTION_STRING, "mydb:///potatoes"),
87+
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM potato WHERE id=?"),
88+
entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"),
89+
entry(DbIncubatingAttributes.DB_SQL_TABLE, "potato"),
90+
entry(stringKey("db.namespace"), "potatoes"),
91+
entry(stringKey("db.query.text"), "SELECT * FROM potato WHERE id=?"),
92+
entry(stringKey("db.operation.name"), "SELECT"),
93+
entry(stringKey("db.collection.name"), "potato"));
94+
} else if (SemconvStability.emitOldDatabaseSemconv()) {
8195
assertThat(startAttributes.build())
8296
.containsOnly(
8397
entry(DbIncubatingAttributes.DB_SYSTEM, "myDb"),
@@ -87,21 +101,14 @@ void shouldExtractAllAttributes() {
87101
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM potato WHERE id=?"),
88102
entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"),
89103
entry(DbIncubatingAttributes.DB_SQL_TABLE, "potato"));
90-
} else {
104+
} else if (SemconvStability.emitStableDatabaseSemconv()) {
91105
assertThat(startAttributes.build())
92106
.containsOnly(
93107
entry(DbIncubatingAttributes.DB_SYSTEM, "myDb"),
94-
entry(
95-
SemconvStabilityUtil.getAttributeKey(DbIncubatingAttributes.DB_NAME), "potatoes"),
96-
entry(
97-
SemconvStabilityUtil.getAttributeKey(DbIncubatingAttributes.DB_STATEMENT),
98-
"SELECT * FROM potato WHERE id=?"),
99-
entry(
100-
SemconvStabilityUtil.getAttributeKey(DbIncubatingAttributes.DB_OPERATION),
101-
"SELECT"),
102-
entry(
103-
SemconvStabilityUtil.getAttributeKey(DbIncubatingAttributes.DB_SQL_TABLE),
104-
"potato"));
108+
entry(stringKey("db.namespace"), "potatoes"),
109+
entry(stringKey("db.query.text"), "SELECT * FROM potato WHERE id=?"),
110+
entry(stringKey("db.operation.name"), "SELECT"),
111+
entry(stringKey("db.collection.name"), "potato"));
105112
}
106113

107114
assertThat(endAttributes.build().isEmpty()).isTrue();
@@ -123,14 +130,24 @@ void shouldNotExtractTableIfAttributeIsNotSet() {
123130
underTest.onStart(attributes, context, request);
124131

125132
// then
126-
assertThat(attributes.build())
127-
.containsOnly(
128-
entry(
129-
SemconvStabilityUtil.getAttributeKey(DbIncubatingAttributes.DB_STATEMENT),
130-
"SELECT *"),
131-
entry(
132-
SemconvStabilityUtil.getAttributeKey(DbIncubatingAttributes.DB_OPERATION),
133-
"SELECT"));
133+
if (SemconvStability.emitStableDatabaseSemconv() && SemconvStability.emitOldDatabaseSemconv()) {
134+
assertThat(attributes.build())
135+
.containsOnly(
136+
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT *"),
137+
entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"),
138+
entry(stringKey("db.query.text"), "SELECT *"),
139+
entry(stringKey("db.operation.name"), "SELECT"));
140+
} else if (SemconvStability.emitOldDatabaseSemconv()) {
141+
assertThat(attributes.build())
142+
.containsOnly(
143+
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT *"),
144+
entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"));
145+
} else if (SemconvStability.emitStableDatabaseSemconv()) {
146+
assertThat(attributes.build())
147+
.containsOnly(
148+
entry(stringKey("db.query.text"), "SELECT *"),
149+
entry(stringKey("db.operation.name"), "SELECT"));
150+
}
134151
}
135152

136153
@Test
@@ -152,17 +169,28 @@ void shouldExtractTableToSpecifiedKey() {
152169
underTest.onStart(attributes, context, request);
153170

154171
// then
155-
assertThat(attributes.build())
156-
.containsOnly(
157-
entry(
158-
SemconvStabilityUtil.getAttributeKey(DbIncubatingAttributes.DB_STATEMENT),
159-
"SELECT * FROM table"),
160-
entry(
161-
SemconvStabilityUtil.getAttributeKey(DbIncubatingAttributes.DB_OPERATION),
162-
"SELECT"),
163-
entry(
164-
SemconvStabilityUtil.getAttributeKey(DbIncubatingAttributes.DB_CASSANDRA_TABLE),
165-
"table"));
172+
if (SemconvStability.emitStableDatabaseSemconv() && SemconvStability.emitOldDatabaseSemconv()) {
173+
assertThat(attributes.build())
174+
.containsOnly(
175+
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM table"),
176+
entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"),
177+
entry(DbIncubatingAttributes.DB_CASSANDRA_TABLE, "table"),
178+
entry(stringKey("db.query.text"), "SELECT * FROM table"),
179+
entry(stringKey("db.operation.name"), "SELECT"),
180+
entry(stringKey("db.collection.name"), "table"));
181+
} else if (SemconvStability.emitOldDatabaseSemconv()) {
182+
assertThat(attributes.build())
183+
.containsOnly(
184+
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM table"),
185+
entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"),
186+
entry(DbIncubatingAttributes.DB_CASSANDRA_TABLE, "table"));
187+
} else if (SemconvStability.emitStableDatabaseSemconv()) {
188+
assertThat(attributes.build())
189+
.containsOnly(
190+
entry(stringKey("db.query.text"), "SELECT * FROM table"),
191+
entry(stringKey("db.operation.name"), "SELECT"),
192+
entry(stringKey("db.collection.name"), "table"));
193+
}
166194
}
167195

168196
@Test

0 commit comments

Comments
 (0)