Skip to content

Commit a8726bb

Browse files
authored
remove deprecated semconv warnings (#14022)
1 parent 28afa61 commit a8726bb

File tree

3 files changed

+46
-47
lines changed

3 files changed

+46
-47
lines changed

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

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.instrumentation.api.incubator.semconv.db;
77

88
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
9+
import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_BATCH_SIZE;
910
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_QUERY_PARAMETER;
1011
import static java.util.Collections.emptySet;
1112
import static java.util.Collections.singleton;
@@ -61,7 +62,7 @@ public String getConnectionString(Map<String, Object> map) {
6162

6263
@Override
6364
public Long getBatchSize(Map<String, Object> map) {
64-
return read(map, "db.operation.batch.size", Long.class);
65+
return read(map, DB_OPERATION_BATCH_SIZE.getKey(), Long.class);
6566
}
6667

6768
@SuppressWarnings("unchecked")
@@ -174,8 +175,8 @@ void shouldNotExtractTableIfAttributeIsNotSet() {
174175
.containsOnly(
175176
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT *"),
176177
entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"),
177-
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT *"),
178-
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"));
178+
entry(DbAttributes.DB_QUERY_TEXT, "SELECT *"),
179+
entry(DbAttributes.DB_OPERATION_NAME, "SELECT"));
179180
} else if (SemconvStability.emitOldDatabaseSemconv()) {
180181
assertThat(attributes.build())
181182
.containsOnly(
@@ -184,8 +185,8 @@ void shouldNotExtractTableIfAttributeIsNotSet() {
184185
} else if (SemconvStability.emitStableDatabaseSemconv()) {
185186
assertThat(attributes.build())
186187
.containsOnly(
187-
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT *"),
188-
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"));
188+
entry(DbAttributes.DB_QUERY_TEXT, "SELECT *"),
189+
entry(DbAttributes.DB_OPERATION_NAME, "SELECT"));
189190
}
190191
}
191192

@@ -214,9 +215,9 @@ void shouldExtractTableToSpecifiedKey() {
214215
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM table"),
215216
entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"),
216217
entry(DbIncubatingAttributes.DB_CASSANDRA_TABLE, "table"),
217-
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT * FROM table"),
218-
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"),
219-
entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "table"));
218+
entry(DbAttributes.DB_QUERY_TEXT, "SELECT * FROM table"),
219+
entry(DbAttributes.DB_OPERATION_NAME, "SELECT"),
220+
entry(DbAttributes.DB_COLLECTION_NAME, "table"));
220221
} else if (SemconvStability.emitOldDatabaseSemconv()) {
221222
assertThat(attributes.build())
222223
.containsOnly(
@@ -226,9 +227,9 @@ void shouldExtractTableToSpecifiedKey() {
226227
} else if (SemconvStability.emitStableDatabaseSemconv()) {
227228
assertThat(attributes.build())
228229
.containsOnly(
229-
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT * FROM table"),
230-
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"),
231-
entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "table"));
230+
entry(DbAttributes.DB_QUERY_TEXT, "SELECT * FROM table"),
231+
entry(DbAttributes.DB_OPERATION_NAME, "SELECT"),
232+
entry(DbAttributes.DB_COLLECTION_NAME, "table"));
232233
}
233234
}
234235

