Skip to content

Commit f4e554a

Browse files
committed
reuse db incubating attributes in tests
1 parent 07c1761 commit f4e554a

File tree

5 files changed

+34
-30
lines changed

5 files changed

+34
-30
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ void shouldExtractAllAvailableAttributes() {
9090
entry(DbIncubatingAttributes.DB_CONNECTION_STRING, "mydb:///potatoes"),
9191
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM potato"),
9292
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"));
93+
entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"),
94+
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT * FROM potato"),
95+
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"));
9696
} else if (SemconvStability.emitOldDatabaseSemconv()) {
9797
assertThat(startAttributes.build())
9898
.containsOnly(
@@ -106,9 +106,9 @@ void shouldExtractAllAvailableAttributes() {
106106
assertThat(startAttributes.build())
107107
.containsOnly(
108108
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"));
109+
entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"),
110+
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT * FROM potato"),
111+
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"));
112112
}
113113

114114
assertThat(endAttributes.build().isEmpty()).isTrue();

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ void shouldExtractAllAttributes() {
8888
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM potato WHERE id=?"),
8989
entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"),
9090
entry(DbIncubatingAttributes.DB_SQL_TABLE, "potato"),
91-
entry(stringKey("db.namespace"), "potatoes"),
92-
entry(stringKey("db.query.text"), "SELECT * FROM potato WHERE id=?"),
93-
entry(stringKey("db.operation.name"), "SELECT"),
94-
entry(stringKey("db.collection.name"), "potato"));
91+
entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"),
92+
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT * FROM potato WHERE id=?"),
93+
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"),
94+
entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "potato"));
9595
} else if (SemconvStability.emitOldDatabaseSemconv()) {
9696
assertThat(startAttributes.build())
9797
.containsOnly(
@@ -106,10 +106,10 @@ void shouldExtractAllAttributes() {
106106
assertThat(startAttributes.build())
107107
.containsOnly(
108108
entry(DbIncubatingAttributes.DB_SYSTEM, "myDb"),
109-
entry(stringKey("db.namespace"), "potatoes"),
110-
entry(stringKey("db.query.text"), "SELECT * FROM potato WHERE id=?"),
111-
entry(stringKey("db.operation.name"), "SELECT"),
112-
entry(stringKey("db.collection.name"), "potato"));
109+
entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"),
110+
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT * FROM potato WHERE id=?"),
111+
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"),
112+
entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "potato"));
113113
}
114114

115115
assertThat(endAttributes.build().isEmpty()).isTrue();
@@ -136,8 +136,8 @@ void shouldNotExtractTableIfAttributeIsNotSet() {
136136
.containsOnly(
137137
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT *"),
138138
entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"),
139-
entry(stringKey("db.query.text"), "SELECT *"),
140-
entry(stringKey("db.operation.name"), "SELECT"));
139+
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT *"),
140+
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"));
141141
} else if (SemconvStability.emitOldDatabaseSemconv()) {
142142
assertThat(attributes.build())
143143
.containsOnly(
@@ -146,8 +146,8 @@ void shouldNotExtractTableIfAttributeIsNotSet() {
146146
} else if (SemconvStability.emitStableDatabaseSemconv()) {
147147
assertThat(attributes.build())
148148
.containsOnly(
149-
entry(stringKey("db.query.text"), "SELECT *"),
150-
entry(stringKey("db.operation.name"), "SELECT"));
149+
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT *"),
150+
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"));
151151
}
152152
}
153153

@@ -176,9 +176,9 @@ void shouldExtractTableToSpecifiedKey() {
176176
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM table"),
177177
entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"),
178178
entry(DbIncubatingAttributes.DB_CASSANDRA_TABLE, "table"),
179-
entry(stringKey("db.query.text"), "SELECT * FROM table"),
180-
entry(stringKey("db.operation.name"), "SELECT"),
181-
entry(stringKey("db.collection.name"), "table"));
179+
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT * FROM table"),
180+
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"),
181+
entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "table"));
182182
} else if (SemconvStability.emitOldDatabaseSemconv()) {
183183
assertThat(attributes.build())
184184
.containsOnly(
@@ -188,9 +188,9 @@ void shouldExtractTableToSpecifiedKey() {
188188
} else if (SemconvStability.emitStableDatabaseSemconv()) {
189189
assertThat(attributes.build())
190190
.containsOnly(
191-
entry(stringKey("db.query.text"), "SELECT * FROM table"),
192-
entry(stringKey("db.operation.name"), "SELECT"),
193-
entry(stringKey("db.collection.name"), "table"));
191+
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT * FROM table"),
192+
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"),
193+
entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "table"));
194194
}
195195
}
196196

instrumentation/elasticsearch/elasticsearch-api-client-7.16/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/apiclient/ElasticsearchClientTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.opentelemetry.api.trace.SpanKind;
2828
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
2929
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
30+
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
3031
import java.io.IOException;
3132
import java.util.concurrent.CountDownLatch;
3233
import java.util.concurrent.TimeUnit;
@@ -139,10 +140,12 @@ public void elasticsearchIndex() throws IOException {
139140
URL_FULL,
140141
httpHost.toURI() + "/test-index/_doc/test-id?timeout=10s"),
141142
equalTo(
142-
AttributeKey.stringKey("db.elasticsearch.path_parts.index"),
143+
DbIncubatingAttributes.DB_ELASTICSEARCH_PATH_PARTS.getAttributeKey(
144+
"index"),
143145
"test-index"),
144146
equalTo(
145-
AttributeKey.stringKey("db.elasticsearch.path_parts.id"),
147+
DbIncubatingAttributes.DB_ELASTICSEARCH_PATH_PARTS.getAttributeKey(
148+
"id"),
146149
"test-id")),
147150
span ->
148151
span.hasName("PUT")

instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
2323
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
2424
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
25+
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
2526
import io.vertx.core.Vertx;
2627
import io.vertx.redis.client.Redis;
2728
import io.vertx.redis.client.RedisAPI;
@@ -212,9 +213,9 @@ private static AttributeAssertion[] redisSpanAttributes(String operation, String
212213
if (emitStableDatabaseSemconv()) {
213214
return new AttributeAssertion[] {
214215
equalTo(DB_SYSTEM, "redis"),
215-
equalTo(AttributeKey.stringKey("db.query.text"), statement),
216-
equalTo(AttributeKey.stringKey("db.operation.name"), operation),
217-
equalTo(AttributeKey.stringKey("db.namespace"), "1"),
216+
equalTo(DbIncubatingAttributes.DB_QUERY_TEXT, statement),
217+
equalTo(DbIncubatingAttributes.DB_OPERATION_NAME, operation),
218+
equalTo(DbIncubatingAttributes.DB_NAMESPACE, "1"),
218219
equalTo(SERVER_ADDRESS, host),
219220
equalTo(SERVER_PORT, port),
220221
equalTo(NETWORK_PEER_PORT, port),

instrumentation/xxl-job/xxl-job-common/testing/src/main/java/io/opentelemetry/instrumentation/xxljob/AbstractXxlJobTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
2020
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
2121
import io.opentelemetry.sdk.trace.data.StatusData;
22+
import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes;
2223
import java.util.ArrayList;
2324
import java.util.List;
24-
import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes;
2525
import org.junit.jupiter.api.Assumptions;
2626
import org.junit.jupiter.api.BeforeAll;
2727
import org.junit.jupiter.api.Test;

0 commit comments

Comments
 (0)