Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,7 +62,7 @@ public String getConnectionString(Map<String, Object> map) {

@Override
public Long getBatchSize(Map<String, Object> map) {
return read(map, "db.operation.batch.size", Long.class);
return read(map, DB_OPERATION_BATCH_SIZE.getKey(), Long.class);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -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(
Expand All @@ -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"));
}
}

Expand Down Expand Up @@ -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(
Expand All @@ -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"));
}
}

Expand All @@ -252,7 +253,7 @@ void shouldExtractSingleQueryBatchAttributes() {
Map<String, Object> 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();

Expand All @@ -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(
Expand All @@ -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();
Expand All @@ -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();

Expand All @@ -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();
Expand All @@ -353,7 +354,7 @@ void shouldIgnoreBatchSizeOne() {
Map<String, Object> 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();

Expand All @@ -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(
Expand All @@ -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();
Expand Down Expand Up @@ -446,7 +447,7 @@ void shouldNotExtractQueryParametersForBatch() {
Map<String, Object> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,8 +20,6 @@ enum TransactionAttributeExtractor implements AttributesExtractor<DbRequest, Voi

// copied from DbIncubatingAttributes
private static final AttributeKey<String> DB_OPERATION = AttributeKey.stringKey("db.operation");
private static final AttributeKey<String> DB_OPERATION_NAME =
AttributeKey.stringKey("db.operation.name");

@Override
public void onStart(AttributesBuilder attributes, Context parentContext, DbRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,8 +22,6 @@

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

Expand Down
Loading