@@ -252,7 +253,7 @@ void shouldExtractSingleQueryBatchAttributes() {
252253
Map<String, Object> request = new HashMap<>();
253254
request.put("db.name", "potatoes");
254255
request.put("db.statements", singleton("INSERT INTO potato VALUES(?)"));
255-
request.put("db.operation.batch.size", 2L);
256+
request.put(DB_OPERATION_BATCH_SIZE.getKey(), 2L);
256257

257258
Context context = Context.root();
258259

@@ -274,11 +275,11 @@ void shouldExtractSingleQueryBatchAttributes() {
274275
entry(DbIncubatingAttributes.DB_STATEMENT, "INSERT INTO potato VALUES(?)"),
275276
entry(DbIncubatingAttributes.DB_OPERATION, "INSERT"),
276277
entry(DbIncubatingAttributes.DB_SQL_TABLE, "potato"),
277-
entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"),
278-
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"),
279-
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "BATCH INSERT"),
280-
entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "potato"),
281-
entry(DbIncubatingAttributes.DB_OPERATION_BATCH_SIZE, 2L));
278+
entry(DbAttributes.DB_NAMESPACE, "potatoes"),
279+
entry(DbAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"),
280+
entry(DbAttributes.DB_OPERATION_NAME, "BATCH INSERT"),
281+
entry(DbAttributes.DB_COLLECTION_NAME, "potato"),
282+
entry(DB_OPERATION_BATCH_SIZE, 2L));
282283
} else if (SemconvStability.emitOldDatabaseSemconv()) {
283284
assertThat(startAttributes.build())
284285
.containsOnly(
@@ -289,11 +290,11 @@ void shouldExtractSingleQueryBatchAttributes() {
289290
} else if (SemconvStability.emitStableDatabaseSemconv()) {
290291
assertThat(startAttributes.build())
291292
.containsOnly(
292-
entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"),
293-
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"),
294-
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "BATCH INSERT"),
295-
entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "potato"),
296-
entry(DbIncubatingAttributes.DB_OPERATION_BATCH_SIZE, 2L));
293+
entry(DbAttributes.DB_NAMESPACE, "potatoes"),
294+
entry(DbAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"),
295+
entry(DbAttributes.DB_OPERATION_NAME, "BATCH INSERT"),
296+
entry(DbAttributes.DB_COLLECTION_NAME, "potato"),
297+
entry(DB_OPERATION_BATCH_SIZE, 2L));
297298
}
298299

299300
assertThat(endAttributes.build().isEmpty()).isTrue();
@@ -307,7 +308,7 @@ void shouldExtractMultiQueryBatchAttributes() {
307308
request.put(
308309
"db.statements",
309310
Arrays.asList("INSERT INTO potato VALUES(1)", "INSERT INTO potato VALUES(2)"));
310-
request.put("db.operation.batch.size", 2L);
311+
request.put(DB_OPERATION_BATCH_SIZE.getKey(), 2L);
311312

312313
Context context = Context.root();
313314

@@ -326,22 +327,22 @@ void shouldExtractMultiQueryBatchAttributes() {
326327
assertThat(startAttributes.build())
327328
.containsOnly(
328329
entry(DbIncubatingAttributes.DB_NAME, "potatoes"),
329-
entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"),
330-
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"),
331-
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "BATCH INSERT"),
332-
entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "potato"),
333-
entry(DbIncubatingAttributes.DB_OPERATION_BATCH_SIZE, 2L));
330+
entry(DbAttributes.DB_NAMESPACE, "potatoes"),
331+
entry(DbAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"),
332+
entry(DbAttributes.DB_OPERATION_NAME, "BATCH INSERT"),
333+
entry(DbAttributes.DB_COLLECTION_NAME, "potato"),
334+
entry(DB_OPERATION_BATCH_SIZE, 2L));
334335
} else if (SemconvStability.emitOldDatabaseSemconv()) {
335336
assertThat(startAttributes.build())
336337
.containsOnly(entry(DbIncubatingAttributes.DB_NAME, "potatoes"));
337338
} else if (SemconvStability.emitStableDatabaseSemconv()) {
338339
assertThat(startAttributes.build())
339340
.containsOnly(
340-
entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"),
341-
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"),
342-
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "BATCH INSERT"),
343-
entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "potato"),
344-
entry(DbIncubatingAttributes.DB_OPERATION_BATCH_SIZE, 2L));
341+
entry(DbAttributes.DB_NAMESPACE, "potatoes"),
342+
entry(DbAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"),
343+
entry(DbAttributes.DB_OPERATION_NAME, "BATCH INSERT"),
344+
entry(DbAttributes.DB_COLLECTION_NAME, "potato"),
345+
entry(DB_OPERATION_BATCH_SIZE, 2L));
345346
}
346347

