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
2 changes: 1 addition & 1 deletion dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ val asmVersion = "9.8"
val jmhVersion = "1.37"
val mockitoVersion = "4.11.0"
val slf4jVersion = "2.0.17"
val semConvVersion = "1.32.0"
val semConvVersion = "1.34.0"
val semConvAlphaVersion = semConvVersion.replaceFirst("(-rc.*)?$".toRegex(), "-alpha$1")

val CORE_DEPENDENCIES = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package io.opentelemetry.instrumentation.api.incubator.semconv.db;

import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;
import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_NAME;
import static io.opentelemetry.semconv.DbAttributes.DB_QUERY_TEXT;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.AttributesBuilder;
Expand All @@ -27,11 +29,7 @@ public final class DbClientAttributesExtractor<REQUEST, RESPONSE>

// copied from DbIncubatingAttributes
private static final AttributeKey<String> DB_STATEMENT = AttributeKey.stringKey("db.statement");
private static final AttributeKey<String> DB_QUERY_TEXT = AttributeKey.stringKey("db.query.text");
static final AttributeKey<String> DB_OPERATION = AttributeKey.stringKey("db.operation");
static final AttributeKey<String> DB_OPERATION_NAME = AttributeKey.stringKey("db.operation.name");
static final AttributeKey<String> DB_RESPONSE_STATUS_CODE =
AttributeKey.stringKey("db.response.status_code");

/** Creates the database client attributes extractor with default configuration. */
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
package io.opentelemetry.instrumentation.api.incubator.semconv.db;

import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;
import static io.opentelemetry.semconv.DbAttributes.DB_NAMESPACE;
import static io.opentelemetry.semconv.DbAttributes.DB_RESPONSE_STATUS_CODE;
import static io.opentelemetry.semconv.DbAttributes.DB_SYSTEM_NAME;
import static io.opentelemetry.semconv.ErrorAttributes.ERROR_TYPE;

import io.opentelemetry.api.common.AttributeKey;
Expand All @@ -23,15 +26,10 @@ abstract class DbClientCommonAttributesExtractor<

// copied from DbIncubatingAttributes
private static final AttributeKey<String> DB_NAME = AttributeKey.stringKey("db.name");
static final AttributeKey<String> DB_NAMESPACE = AttributeKey.stringKey("db.namespace");
static final AttributeKey<String> DB_SYSTEM = AttributeKey.stringKey("db.system");
public static final AttributeKey<String> DB_SYSTEM_NAME =
AttributeKey.stringKey("db.system.name");
private static final AttributeKey<String> DB_USER = AttributeKey.stringKey("db.user");
private static final AttributeKey<String> DB_CONNECTION_STRING =
AttributeKey.stringKey("db.connection_string");
private static final AttributeKey<String> DB_RESPONSE_STATUS_CODE =
AttributeKey.stringKey("db.response.status_code");

