Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -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 @@ -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,21 @@

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.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 +38,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 +53,22 @@ 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",
maybeStable(DB_SYSTEM),
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, DB_SYSTEM_DYNAMODB);
}
if (SemconvStability.emitOldDatabaseSemconv()) {
span.setAttribute(DB_SYSTEM_NAME, DB_SYSTEM_AWS_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 @@ -15,8 +15,8 @@ public class DecoratorRegistry {
private static final SpanDecorator DEFAULT = new BaseSpanDecorator();
private static final Map<String, SpanDecorator> DECORATORS = loadDecorators();

@SuppressWarnings("deprecation") // using deprecated DbSystemIncubatingValues
private static Map<String, SpanDecorator> loadDecorators() {

Map<String, SpanDecorator> result = new HashMap<>();
result.put("ahc", new HttpSpanDecorator());
result.put("ampq", new MessagingSpanDecorator("ampq"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

final class CassandraSqlAttributesGetter implements SqlClientAttributesGetter<CassandraRequest> {

@SuppressWarnings("deprecation") // using deprecated DbSystemIncubatingValues
@Override
public String getDbSystem(CassandraRequest request) {
return DbIncubatingAttributes.DbSystemIncubatingValues.CASSANDRA;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.semconv.ServerAttributes;
import io.opentelemetry.semconv.incubating.CassandraIncubatingAttributes;
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
Expand All @@ -26,6 +28,7 @@ final class CassandraAttributesExtractor
public void onStart(
AttributesBuilder attributes, Context parentContext, CassandraRequest request) {}

@SuppressWarnings("deprecation") // using deprecated semconv
@Override
public void onEnd(
AttributesBuilder attributes,
Expand All @@ -46,17 +49,38 @@ public void onEnd(
attributes.put(ServerAttributes.SERVER_PORT, ((InetSocketAddress) address).getPort());
}
if (coordinator.getDatacenter() != null) {
attributes.put(
DbIncubatingAttributes.DB_CASSANDRA_COORDINATOR_DC, coordinator.getDatacenter());
if (SemconvStability.emitStableDatabaseSemconv()) {
attributes.put(
CassandraIncubatingAttributes.CASSANDRA_COORDINATOR_DC, coordinator.getDatacenter());
}
if (SemconvStability.emitOldDatabaseSemconv()) {
attributes.put(
DbIncubatingAttributes.DB_CASSANDRA_COORDINATOR_DC, coordinator.getDatacenter());
}
}
if (coordinator.getHostId() != null) {
attributes.put(
DbIncubatingAttributes.DB_CASSANDRA_COORDINATOR_ID, coordinator.getHostId().toString());
if (SemconvStability.emitStableDatabaseSemconv()) {
attributes.put(
CassandraIncubatingAttributes.CASSANDRA_COORDINATOR_ID,
coordinator.getHostId().toString());
}
if (SemconvStability.emitOldDatabaseSemconv()) {
attributes.put(
DbIncubatingAttributes.DB_CASSANDRA_COORDINATOR_ID,
coordinator.getHostId().toString());
}
}
}
attributes.put(
DbIncubatingAttributes.DB_CASSANDRA_SPECULATIVE_EXECUTION_COUNT,
executionInfo.getSpeculativeExecutionCount());
if (SemconvStability.emitStableDatabaseSemconv()) {
attributes.put(
CassandraIncubatingAttributes.CASSANDRA_SPECULATIVE_EXECUTION_COUNT,
executionInfo.getSpeculativeExecutionCount());
}
if (SemconvStability.emitOldDatabaseSemconv()) {
attributes.put(
DbIncubatingAttributes.DB_CASSANDRA_SPECULATIVE_EXECUTION_COUNT,
executionInfo.getSpeculativeExecutionCount());
}

Statement<?> statement = executionInfo.getStatement();
String consistencyLevel;
Expand All @@ -67,21 +91,41 @@ public void onEnd(
} else {
consistencyLevel = config.getString(DefaultDriverOption.REQUEST_CONSISTENCY);
}
attributes.put(DbIncubatingAttributes.DB_CASSANDRA_CONSISTENCY_LEVEL, consistencyLevel);
if (SemconvStability.emitStableDatabaseSemconv()) {
attributes.put(CassandraIncubatingAttributes.CASSANDRA_CONSISTENCY_LEVEL, consistencyLevel);
}
if (SemconvStability.emitOldDatabaseSemconv()) {
attributes.put(DbIncubatingAttributes.DB_CASSANDRA_CONSISTENCY_LEVEL, consistencyLevel);
}

if (statement.getPageSize() > 0) {
attributes.put(DbIncubatingAttributes.DB_CASSANDRA_PAGE_SIZE, statement.getPageSize());
if (SemconvStability.emitStableDatabaseSemconv()) {
attributes.put(CassandraIncubatingAttributes.CASSANDRA_PAGE_SIZE, statement.getPageSize());
}
if (SemconvStability.emitOldDatabaseSemconv()) {
attributes.put(DbIncubatingAttributes.DB_CASSANDRA_PAGE_SIZE, statement.getPageSize());
}
} else {
int pageSize = config.getInt(DefaultDriverOption.REQUEST_PAGE_SIZE);
if (pageSize > 0) {
attributes.put(DbIncubatingAttributes.DB_CASSANDRA_PAGE_SIZE, pageSize);
if (SemconvStability.emitStableDatabaseSemconv()) {
attributes.put(CassandraIncubatingAttributes.CASSANDRA_PAGE_SIZE, pageSize);
}
if (SemconvStability.emitOldDatabaseSemconv()) {
attributes.put(DbIncubatingAttributes.DB_CASSANDRA_PAGE_SIZE, pageSize);
}
}
}

Boolean idempotent = statement.isIdempotent();
if (idempotent == null) {
idempotent = config.getBoolean(DefaultDriverOption.REQUEST_DEFAULT_IDEMPOTENCE);
}
attributes.put(DbIncubatingAttributes.DB_CASSANDRA_IDEMPOTENCE, idempotent);
if (SemconvStability.emitStableDatabaseSemconv()) {
attributes.put(CassandraIncubatingAttributes.CASSANDRA_QUERY_IDEMPOTENT, idempotent);
}
if (SemconvStability.emitOldDatabaseSemconv()) {
attributes.put(DbIncubatingAttributes.DB_CASSANDRA_IDEMPOTENCE, idempotent);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

final class CassandraSqlAttributesGetter implements SqlClientAttributesGetter<CassandraRequest> {

@SuppressWarnings("deprecation") // using deprecated DbSystemIncubatingValues
@Override
public String getDbSystem(CassandraRequest request) {
return DbIncubatingAttributes.DbSystemIncubatingValues.CASSANDRA;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public String getDbOperationName(ClickHouseDbRequest request) {
return request.getSqlStatementInfo().getOperation();
}

@Nullable
@SuppressWarnings("deprecation") // using deprecated DbSystemIncubatingValues
@Override
public String getDbSystem(ClickHouseDbRequest request) {
return DbIncubatingAttributes.DbSystemIncubatingValues.CLICKHOUSE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

final class CouchbaseAttributesGetter implements DbClientAttributesGetter<CouchbaseRequestInfo> {

@SuppressWarnings("deprecation") // using deprecated DbSystemIncubatingValues
@Override
public String getDbSystem(CouchbaseRequestInfo couchbaseRequest) {
return DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE;
Expand Down
Loading
Loading