347348
assertThat(endAttributes.build().isEmpty()).isTrue();
@@ -353,7 +354,7 @@ void shouldIgnoreBatchSizeOne() {
353354
Map<String, Object> request = new HashMap<>();
354355
request.put("db.name", "potatoes");
355356
request.put("db.statements", singleton("INSERT INTO potato VALUES(?)"));
356-
request.put("db.operation.batch.size", 1L);
357+
request.put(DB_OPERATION_BATCH_SIZE.getKey(), 1L);
357358

358359
Context context = Context.root();
359360

@@ -375,10 +376,10 @@ void shouldIgnoreBatchSizeOne() {
375376
entry(DbIncubatingAttributes.DB_STATEMENT, "INSERT INTO potato VALUES(?)"),
376377
entry(DbIncubatingAttributes.DB_OPERATION, "INSERT"),
377378
entry(DbIncubatingAttributes.DB_SQL_TABLE, "potato"),
378-
entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"),
379-
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"),
380-
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "INSERT"),
381-
entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "potato"));
379+
entry(DbAttributes.DB_NAMESPACE, "potatoes"),
380+
entry(DbAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"),
381+
entry(DbAttributes.DB_OPERATION_NAME, "INSERT"),
382+
entry(DbAttributes.DB_COLLECTION_NAME, "potato"));
382383
} else if (SemconvStability.emitOldDatabaseSemconv()) {
383384
assertThat(startAttributes.build())
384385
.containsOnly(
@@ -389,10 +390,10 @@ void shouldIgnoreBatchSizeOne() {
389390
} else if (SemconvStability.emitStableDatabaseSemconv()) {
390391
assertThat(startAttributes.build())
391392
.containsOnly(
392-
entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"),
393-
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"),
394-
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "INSERT"),
395-
entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "potato"));
393+
entry(DbAttributes.DB_NAMESPACE, "potatoes"),
394+
entry(DbAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"),
395+
entry(DbAttributes.DB_OPERATION_NAME, "INSERT"),
396+
entry(DbAttributes.DB_COLLECTION_NAME, "potato"));
396397
}
397398

398399
assertThat(endAttributes.build().isEmpty()).isTrue();
@@ -446,7 +447,7 @@ void shouldNotExtractQueryParametersForBatch() {
446447
Map<String, Object> request = new HashMap<>();
447448
request.put("db.name", "potatoes");
448449
request.put("db.statements", singleton("INSERT INTO potato VALUES(?)"));
449-
request.put("db.operation.batch.size", 2L);
450+
request.put(DB_OPERATION_BATCH_SIZE.getKey(), 2L);
450451
request.put("db.query.parameter", Collections.singletonMap("0", "1"));
451452

452453
Context context = Context.root();

instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/TransactionAttributeExtractor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.instrumentation.jdbc.internal;
77

88
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;
9+
import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_NAME;
910

1011
import io.opentelemetry.api.common.AttributeKey;
1112
import io.opentelemetry.api.common.AttributesBuilder;
@@ -19,8 +20,6 @@ enum TransactionAttributeExtractor implements AttributesExtractor<DbRequest, Voi
1920

2021
// copied from DbIncubatingAttributes
2122
private static final AttributeKey<String> DB_OPERATION = AttributeKey.stringKey("db.operation");
22-
private static final AttributeKey<String> DB_OPERATION_NAME =
23-
AttributeKey.stringKey("db.operation.name");
2423

2524
@Override
2625
public void onStart(AttributesBuilder attributes, Context parentContext, DbRequest request) {

instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/MongoAttributesExtractor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitOldDatabaseSemconv;
99
import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv;
10+
import static io.opentelemetry.semconv.DbAttributes.DB_COLLECTION_NAME;
1011
import static java.util.Arrays.asList;
1112

1213
import com.mongodb.event.CommandStartedEvent;
@@ -21,8 +22,6 @@
2122

2223
class MongoAttributesExtractor implements AttributesExtractor<CommandStartedEvent, Void> {
2324
// copied from DbIncubatingAttributes
24-
private static final AttributeKey<String> DB_COLLECTION_NAME =
25-
AttributeKey.stringKey("db.collection.name");
2625
private static final AttributeKey<String> DB_MONGODB_COLLECTION =
2726
AttributeKey.stringKey("db.mongodb.collection");
2827

0 commit comments

Comments
 (0)