final GETTER getter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import io.opentelemetry.api.incubator.metrics.ExtendedDoubleHistogramBuilder;
import io.opentelemetry.api.metrics.DoubleHistogramBuilder;
import io.opentelemetry.semconv.DbAttributes;
import io.opentelemetry.semconv.ErrorAttributes;
import io.opentelemetry.semconv.NetworkAttributes;
import io.opentelemetry.semconv.ServerAttributes;
Expand All @@ -28,11 +29,11 @@ static void applyClientDurationAdvice(DoubleHistogramBuilder builder) {
((ExtendedDoubleHistogramBuilder) builder)
.setAttributesAdvice(
asList(
DbClientCommonAttributesExtractor.DB_SYSTEM_NAME,
SqlClientAttributesExtractor.DB_COLLECTION_NAME,
DbClientCommonAttributesExtractor.DB_NAMESPACE,
DbClientAttributesExtractor.DB_OPERATION_NAME,
DbClientAttributesExtractor.DB_RESPONSE_STATUS_CODE,
DbAttributes.DB_SYSTEM_NAME,
DbAttributes.DB_COLLECTION_NAME,
DbAttributes.DB_NAMESPACE,
DbAttributes.DB_OPERATION_NAME,
DbAttributes.DB_RESPONSE_STATUS_CODE,
ErrorAttributes.ERROR_TYPE,
NetworkAttributes.NETWORK_PEER_ADDRESS,
NetworkAttributes.NETWORK_PEER_PORT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
package io.opentelemetry.instrumentation.api.incubator.semconv.db;

import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;
import static io.opentelemetry.semconv.DbAttributes.DB_COLLECTION_NAME;
import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_BATCH_SIZE;
import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_NAME;
import static io.opentelemetry.semconv.DbAttributes.DB_QUERY_TEXT;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.AttributesBuilder;
Expand All @@ -32,14 +36,7 @@ public final class SqlClientAttributesExtractor<REQUEST, RESPONSE>

// 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");
private static final AttributeKey<String> DB_STATEMENT = AttributeKey.stringKey("db.statement");
private static final AttributeKey<String> DB_QUERY_TEXT = AttributeKey.stringKey("db.query.text");
static final AttributeKey<String> DB_COLLECTION_NAME =
AttributeKey.stringKey("db.collection.name");
private static final AttributeKey<Long> DB_OPERATION_BATCH_SIZE =
AttributeKey.longKey("db.operation.batch.size");
private static final AttributeKeyTemplate<String> DB_QUERY_PARAMETER =
AttributeKeyTemplate.stringKeyTemplate("db.query.parameter");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.semconv.DbAttributes;
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -85,15 +86,15 @@ void shouldExtractAllAvailableAttributes() {
assertThat(startAttributes.build())
.containsOnly(
entry(DbIncubatingAttributes.DB_SYSTEM, "myDb"),
entry(DbIncubatingAttributes.DB_SYSTEM_NAME, "myDb"),
entry(DbAttributes.DB_SYSTEM_NAME, "myDb"),
entry(DbIncubatingAttributes.DB_USER, "username"),
entry(DbIncubatingAttributes.DB_NAME, "potatoes"),
entry(DbIncubatingAttributes.DB_CONNECTION_STRING, "mydb:///potatoes"),
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM potato"),
entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"),
entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"),
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT * FROM potato"),
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"));
entry(DbAttributes.DB_NAMESPACE, "potatoes"),
entry(DbAttributes.DB_QUERY_TEXT, "SELECT * FROM potato"),
entry(DbAttributes.DB_OPERATION_NAME, "SELECT"));
} else if (SemconvStability.emitOldDatabaseSemconv()) {
assertThat(startAttributes.build())
.containsOnly(
Expand All @@ -106,10 +107,10 @@ void shouldExtractAllAvailableAttributes() {
} else if (SemconvStability.emitStableDatabaseSemconv()) {
assertThat(startAttributes.build())
.containsOnly(
entry(DbIncubatingAttributes.DB_SYSTEM_NAME, "myDb"),
entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"),
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT * FROM potato"),
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"));
entry(DbAttributes.DB_SYSTEM_NAME, "myDb"),
entry(DbAttributes.DB_NAMESPACE, "potatoes"),
entry(DbAttributes.DB_QUERY_TEXT, "SELECT * FROM potato"),
entry(DbAttributes.DB_OPERATION_NAME, "SELECT"));
}

assertThat(endAttributes.build().isEmpty()).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.OperationListener;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
import io.opentelemetry.semconv.DbAttributes;
import io.opentelemetry.semconv.ErrorAttributes;
import io.opentelemetry.semconv.NetworkAttributes;
import io.opentelemetry.semconv.ServerAttributes;
Expand All @@ -42,17 +43,17 @@ void collectsMetrics() {

Attributes operationAttributes =
Attributes.builder()
.put(DbClientCommonAttributesExtractor.DB_SYSTEM_NAME, "myDb")
.put(SqlClientAttributesExtractor.DB_COLLECTION_NAME, "table")
.put(DbClientCommonAttributesExtractor.DB_NAMESPACE, "potatoes")
.put(DbClientAttributesExtractor.DB_OPERATION_NAME, "SELECT")
.put(DbAttributes.DB_SYSTEM_NAME, "myDb")
.put(DbAttributes.DB_COLLECTION_NAME, "table")
.put(DbAttributes.DB_NAMESPACE, "potatoes")
.put(DbAttributes.DB_OPERATION_NAME, "SELECT")
.put(ServerAttributes.SERVER_ADDRESS, "localhost")
.put(ServerAttributes.SERVER_PORT, 1234)
.build();

Attributes responseAttributes =
Attributes.builder()
.put(DbClientAttributesExtractor.DB_RESPONSE_STATUS_CODE, "200")
.put(DbAttributes.DB_RESPONSE_STATUS_CODE, "200")
.put(ErrorAttributes.ERROR_TYPE, "400")
.put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4")
.put(NetworkAttributes.NETWORK_PEER_PORT, 8080)
Expand Down Expand Up @@ -88,23 +89,13 @@ void collectsMetrics() {
point
.hasSum(0.15 /* seconds */)
.hasAttributesSatisfying(
equalTo(
DbClientCommonAttributesExtractor.DB_SYSTEM_NAME,
"myDb"),
equalTo(
DbClientCommonAttributesExtractor.DB_NAMESPACE,
"potatoes"),
equalTo(
DbClientAttributesExtractor.DB_OPERATION_NAME,
"SELECT"),
equalTo(
SqlClientAttributesExtractor.DB_COLLECTION_NAME,
"table"),
equalTo(DbAttributes.DB_SYSTEM_NAME, "myDb"),
equalTo(DbAttributes.DB_NAMESPACE, "potatoes"),
equalTo(DbAttributes.DB_OPERATION_NAME, "SELECT"),
equalTo(DbAttributes.DB_COLLECTION_NAME, "table"),
equalTo(ServerAttributes.SERVER_ADDRESS, "localhost"),
equalTo(ServerAttributes.SERVER_PORT, 1234),
equalTo(
DbClientAttributesExtractor.DB_RESPONSE_STATUS_CODE,
"200"),
equalTo(DbAttributes.DB_RESPONSE_STATUS_CODE, "200"),
equalTo(ErrorAttributes.ERROR_TYPE, "400"),
equalTo(
NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4"),
Expand Down
Loading
Loading