diff --git a/instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractorTest.java b/instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractorTest.java index 44c06bab1f38..e5dc0307cb95 100644 --- a/instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractorTest.java +++ b/instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractorTest.java @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.api.incubator.semconv.db; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; +import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_BATCH_SIZE; import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_QUERY_PARAMETER; import static java.util.Collections.emptySet; import static java.util.Collections.singleton; @@ -61,7 +62,7 @@ public String getConnectionString(Map map) { @Override public Long getBatchSize(Map map) { - return read(map, "db.operation.batch.size", Long.class); + return read(map, DB_OPERATION_BATCH_SIZE.getKey(), Long.class); } @SuppressWarnings("unchecked") @@ -174,8 +175,8 @@ void shouldNotExtractTableIfAttributeIsNotSet() { .containsOnly( entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT *"), entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"), - entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT *"), - entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT")); + entry(DbAttributes.DB_QUERY_TEXT, "SELECT *"), + entry(DbAttributes.DB_OPERATION_NAME, "SELECT")); } else if (SemconvStability.emitOldDatabaseSemconv()) { assertThat(attributes.build()) .containsOnly( @@ -184,8 +185,8 @@ void shouldNotExtractTableIfAttributeIsNotSet() { } else if (SemconvStability.emitStableDatabaseSemconv()) { assertThat(attributes.build()) .containsOnly( - entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT *"), - entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT")); + entry(DbAttributes.DB_QUERY_TEXT, "SELECT *"), + entry(DbAttributes.DB_OPERATION_NAME, "SELECT")); } } @@ -214,9 +215,9 @@ void shouldExtractTableToSpecifiedKey() { entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM table"), entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"), entry(DbIncubatingAttributes.DB_CASSANDRA_TABLE, "table"), - entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT * FROM table"), - entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"), - entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "table")); + entry(DbAttributes.DB_QUERY_TEXT, "SELECT * FROM table"), + entry(DbAttributes.DB_OPERATION_NAME, "SELECT"), + entry(DbAttributes.DB_COLLECTION_NAME, "table")); } else if (SemconvStability.emitOldDatabaseSemconv()) { assertThat(attributes.build()) .containsOnly( @@ -226,9 +227,9 @@ void shouldExtractTableToSpecifiedKey() { } else if (SemconvStability.emitStableDatabaseSemconv()) { assertThat(attributes.build()) .containsOnly( - entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT * FROM table"), - entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"), - entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "table")); + entry(DbAttributes.DB_QUERY_TEXT, "SELECT * FROM table"), + entry(DbAttributes.DB_OPERATION_NAME, "SELECT"), + entry(DbAttributes.DB_COLLECTION_NAME, "table")); } } @@ -252,7 +253,7 @@ void shouldExtractSingleQueryBatchAttributes() { Map request = new HashMap<>(); request.put("db.name", "potatoes"); request.put("db.statements", singleton("INSERT INTO potato VALUES(?)")); - request.put("db.operation.batch.size", 2L); + request.put(DB_OPERATION_BATCH_SIZE.getKey(), 2L); Context context = Context.root(); @@ -274,11 +275,11 @@ void shouldExtractSingleQueryBatchAttributes() { entry(DbIncubatingAttributes.DB_STATEMENT, "INSERT INTO potato VALUES(?)"), entry(DbIncubatingAttributes.DB_OPERATION, "INSERT"), entry(DbIncubatingAttributes.DB_SQL_TABLE, "potato"), - entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"), - entry(DbIncubatingAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"), - entry(DbIncubatingAttributes.DB_OPERATION_NAME, "BATCH INSERT"), - entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "potato"), - entry(DbIncubatingAttributes.DB_OPERATION_BATCH_SIZE, 2L)); + entry(DbAttributes.DB_NAMESPACE, "potatoes"), + entry(DbAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"), + entry(DbAttributes.DB_OPERATION_NAME, "BATCH INSERT"), + entry(DbAttributes.DB_COLLECTION_NAME, "potato"), + entry(DB_OPERATION_BATCH_SIZE, 2L)); } else if (SemconvStability.emitOldDatabaseSemconv()) { assertThat(startAttributes.build()) .containsOnly( @@ -289,11 +290,11 @@ void shouldExtractSingleQueryBatchAttributes() { } else if (SemconvStability.emitStableDatabaseSemconv()) { assertThat(startAttributes.build()) .containsOnly( - entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"), - entry(DbIncubatingAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"), - entry(DbIncubatingAttributes.DB_OPERATION_NAME, "BATCH INSERT"), - entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "potato"), - entry(DbIncubatingAttributes.DB_OPERATION_BATCH_SIZE, 2L)); + entry(DbAttributes.DB_NAMESPACE, "potatoes"), + entry(DbAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"), + entry(DbAttributes.DB_OPERATION_NAME, "BATCH INSERT"), + entry(DbAttributes.DB_COLLECTION_NAME, "potato"), + entry(DB_OPERATION_BATCH_SIZE, 2L)); } assertThat(endAttributes.build().isEmpty()).isTrue(); @@ -307,7 +308,7 @@ void shouldExtractMultiQueryBatchAttributes() { request.put( "db.statements", Arrays.asList("INSERT INTO potato VALUES(1)", "INSERT INTO potato VALUES(2)")); - request.put("db.operation.batch.size", 2L); + request.put(DB_OPERATION_BATCH_SIZE.getKey(), 2L); Context context = Context.root(); @@ -326,22 +327,22 @@ void shouldExtractMultiQueryBatchAttributes() { assertThat(startAttributes.build()) .containsOnly( entry(DbIncubatingAttributes.DB_NAME, "potatoes"), - entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"), - entry(DbIncubatingAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"), - entry(DbIncubatingAttributes.DB_OPERATION_NAME, "BATCH INSERT"), - entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "potato"), - entry(DbIncubatingAttributes.DB_OPERATION_BATCH_SIZE, 2L)); + entry(DbAttributes.DB_NAMESPACE, "potatoes"), + entry(DbAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"), + entry(DbAttributes.DB_OPERATION_NAME, "BATCH INSERT"), + entry(DbAttributes.DB_COLLECTION_NAME, "potato"), + entry(DB_OPERATION_BATCH_SIZE, 2L)); } else if (SemconvStability.emitOldDatabaseSemconv()) { assertThat(startAttributes.build()) .containsOnly(entry(DbIncubatingAttributes.DB_NAME, "potatoes")); } else if (SemconvStability.emitStableDatabaseSemconv()) { assertThat(startAttributes.build()) .containsOnly( - entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"), - entry(DbIncubatingAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"), - entry(DbIncubatingAttributes.DB_OPERATION_NAME, "BATCH INSERT"), - entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "potato"), - entry(DbIncubatingAttributes.DB_OPERATION_BATCH_SIZE, 2L)); + entry(DbAttributes.DB_NAMESPACE, "potatoes"), + entry(DbAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"), + entry(DbAttributes.DB_OPERATION_NAME, "BATCH INSERT"), + entry(DbAttributes.DB_COLLECTION_NAME, "potato"), + entry(DB_OPERATION_BATCH_SIZE, 2L)); } assertThat(endAttributes.build().isEmpty()).isTrue(); @@ -353,7 +354,7 @@ void shouldIgnoreBatchSizeOne() { Map request = new HashMap<>(); request.put("db.name", "potatoes"); request.put("db.statements", singleton("INSERT INTO potato VALUES(?)")); - request.put("db.operation.batch.size", 1L); + request.put(DB_OPERATION_BATCH_SIZE.getKey(), 1L); Context context = Context.root(); @@ -375,10 +376,10 @@ void shouldIgnoreBatchSizeOne() { entry(DbIncubatingAttributes.DB_STATEMENT, "INSERT INTO potato VALUES(?)"), entry(DbIncubatingAttributes.DB_OPERATION, "INSERT"), entry(DbIncubatingAttributes.DB_SQL_TABLE, "potato"), - entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"), - entry(DbIncubatingAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"), - entry(DbIncubatingAttributes.DB_OPERATION_NAME, "INSERT"), - entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "potato")); + entry(DbAttributes.DB_NAMESPACE, "potatoes"), + entry(DbAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"), + entry(DbAttributes.DB_OPERATION_NAME, "INSERT"), + entry(DbAttributes.DB_COLLECTION_NAME, "potato")); } else if (SemconvStability.emitOldDatabaseSemconv()) { assertThat(startAttributes.build()) .containsOnly( @@ -389,10 +390,10 @@ void shouldIgnoreBatchSizeOne() { } else if (SemconvStability.emitStableDatabaseSemconv()) { assertThat(startAttributes.build()) .containsOnly( - entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"), - entry(DbIncubatingAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"), - entry(DbIncubatingAttributes.DB_OPERATION_NAME, "INSERT"), - entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "potato")); + entry(DbAttributes.DB_NAMESPACE, "potatoes"), + entry(DbAttributes.DB_QUERY_TEXT, "INSERT INTO potato VALUES(?)"), + entry(DbAttributes.DB_OPERATION_NAME, "INSERT"), + entry(DbAttributes.DB_COLLECTION_NAME, "potato")); } assertThat(endAttributes.build().isEmpty()).isTrue(); @@ -446,7 +447,7 @@ void shouldNotExtractQueryParametersForBatch() { Map request = new HashMap<>(); request.put("db.name", "potatoes"); request.put("db.statements", singleton("INSERT INTO potato VALUES(?)")); - request.put("db.operation.batch.size", 2L); + request.put(DB_OPERATION_BATCH_SIZE.getKey(), 2L); request.put("db.query.parameter", Collections.singletonMap("0", "1")); Context context = Context.root(); diff --git a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/TransactionAttributeExtractor.java b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/TransactionAttributeExtractor.java index cb3553b1e7cc..f601f8a0a86d 100644 --- a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/TransactionAttributeExtractor.java +++ b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/TransactionAttributeExtractor.java @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.jdbc.internal; import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet; +import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_NAME; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; @@ -19,8 +20,6 @@ enum TransactionAttributeExtractor implements AttributesExtractor DB_OPERATION = AttributeKey.stringKey("db.operation"); - private static final AttributeKey DB_OPERATION_NAME = - AttributeKey.stringKey("db.operation.name"); @Override public void onStart(AttributesBuilder attributes, Context parentContext, DbRequest request) { diff --git a/instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/MongoAttributesExtractor.java b/instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/MongoAttributesExtractor.java index 75254966739e..1d1cf58f2e0a 100644 --- a/instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/MongoAttributesExtractor.java +++ b/instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/MongoAttributesExtractor.java @@ -7,6 +7,7 @@ import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitOldDatabaseSemconv; import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; +import static io.opentelemetry.semconv.DbAttributes.DB_COLLECTION_NAME; import static java.util.Arrays.asList; import com.mongodb.event.CommandStartedEvent; @@ -21,8 +22,6 @@ class MongoAttributesExtractor implements AttributesExtractor { // copied from DbIncubatingAttributes - private static final AttributeKey DB_COLLECTION_NAME = - AttributeKey.stringKey("db.collection.name"); private static final AttributeKey DB_MONGODB_COLLECTION = AttributeKey.stringKey("db.mongodb.collection");