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
7 changes: 3 additions & 4 deletions bom-alpha/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ dependencies {
// Get the semconv version from :dependencyManagement
val semconvConstraint = project.project(project(":dependencyManagement").path).configurations["api"].allDependencyConstraints
.find { it.group.equals("io.opentelemetry.semconv")
&& it.name.equals("opentelemetry-semconv") }
&& it.name.equals("opentelemetry-semconv-incubating") }
?: throw Exception("semconv constraint not found")
val semconvVersion = semconvConstraint.version ?: throw Exception("missing version")
otelBom.addExtra(semconvConstraint.group, semconvConstraint.name, semconvVersion)
otelBom.addExtra(semconvConstraint.group, "opentelemetry-semconv-incubating", semconvVersion)
val semconvAlphaVersion = semconvConstraint.version ?: throw Exception("missing version")
otelBom.addExtra(semconvConstraint.group, "opentelemetry-semconv-incubating", semconvAlphaVersion)
}

otelBom.projectFilter.set { it.findProperty("otel.stable") != "true" }
8 changes: 8 additions & 0 deletions bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ javaPlatform {

dependencies {
api(platform("io.opentelemetry:opentelemetry-bom"))

// Get the semconv version from :dependencyManagement
val semconvConstraint = project.project(project(":dependencyManagement").path).configurations["api"].allDependencyConstraints
.find { it.group.equals("io.opentelemetry.semconv")
&& it.name.equals("opentelemetry-semconv") }
?: throw Exception("semconv constraint not found")
val semconvVersion = semconvConstraint.version ?: throw Exception("missing version")
otelBom.addExtra(semconvConstraint.group, semconvConstraint.name, semconvVersion)
}

otelBom.projectFilter.set { it.findProperty("otel.stable") == "true" }
5 changes: 3 additions & 2 deletions dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ val asmVersion = "9.7.1"
val jmhVersion = "1.37"
val mockitoVersion = "4.11.0"
val slf4jVersion = "2.0.16"
val semConvVersion = "1.29.0-alpha"
val semConvVersion = "1.30.0-rc.1"
val semConvAlphaVersion = semConvVersion.replaceFirst("(-rc.*)?$".toRegex(), "-alpha$1")

val CORE_DEPENDENCIES = listOf(
"io.opentelemetry.semconv:opentelemetry-semconv:${semConvVersion}",
"io.opentelemetry.semconv:opentelemetry-semconv-incubating:${semConvVersion}",
"io.opentelemetry.semconv:opentelemetry-semconv-incubating:${semConvAlphaVersion}",
"com.google.auto.service:auto-service:${autoServiceVersion}",
"com.google.auto.service:auto-service-annotations:${autoServiceVersion}",
"com.google.auto.value:auto-value:${autoValueVersion}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

@SuppressWarnings("deprecation") // CodeIncubatingAttributes.CODE_FUNCTION is deprecated
public abstract class AbstractWithSpanTest<T extends U, U> {

@RegisterExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ abstract class DbClientCommonAttributesExtractor<
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");
Expand All @@ -37,11 +39,15 @@ abstract class DbClientCommonAttributesExtractor<
@SuppressWarnings("deprecation") // until old db semconv are dropped
@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
internalSet(attributes, DB_SYSTEM, getter.getDbSystem(request));
if (SemconvStability.emitStableDatabaseSemconv()) {
internalSet(
attributes,
DB_SYSTEM_NAME,
SemconvStability.stableDbSystemName(getter.getDbSystem(request)));
internalSet(attributes, DB_NAMESPACE, getter.getDbNamespace(request));
}
if (SemconvStability.emitOldDatabaseSemconv()) {
internalSet(attributes, DB_SYSTEM, getter.getDbSystem(request));
internalSet(attributes, DB_USER, getter.getUser(request));
internalSet(attributes, DB_NAME, getter.getDbNamespace(request));
internalSet(attributes, DB_CONNECTION_STRING, getter.getConnectionString(request));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static void applyClientDurationAdvice(DoubleHistogramBuilder builder) {
((ExtendedDoubleHistogramBuilder) builder)
.setAttributesAdvice(
asList(
DbClientCommonAttributesExtractor.DB_SYSTEM,
DbClientCommonAttributesExtractor.DB_SYSTEM_NAME,
SqlClientAttributesExtractor.DB_COLLECTION_NAME,
DbClientCommonAttributesExtractor.DB_NAMESPACE,
DbClientAttributesExtractor.DB_OPERATION_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public String getMethodName(Map<String, String> request) {
}
}

@SuppressWarnings("deprecation") // using deprecated semconv
@Test
void shouldExtractAllAttributes() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void shouldExtractAllAvailableAttributes() {
assertThat(startAttributes.build())
.containsOnly(
entry(DbIncubatingAttributes.DB_SYSTEM, "myDb"),
entry(DbIncubatingAttributes.DB_SYSTEM_NAME, "myDb"),
entry(DbIncubatingAttributes.DB_USER, "username"),
entry(DbIncubatingAttributes.DB_NAME, "potatoes"),
entry(DbIncubatingAttributes.DB_CONNECTION_STRING, "mydb:///potatoes"),
Expand All @@ -104,7 +105,7 @@ void shouldExtractAllAvailableAttributes() {
} else if (SemconvStability.emitStableDatabaseSemconv()) {
assertThat(startAttributes.build())
.containsOnly(
entry(DbIncubatingAttributes.DB_SYSTEM, "myDb"),
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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void collectsMetrics() {

Attributes operationAttributes =
Attributes.builder()
.put(DbClientCommonAttributesExtractor.DB_SYSTEM, "myDb")
.put(DbClientCommonAttributesExtractor.DB_SYSTEM_NAME, "myDb")
.put(SqlClientAttributesExtractor.DB_COLLECTION_NAME, "table")
.put(DbClientCommonAttributesExtractor.DB_NAMESPACE, "potatoes")
.put(DbClientAttributesExtractor.DB_OPERATION_NAME, "SELECT")
Expand Down Expand Up @@ -89,7 +89,7 @@ void collectsMetrics() {
.hasSum(0.15 /* seconds */)
.hasAttributesSatisfying(
equalTo(
DbClientCommonAttributesExtractor.DB_SYSTEM,
DbClientCommonAttributesExtractor.DB_SYSTEM_NAME,
"myDb"),
equalTo(
DbClientCommonAttributesExtractor.DB_NAMESPACE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void shouldExtractAllAttributes() {
assertThat(startAttributes.build())
.containsOnly(
entry(DbIncubatingAttributes.DB_SYSTEM, "myDb"),
entry(DbIncubatingAttributes.DB_SYSTEM_NAME, "myDb"),
entry(DbIncubatingAttributes.DB_USER, "username"),
entry(DbIncubatingAttributes.DB_NAME, "potatoes"),
entry(DbIncubatingAttributes.DB_CONNECTION_STRING, "mydb:///potatoes"),
Expand All @@ -131,7 +132,7 @@ void shouldExtractAllAttributes() {
} else if (SemconvStability.emitStableDatabaseSemconv()) {
assertThat(startAttributes.build())
.containsOnly(
entry(DbIncubatingAttributes.DB_SYSTEM, "myDb"),
entry(DbIncubatingAttributes.DB_SYSTEM_NAME, "myDb"),
entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"),
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT * FROM potato WHERE id=?"),
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import static java.util.Arrays.asList;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
Expand Down Expand Up @@ -50,5 +52,30 @@ public static boolean emitStableDatabaseSemconv() {
return emitStableDatabaseSemconv;
}

private static final Map<String, String> dbSystemNameMap = new HashMap<>();

static {
dbSystemNameMap.put("adabas", "softwareag.adabas");
dbSystemNameMap.put("intersystems_cache", "intersystems.cache");
dbSystemNameMap.put("cosmosdb", "azure.cosmosdb");
dbSystemNameMap.put("db2", "ibm.db2");
dbSystemNameMap.put("dynamodb", "aws.dynamodb");
dbSystemNameMap.put("h2", "h2database");
dbSystemNameMap.put("hanadb", "sap.hana");
dbSystemNameMap.put("informix", "ibm.informix");
dbSystemNameMap.put("ingres", "actian.ingres");
dbSystemNameMap.put("maxdb", "sap.maxdb");
dbSystemNameMap.put("mssql", "microsoft.sql_server");
dbSystemNameMap.put("netezza", "ibm.netezza");
dbSystemNameMap.put("oracle", "oracle.db");
dbSystemNameMap.put("redshift", "aws.redshift");
dbSystemNameMap.put("spanner", "gcp.spanner");
}

public static String stableDbSystemName(String oldDbSystem) {
String dbSystemName = dbSystemNameMap.get(oldDbSystem);
return dbSystemName != null ? dbSystemName : oldDbSystem;
}

private SemconvStability() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
Expand All @@ -20,16 +21,24 @@ public class DynamoDbAttributesExtractor implements AttributesExtractor<Request<

// copied from DbIncubatingAttributes
private static final AttributeKey<String> DB_SYSTEM = AttributeKey.stringKey("db.system");
private static final AttributeKey<String> DB_SYSTEM_NAME =
AttributeKey.stringKey("db.system.name");
// copied from AwsIncubatingAttributes
private static final AttributeKey<List<String>> AWS_DYNAMODB_TABLE_NAMES =
AttributeKey.stringArrayKey("aws.dynamodb.table_names");

// copied from DbIncubatingAttributes.DbSystemIncubatingValues
private static final String DYNAMODB = "dynamodb";
// copied from DbIncubatingAttributes.DbSystemNameIncubatingValues
private static final String AWS_DYNAMODB = "aws.dynamodb";

@Override
public void onStart(AttributesBuilder attributes, Context parentContext, Request<?> request) {
AttributesExtractorUtil.internalSet(attributes, DB_SYSTEM, DYNAMODB);
if (SemconvStability.emitStableDatabaseSemconv()) {
AttributesExtractorUtil.internalSet(attributes, DB_SYSTEM_NAME, AWS_DYNAMODB);
} else {
AttributesExtractorUtil.internalSet(attributes, DB_SYSTEM, DYNAMODB);
}
String tableName = RequestAccess.getTableName(request.getOriginalRequest());
AttributesExtractorUtil.internalSet(
attributes, AWS_DYNAMODB_TABLE_NAMES, Collections.singletonList(tableName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@

import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.instrumentation.testing.junit.db.DbClientMetricsTestUtil.assertDurationMetric;
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_DYNAMODB_TABLE_NAMES;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DbSystemIncubatingValues.DYNAMODB;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM_NAME;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DbSystemNameIncubatingValues.AWS_DYNAMODB;
import static java.util.Collections.singletonList;

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
import io.opentelemetry.testing.internal.armeria.common.HttpResponse;
import io.opentelemetry.testing.internal.armeria.common.HttpStatus;
import io.opentelemetry.testing.internal.armeria.common.MediaType;
Expand All @@ -35,6 +39,7 @@ protected boolean hasRequestId() {
return false;
}

@SuppressWarnings("deprecation") // using deprecated semconv
@Test
public void sendRequestWithMockedResponse() throws Exception {
AmazonDynamoDBClientBuilder clientBuilder = AmazonDynamoDBClientBuilder.standard();
Expand All @@ -49,14 +54,18 @@ public void sendRequestWithMockedResponse() throws Exception {
List<AttributeAssertion> additionalAttributes =
Arrays.asList(
equalTo(stringKey("aws.table.name"), "sometable"),
equalTo(DB_SYSTEM, DYNAMODB),
equalTo(
maybeStable(DB_SYSTEM),
SemconvStability.emitStableDatabaseSemconv()
? AWS_DYNAMODB
: DbIncubatingAttributes.DbSystemIncubatingValues.DYNAMODB),
equalTo(AWS_DYNAMODB_TABLE_NAMES, singletonList("sometable")));

Object response = client.createTable(new CreateTableRequest("sometable", null));
assertRequestWithMockedResponse(
response, client, "DynamoDBv2", "CreateTable", "POST", additionalAttributes);

assertDurationMetric(
testing(), "io.opentelemetry.aws-sdk-1.11", DB_SYSTEM, SERVER_ADDRESS, SERVER_PORT);
testing(), "io.opentelemetry.aws-sdk-1.11", DB_SYSTEM_NAME, SERVER_ADDRESS, SERVER_PORT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ public final class TracingExecutionInterceptor implements ExecutionInterceptor {
private static final AttributeKey<String> DB_OPERATION_NAME =
AttributeKey.stringKey("db.operation.name");
private static final AttributeKey<String> DB_SYSTEM = AttributeKey.stringKey("db.system");
private static final AttributeKey<String> DB_SYSTEM_NAME =
AttributeKey.stringKey("db.system.name");
// copied from DbIncubatingAttributes.DbSystemIncubatingValues
private static final String DB_SYSTEM_DYNAMODB = "dynamodb";
// copied from DbIncubatingAttributes.DbSystemNameIncubatingValues
private static final String DB_SYSTEM_AWS_DYNAMODB = "aws.dynamodb";
// copied from AwsIncubatingAttributes
private static final AttributeKey<String> AWS_REQUEST_ID =
AttributeKey.stringKey("aws.request_id");
Expand Down Expand Up @@ -331,7 +335,12 @@ private void populateRequestAttributes(
fieldMapper.mapToAttributes(sdkRequest, awsSdkRequest, span);

if (awsSdkRequest.type() == DYNAMODB) {
span.setAttribute(DB_SYSTEM, DB_SYSTEM_DYNAMODB);
if (SemconvStability.emitStableDatabaseSemconv()) {
span.setAttribute(DB_SYSTEM_NAME, DB_SYSTEM_AWS_DYNAMODB);
}
if (SemconvStability.emitOldDatabaseSemconv()) {
span.setAttribute(DB_SYSTEM, DB_SYSTEM_DYNAMODB);
}
String operation = attributes.getAttribute(SdkExecutionAttribute.OPERATION_NAME);
if (operation != null) {
if (SemconvStability.emitStableDatabaseSemconv()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStableDbSystemName;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.semconv.HttpAttributes.HTTP_REQUEST_METHOD;
import static io.opentelemetry.semconv.HttpAttributes.HTTP_RESPONSE_STATUS_CODE;
Expand Down Expand Up @@ -170,7 +171,7 @@ private static void assertCreateTableRequest(SpanDataAssert span) {
equalTo(stringKey("aws.agent"), "java-aws-sdk"),
equalTo(AWS_REQUEST_ID, "UNKNOWN"),
equalTo(stringKey("aws.table.name"), "sometable"),
equalTo(DB_SYSTEM, "dynamodb"),
equalTo(maybeStable(DB_SYSTEM), maybeStableDbSystemName("dynamodb")),
equalTo(maybeStable(DB_OPERATION), "CreateTable"),
equalTo(
stringKey("aws.dynamodb.global_secondary_indexes"),
Expand All @@ -196,7 +197,7 @@ private static void assertQueryRequest(SpanDataAssert span) {
equalTo(stringKey("aws.agent"), "java-aws-sdk"),
equalTo(AWS_REQUEST_ID, "UNKNOWN"),
equalTo(stringKey("aws.table.name"), "sometable"),
equalTo(DB_SYSTEM, "dynamodb"),
equalTo(maybeStable(DB_SYSTEM), maybeStableDbSystemName("dynamodb")),
equalTo(maybeStable(DB_OPERATION), "Query"),
equalTo(stringKey("aws.dynamodb.limit"), "10"),
equalTo(stringKey("aws.dynamodb.select"), "ALL_ATTRIBUTES"));
Expand All @@ -219,7 +220,7 @@ private static void assertDynamoDbRequest(SpanDataAssert span, String operation)
equalTo(stringKey("aws.agent"), "java-aws-sdk"),
equalTo(AWS_REQUEST_ID, "UNKNOWN"),
equalTo(stringKey("aws.table.name"), "sometable"),
equalTo(DB_SYSTEM, "dynamodb"),
equalTo(maybeStable(DB_SYSTEM), maybeStableDbSystemName("dynamodb")),
equalTo(maybeStable(DB_OPERATION), operation));
}

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

import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStableDbSystemName;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.semconv.HttpAttributes.HTTP_REQUEST_METHOD;
Expand Down Expand Up @@ -184,7 +185,7 @@ public void testSendDynamoDbRequestWithRetries() {
equalTo(stringKey("aws.agent"), "java-aws-sdk"),
equalTo(AWS_REQUEST_ID, requestId),
equalTo(stringKey("aws.table.name"), "sometable"),
equalTo(DB_SYSTEM, "dynamodb"),
equalTo(maybeStable(DB_SYSTEM), maybeStableDbSystemName("dynamodb")),
equalTo(maybeStable(DB_OPERATION), operation));
if (isRecordIndividualHttpErrorEnabled()) {
span.hasEventsSatisfyingExactly(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ public void pre(
CamelDirection camelDirection) {
super.pre(attributes, exchange, endpoint, camelDirection);

attributes.put(DbIncubatingAttributes.DB_SYSTEM, system);
if (SemconvStability.emitStableDatabaseSemconv()) {
attributes.put(DbIncubatingAttributes.DB_SYSTEM_NAME, system);
}
if (SemconvStability.emitOldDatabaseSemconv()) {
attributes.put(DbIncubatingAttributes.DB_SYSTEM, system);
}
String statement = getStatement(exchange, endpoint);
if (statement != null) {
if (SemconvStability.emitStableDatabaseSemconv()) {
Expand Down
Loading
Loading