diff --git a/instrumentation-api-incubator/build.gradle.kts b/instrumentation-api-incubator/build.gradle.kts index 00d887da1b25..81c90c90748d 100644 --- a/instrumentation-api-incubator/build.gradle.kts +++ b/instrumentation-api-incubator/build.gradle.kts @@ -40,4 +40,17 @@ tasks { sourcesJar { dependsOn("generateJflex") } + + val testStableSemconv by registering(Test::class) { + jvmArgs("-Dotel.semconv-stability.opt-in=database") + } + + val testBothSemconv by registering(Test::class) { + jvmArgs("-Dotel.semconv-stability.opt-in=database/dup") + } + + check { + dependsOn(testStableSemconv) + dependsOn(testBothSemconv) + } } diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesExtractor.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesExtractor.java index 09c8fbc72570..279f3171d192 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesExtractor.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesExtractor.java @@ -11,6 +11,7 @@ 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; /** * Extractor of // copied from DbIncubatingAttributes private static final AttributeKey DB_STATEMENT = AttributeKey.stringKey("db.statement"); + private static final AttributeKey DB_QUERY_TEXT = AttributeKey.stringKey("db.query.text"); + private static final AttributeKey DB_OPERATION = AttributeKey.stringKey("db.operation"); + private static final AttributeKey DB_OPERATION_NAME = + AttributeKey.stringKey("db.operation.name"); /** Creates the database client attributes extractor with default configuration. */ public static AttributesExtractor create( @@ -42,7 +47,13 @@ public static AttributesExtractor create( public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { super.onStart(attributes, parentContext, request); - internalSet(attributes, DB_STATEMENT, getter.getStatement(request)); - internalSet(attributes, DB_OPERATION, getter.getOperation(request)); + if (SemconvStability.emitStableDatabaseSemconv()) { + internalSet(attributes, DB_QUERY_TEXT, getter.getDbQueryText(request)); + internalSet(attributes, DB_OPERATION_NAME, getter.getDbOperationName(request)); + } + if (SemconvStability.emitOldDatabaseSemconv()) { + internalSet(attributes, DB_STATEMENT, getter.getDbQueryText(request)); + internalSet(attributes, DB_OPERATION, getter.getDbOperationName(request)); + } } } diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesGetter.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesGetter.java index 0d924b3dcfbf..ddf9f8f07a1a 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesGetter.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesGetter.java @@ -20,9 +20,33 @@ */ public interface DbClientAttributesGetter extends DbClientCommonAttributesGetter { + /** + * @deprecated Use {@link #getDbQueryText(REQUEST)} instead. + */ + @Deprecated @Nullable - String getStatement(REQUEST request); + default String getStatement(REQUEST request) { + return null; + } + // TODO: make this required to implement @Nullable - String getOperation(REQUEST request); + default String getDbQueryText(REQUEST request) { + return getStatement(request); + } + + /** + * @deprecated Use {@link #getDbOperationName(REQUEST)} instead. + */ + @Deprecated + @Nullable + default String getOperation(REQUEST request) { + return null; + } + + // TODO: make this required to implement + @Nullable + default String getDbOperationName(REQUEST request) { + return getOperation(request); + } } diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientCommonAttributesExtractor.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientCommonAttributesExtractor.java index e3a6614c7660..9cbf4fb97895 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientCommonAttributesExtractor.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientCommonAttributesExtractor.java @@ -11,6 +11,7 @@ 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.instrumentation.api.internal.SpanKey; import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider; import javax.annotation.Nullable; @@ -21,6 +22,7 @@ abstract class DbClientCommonAttributesExtractor< // copied from DbIncubatingAttributes private static final AttributeKey DB_NAME = AttributeKey.stringKey("db.name"); + private static final AttributeKey DB_NAMESPACE = AttributeKey.stringKey("db.namespace"); private static final AttributeKey DB_SYSTEM = AttributeKey.stringKey("db.system"); private static final AttributeKey DB_USER = AttributeKey.stringKey("db.user"); private static final AttributeKey DB_CONNECTION_STRING = @@ -32,12 +34,18 @@ abstract class DbClientCommonAttributesExtractor< this.getter = getter; } + @SuppressWarnings("deprecation") // until old db semconv are dropped @Override public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { - internalSet(attributes, DB_SYSTEM, getter.getSystem(request)); - internalSet(attributes, DB_USER, getter.getUser(request)); - internalSet(attributes, DB_NAME, getter.getName(request)); - internalSet(attributes, DB_CONNECTION_STRING, getter.getConnectionString(request)); + internalSet(attributes, DB_SYSTEM, getter.getDbSystem(request)); + if (SemconvStability.emitStableDatabaseSemconv()) { + internalSet(attributes, DB_NAMESPACE, getter.getDbNamespace(request)); + } + if (SemconvStability.emitOldDatabaseSemconv()) { + internalSet(attributes, DB_USER, getter.getUser(request)); + internalSet(attributes, DB_NAME, getter.getDbNamespace(request)); + internalSet(attributes, DB_CONNECTION_STRING, getter.getConnectionString(request)); + } } @Override diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientCommonAttributesGetter.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientCommonAttributesGetter.java index 430be029cb0c..bc9a335f4e76 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientCommonAttributesGetter.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientCommonAttributesGetter.java @@ -10,15 +10,38 @@ /** An interface for getting attributes common to database clients. */ public interface DbClientCommonAttributesGetter { + @Deprecated @Nullable - String getSystem(REQUEST request); + default String getSystem(REQUEST request) { + return null; + } + // TODO: make this required to implement + @Nullable + default String getDbSystem(REQUEST request) { + return getSystem(request); + } + + @Deprecated @Nullable String getUser(REQUEST request); + /** + * @deprecated Use {@link #getDbNamespace(Object)} instead. + */ + @Deprecated + @Nullable + default String getName(REQUEST request) { + return null; + } + + // TODO: make this required to implement @Nullable - String getName(REQUEST request); + default String getDbNamespace(REQUEST request) { + return getName(request); + } + @Deprecated @Nullable String getConnectionString(REQUEST request); } diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientSpanNameExtractor.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientSpanNameExtractor.java index 534db4a2a49e..58eb91b08b09 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientSpanNameExtractor.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientSpanNameExtractor.java @@ -13,8 +13,9 @@ public abstract class DbClientSpanNameExtractor implements SpanNameExtr * Returns a {@link SpanNameExtractor} that constructs the span name according to DB semantic * conventions: {@code }. * - * @see DbClientAttributesGetter#getOperation(Object) used to extract {@code }. - * @see DbClientAttributesGetter#getName(Object) used to extract {@code }. + * @see DbClientAttributesGetter#getDbOperationName(Object) used to extract {@code + * }. + * @see DbClientAttributesGetter#getDbNamespace(Object) used to extract {@code }. */ public static SpanNameExtractor create( DbClientAttributesGetter getter) { @@ -26,7 +27,7 @@ public static SpanNameExtractor create( * conventions: {@code .}. * * @see SqlStatementInfo#getOperation() used to extract {@code }. - * @see DbClientAttributesGetter#getName(Object) used to extract {@code }. + * @see DbClientAttributesGetter#getDbNamespace(Object) used to extract {@code }. * @see SqlStatementInfo#getMainIdentifier() used to extract {@code } or stored * procedure name. */ @@ -72,9 +73,9 @@ private GenericDbClientSpanNameExtractor(DbClientAttributesGetter gette @Override public String extract(REQUEST request) { - String dbName = getter.getName(request); - String operation = getter.getOperation(request); - return computeSpanName(dbName, operation, null); + String namespace = getter.getDbNamespace(request); + String operationName = getter.getDbOperationName(request); + return computeSpanName(namespace, operationName, null); } } @@ -92,10 +93,10 @@ private SqlClientSpanNameExtractor(SqlClientAttributesGetter getter) { @Override public String extract(REQUEST request) { - String dbName = getter.getName(request); - SqlStatementInfo sanitizedStatement = sanitizer.sanitize(getter.getRawStatement(request)); + String namespace = getter.getDbNamespace(request); + SqlStatementInfo sanitizedStatement = sanitizer.sanitize(getter.getRawQueryText(request)); return computeSpanName( - dbName, sanitizedStatement.getOperation(), sanitizedStatement.getMainIdentifier()); + namespace, sanitizedStatement.getOperation(), sanitizedStatement.getMainIdentifier()); } } } diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractor.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractor.java index eacf266333bc..fc5f29efe81b 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractor.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractor.java @@ -11,6 +11,7 @@ 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; /** * Extractor of It sets the same set of attributes as {@link DbClientAttributesExtractor} plus an additional * db.sql.table attribute. The raw SQL statements returned by the {@link - * SqlClientAttributesGetter#getRawStatement(Object)} method are sanitized before use, all statement + * SqlClientAttributesGetter#getRawQueryText(Object)} method are sanitized before use, all statement * parameters are removed. */ public final class SqlClientAttributesExtractor @@ -28,7 +29,12 @@ public final class SqlClientAttributesExtractor // copied from DbIncubatingAttributes private static final AttributeKey DB_OPERATION = AttributeKey.stringKey("db.operation"); + private static final AttributeKey DB_OPERATION_NAME = + AttributeKey.stringKey("db.operation.name"); private static final AttributeKey DB_STATEMENT = AttributeKey.stringKey("db.statement"); + private static final AttributeKey DB_QUERY_TEXT = AttributeKey.stringKey("db.query.text"); + private static final AttributeKey DB_COLLECTION_NAME = + AttributeKey.stringKey("db.collection.name"); /** Creates the SQL client attributes extractor with default configuration. */ public static AttributesExtractor create( @@ -49,15 +55,15 @@ public static SqlClientAttributesExtractorBuilder dbTableAttribute; + private final AttributeKey oldSemconvTableAttribute; private final boolean statementSanitizationEnabled; SqlClientAttributesExtractor( SqlClientAttributesGetter getter, - AttributeKey dbTableAttribute, + AttributeKey oldSemconvTableAttribute, boolean statementSanitizationEnabled) { super(getter); - this.dbTableAttribute = dbTableAttribute; + this.oldSemconvTableAttribute = oldSemconvTableAttribute; this.statementSanitizationEnabled = statementSanitizationEnabled; } @@ -65,16 +71,30 @@ public static SqlClientAttributesExtractorBuilder { private static final AttributeKey DB_SQL_TABLE = AttributeKey.stringKey("db.sql.table"); final SqlClientAttributesGetter getter; - AttributeKey dbTableAttribute = DB_SQL_TABLE; + AttributeKey oldSemconvTableAttribute = DB_SQL_TABLE; boolean statementSanitizationEnabled = true; SqlClientAttributesExtractorBuilder(SqlClientAttributesGetter getter) { @@ -26,17 +26,13 @@ public final class SqlClientAttributesExtractorBuilder { } /** - * Configures the extractor to set the table value extracted by the {@link - * SqlClientAttributesExtractor} under the {@code dbTableAttribute} key. By default, the - * db.sql.table attribute is used. - * - * @param dbTableAttribute The {@link AttributeKey} under which the table extracted by the {@link - * SqlClientAttributesExtractor} will be stored. + * @deprecated not needed anymore since the new semantic conventions always use db.collection.name */ @CanIgnoreReturnValue + @Deprecated public SqlClientAttributesExtractorBuilder setTableAttribute( - AttributeKey dbTableAttribute) { - this.dbTableAttribute = requireNonNull(dbTableAttribute); + AttributeKey oldSemconvTableAttribute) { + this.oldSemconvTableAttribute = requireNonNull(oldSemconvTableAttribute); return this; } @@ -58,6 +54,6 @@ public SqlClientAttributesExtractorBuilder setStatementSaniti */ public AttributesExtractor build() { return new SqlClientAttributesExtractor<>( - getter, dbTableAttribute, statementSanitizationEnabled); + getter, oldSemconvTableAttribute, statementSanitizationEnabled); } } diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesGetter.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesGetter.java index e0a19c43df2a..d0817d63e460 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesGetter.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesGetter.java @@ -24,7 +24,18 @@ public interface SqlClientAttributesGetter /** * Get the raw SQL statement. The value returned by this method is later sanitized by the {@link * SqlClientAttributesExtractor} before being set as span attribute. + * + * @deprecated Use {@link #getRawQueryText(Object)} instead. */ + @Deprecated @Nullable - String getRawStatement(REQUEST request); + default String getRawStatement(REQUEST request) { + return null; + } + + // TODO: make this required to implement + @Nullable + default String getRawQueryText(REQUEST request) { + return getRawStatement(request); + } } diff --git a/instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesExtractorTest.java b/instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesExtractorTest.java index 68991d1b813a..4836a85e359c 100644 --- a/instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesExtractorTest.java +++ b/instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesExtractorTest.java @@ -8,10 +8,12 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static org.assertj.core.api.Assertions.entry; +import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; 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.incubating.DbIncubatingAttributes; import java.util.Collections; import java.util.HashMap; @@ -22,32 +24,34 @@ class DbClientAttributesExtractorTest { static final class TestAttributesGetter implements DbClientAttributesGetter> { @Override - public String getSystem(Map map) { + public String getDbSystem(Map map) { return map.get("db.system"); } + @Deprecated @Override public String getUser(Map map) { return map.get("db.user"); } @Override - public String getName(Map map) { + public String getDbNamespace(Map map) { return map.get("db.name"); } + @Deprecated @Override public String getConnectionString(Map map) { return map.get("db.connection_string"); } @Override - public String getStatement(Map map) { + public String getDbQueryText(Map map) { return map.get("db.statement"); } @Override - public String getOperation(Map map) { + public String getDbOperationName(Map map) { return map.get("db.operation"); } } @@ -77,14 +81,35 @@ void shouldExtractAllAvailableAttributes() { underTest.onEnd(endAttributes, context, request, null, null); // then - assertThat(startAttributes.build()) - .containsOnly( - entry(DbIncubatingAttributes.DB_SYSTEM, "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")); + if (SemconvStability.emitStableDatabaseSemconv() && SemconvStability.emitOldDatabaseSemconv()) { + assertThat(startAttributes.build()) + .containsOnly( + entry(DbIncubatingAttributes.DB_SYSTEM, "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(AttributeKey.stringKey("db.namespace"), "potatoes"), + entry(AttributeKey.stringKey("db.query.text"), "SELECT * FROM potato"), + entry(AttributeKey.stringKey("db.operation.name"), "SELECT")); + } else if (SemconvStability.emitOldDatabaseSemconv()) { + assertThat(startAttributes.build()) + .containsOnly( + entry(DbIncubatingAttributes.DB_SYSTEM, "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")); + } else if (SemconvStability.emitStableDatabaseSemconv()) { + assertThat(startAttributes.build()) + .containsOnly( + entry(DbIncubatingAttributes.DB_SYSTEM, "myDb"), + entry(AttributeKey.stringKey("db.namespace"), "potatoes"), + entry(AttributeKey.stringKey("db.query.text"), "SELECT * FROM potato"), + entry(AttributeKey.stringKey("db.operation.name"), "SELECT")); + } assertThat(endAttributes.build().isEmpty()).isTrue(); } diff --git a/instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientSpanNameExtractorTest.java b/instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientSpanNameExtractorTest.java index 39698bdc1ca2..1e05cef5a37e 100644 --- a/instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientSpanNameExtractorTest.java +++ b/instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientSpanNameExtractorTest.java @@ -24,8 +24,8 @@ void shouldExtractFullSpanName() { // given DbRequest dbRequest = new DbRequest(); - when(sqlAttributesGetter.getRawStatement(dbRequest)).thenReturn("SELECT * from table"); - when(sqlAttributesGetter.getName(dbRequest)).thenReturn("database"); + when(sqlAttributesGetter.getRawQueryText(dbRequest)).thenReturn("SELECT * from table"); + when(sqlAttributesGetter.getDbNamespace(dbRequest)).thenReturn("database"); SpanNameExtractor underTest = DbClientSpanNameExtractor.create(sqlAttributesGetter); @@ -41,8 +41,8 @@ void shouldSkipDbNameIfTableAlreadyHasDbNamePrefix() { // given DbRequest dbRequest = new DbRequest(); - when(sqlAttributesGetter.getRawStatement(dbRequest)).thenReturn("SELECT * from another.table"); - when(sqlAttributesGetter.getName(dbRequest)).thenReturn("database"); + when(sqlAttributesGetter.getRawQueryText(dbRequest)).thenReturn("SELECT * from another.table"); + when(sqlAttributesGetter.getDbNamespace(dbRequest)).thenReturn("database"); SpanNameExtractor underTest = DbClientSpanNameExtractor.create(sqlAttributesGetter); @@ -58,7 +58,7 @@ void shouldExtractOperationAndTable() { // given DbRequest dbRequest = new DbRequest(); - when(sqlAttributesGetter.getRawStatement(dbRequest)).thenReturn("SELECT * from table"); + when(sqlAttributesGetter.getRawQueryText(dbRequest)).thenReturn("SELECT * from table"); SpanNameExtractor underTest = DbClientSpanNameExtractor.create(sqlAttributesGetter); @@ -74,8 +74,8 @@ void shouldExtractOperationAndName() { // given DbRequest dbRequest = new DbRequest(); - when(dbAttributesGetter.getOperation(dbRequest)).thenReturn("SELECT"); - when(dbAttributesGetter.getName(dbRequest)).thenReturn("database"); + when(dbAttributesGetter.getDbOperationName(dbRequest)).thenReturn("SELECT"); + when(dbAttributesGetter.getDbNamespace(dbRequest)).thenReturn("database"); SpanNameExtractor underTest = DbClientSpanNameExtractor.create(dbAttributesGetter); @@ -91,7 +91,7 @@ void shouldExtractOperation() { // given DbRequest dbRequest = new DbRequest(); - when(dbAttributesGetter.getOperation(dbRequest)).thenReturn("SELECT"); + when(dbAttributesGetter.getDbOperationName(dbRequest)).thenReturn("SELECT"); SpanNameExtractor underTest = DbClientSpanNameExtractor.create(dbAttributesGetter); @@ -107,7 +107,7 @@ void shouldExtractDbName() { // given DbRequest dbRequest = new DbRequest(); - when(dbAttributesGetter.getName(dbRequest)).thenReturn("database"); + when(dbAttributesGetter.getDbNamespace(dbRequest)).thenReturn("database"); SpanNameExtractor underTest = DbClientSpanNameExtractor.create(dbAttributesGetter); 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 9b32c1f5d7e1..f0b31197a3e2 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 @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.api.incubator.semconv.db; +import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static org.assertj.core.api.Assertions.entry; @@ -12,6 +13,7 @@ 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.incubating.DbIncubatingAttributes; import java.util.Collections; import java.util.HashMap; @@ -25,25 +27,27 @@ static final class TestAttributesGetter implements SqlClientAttributesGetter> { @Override - public String getRawStatement(Map map) { + public String getRawQueryText(Map map) { return map.get("db.statement"); } @Override - public String getSystem(Map map) { + public String getDbSystem(Map map) { return map.get("db.system"); } + @Deprecated @Override public String getUser(Map map) { return map.get("db.user"); } @Override - public String getName(Map map) { + public String getDbNamespace(Map map) { return map.get("db.name"); } + @Deprecated @Override public String getConnectionString(Map map) { return map.get("db.connection_string"); @@ -74,15 +78,39 @@ void shouldExtractAllAttributes() { underTest.onEnd(endAttributes, context, request, null, null); // then - assertThat(startAttributes.build()) - .containsOnly( - entry(DbIncubatingAttributes.DB_SYSTEM, "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 WHERE id=?"), - entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"), - entry(DbIncubatingAttributes.DB_SQL_TABLE, "potato")); + if (SemconvStability.emitStableDatabaseSemconv() && SemconvStability.emitOldDatabaseSemconv()) { + assertThat(startAttributes.build()) + .containsOnly( + entry(DbIncubatingAttributes.DB_SYSTEM, "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 WHERE id=?"), + entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"), + entry(DbIncubatingAttributes.DB_SQL_TABLE, "potato"), + entry(stringKey("db.namespace"), "potatoes"), + entry(stringKey("db.query.text"), "SELECT * FROM potato WHERE id=?"), + entry(stringKey("db.operation.name"), "SELECT"), + entry(stringKey("db.collection.name"), "potato")); + } else if (SemconvStability.emitOldDatabaseSemconv()) { + assertThat(startAttributes.build()) + .containsOnly( + entry(DbIncubatingAttributes.DB_SYSTEM, "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 WHERE id=?"), + entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"), + entry(DbIncubatingAttributes.DB_SQL_TABLE, "potato")); + } else if (SemconvStability.emitStableDatabaseSemconv()) { + assertThat(startAttributes.build()) + .containsOnly( + entry(DbIncubatingAttributes.DB_SYSTEM, "myDb"), + entry(stringKey("db.namespace"), "potatoes"), + entry(stringKey("db.query.text"), "SELECT * FROM potato WHERE id=?"), + entry(stringKey("db.operation.name"), "SELECT"), + entry(stringKey("db.collection.name"), "potato")); + } assertThat(endAttributes.build().isEmpty()).isTrue(); } @@ -103,13 +131,28 @@ void shouldNotExtractTableIfAttributeIsNotSet() { underTest.onStart(attributes, context, request); // then - assertThat(attributes.build()) - .containsOnly( - entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT *"), - entry(DbIncubatingAttributes.DB_OPERATION, "SELECT")); + if (SemconvStability.emitStableDatabaseSemconv() && SemconvStability.emitOldDatabaseSemconv()) { + assertThat(attributes.build()) + .containsOnly( + entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT *"), + entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"), + entry(stringKey("db.query.text"), "SELECT *"), + entry(stringKey("db.operation.name"), "SELECT")); + } else if (SemconvStability.emitOldDatabaseSemconv()) { + assertThat(attributes.build()) + .containsOnly( + entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT *"), + entry(DbIncubatingAttributes.DB_OPERATION, "SELECT")); + } else if (SemconvStability.emitStableDatabaseSemconv()) { + assertThat(attributes.build()) + .containsOnly( + entry(stringKey("db.query.text"), "SELECT *"), + entry(stringKey("db.operation.name"), "SELECT")); + } } @Test + @SuppressWarnings("deprecation") // to support old database semantic conventions void shouldExtractTableToSpecifiedKey() { // given Map request = new HashMap<>(); @@ -127,11 +170,28 @@ void shouldExtractTableToSpecifiedKey() { underTest.onStart(attributes, context, request); // then - assertThat(attributes.build()) - .containsOnly( - entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM table"), - entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"), - entry(DbIncubatingAttributes.DB_CASSANDRA_TABLE, "table")); + if (SemconvStability.emitStableDatabaseSemconv() && SemconvStability.emitOldDatabaseSemconv()) { + assertThat(attributes.build()) + .containsOnly( + entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM table"), + entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"), + entry(DbIncubatingAttributes.DB_CASSANDRA_TABLE, "table"), + entry(stringKey("db.query.text"), "SELECT * FROM table"), + entry(stringKey("db.operation.name"), "SELECT"), + entry(stringKey("db.collection.name"), "table")); + } else if (SemconvStability.emitOldDatabaseSemconv()) { + assertThat(attributes.build()) + .containsOnly( + entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM table"), + entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"), + entry(DbIncubatingAttributes.DB_CASSANDRA_TABLE, "table")); + } else if (SemconvStability.emitStableDatabaseSemconv()) { + assertThat(attributes.build()) + .containsOnly( + entry(stringKey("db.query.text"), "SELECT * FROM table"), + entry(stringKey("db.operation.name"), "SELECT"), + entry(stringKey("db.collection.name"), "table")); + } } @Test diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/SemconvStability.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/SemconvStability.java new file mode 100644 index 000000000000..bbf7706c5a43 --- /dev/null +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/SemconvStability.java @@ -0,0 +1,54 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.internal; + +import static java.util.Arrays.asList; + +import java.util.HashSet; +import java.util.Set; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public final class SemconvStability { + + private static final boolean emitOldDatabaseSemconv; + private static final boolean emitStableDatabaseSemconv; + + static { + boolean oldDatabase = true; + boolean stableDatabase = false; + + String value = ConfigPropertiesUtil.getString("otel.semconv-stability.opt-in"); + if (value != null) { + Set values = new HashSet<>(asList(value.split(","))); + if (values.contains("database")) { + oldDatabase = false; + stableDatabase = true; + } + // no else -- technically it's possible to set "database,database/dup", in which case we + // should emit both sets of attributes + if (values.contains("database/dup")) { + oldDatabase = true; + stableDatabase = true; + } + } + + emitOldDatabaseSemconv = oldDatabase; + emitStableDatabaseSemconv = stableDatabase; + } + + public static boolean emitOldDatabaseSemconv() { + return emitOldDatabaseSemconv; + } + + public static boolean emitStableDatabaseSemconv() { + return emitStableDatabaseSemconv; + } + + private SemconvStability() {} +} diff --git a/instrumentation/cassandra/cassandra-3.0/javaagent/build.gradle.kts b/instrumentation/cassandra/cassandra-3.0/javaagent/build.gradle.kts index f4dfa06370fb..924e4db0f3a3 100644 --- a/instrumentation/cassandra/cassandra-3.0/javaagent/build.gradle.kts +++ b/instrumentation/cassandra/cassandra-3.0/javaagent/build.gradle.kts @@ -44,7 +44,15 @@ dependencies { configurations.testRuntimeClasspath.get().resolutionStrategy.force("com.google.guava:guava:19.0") tasks { - test { + val testStableSemconv by registering(Test::class) { + jvmArgs("-Dotel.semconv-stability.opt-in=database") + } + + withType().configureEach { usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) } + + check { + dependsOn(testStableSemconv) + } } diff --git a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraRequest.java b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraRequest.java index 5407bb6d2f75..0463ce3aa3f5 100644 --- a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraRequest.java +++ b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraRequest.java @@ -11,11 +11,11 @@ @AutoValue public abstract class CassandraRequest { - public static CassandraRequest create(Session session, String statement) { - return new AutoValue_CassandraRequest(session, statement); + public static CassandraRequest create(Session session, String queryText) { + return new AutoValue_CassandraRequest(session, queryText); } public abstract Session getSession(); - public abstract String getStatement(); + public abstract String getQueryText(); } diff --git a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraSqlAttributesGetter.java b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraSqlAttributesGetter.java index 935b407d4cde..516f1133bea6 100644 --- a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraSqlAttributesGetter.java +++ b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraSqlAttributesGetter.java @@ -12,10 +12,11 @@ final class CassandraSqlAttributesGetter implements SqlClientAttributesGetter { @Override - public String getSystem(CassandraRequest request) { + public String getDbSystem(CassandraRequest request) { return DbIncubatingAttributes.DbSystemIncubatingValues.CASSANDRA; } + @Deprecated @Override @Nullable public String getUser(CassandraRequest request) { @@ -24,10 +25,11 @@ public String getUser(CassandraRequest request) { @Override @Nullable - public String getName(CassandraRequest request) { + public String getDbNamespace(CassandraRequest request) { return request.getSession().getLoggedKeyspace(); } + @Deprecated @Override @Nullable public String getConnectionString(CassandraRequest request) { @@ -36,7 +38,7 @@ public String getConnectionString(CassandraRequest request) { @Override @Nullable - public String getRawStatement(CassandraRequest request) { - return request.getStatement(); + public String getRawQueryText(CassandraRequest request) { + return request.getQueryText(); } } diff --git a/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/java/CassandraClientTest.java b/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/java/CassandraClientTest.java index e788a240b943..2db183ba837d 100644 --- a/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/java/CassandraClientTest.java +++ b/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/java/CassandraClientTest.java @@ -12,6 +12,7 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil; import io.opentelemetry.semconv.NetworkAttributes; import io.opentelemetry.semconv.ServerAttributes; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; @@ -101,7 +102,8 @@ void syncTest(Parameter parameter) { equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort), equalTo(DbIncubatingAttributes.DB_SYSTEM, "cassandra"), equalTo( - DbIncubatingAttributes.DB_STATEMENT, + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), "USE " + parameter.keyspace))), trace -> trace.hasSpansSatisfyingExactly( @@ -116,12 +118,22 @@ void syncTest(Parameter parameter) { equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, cassandraIp), equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort), equalTo(DbIncubatingAttributes.DB_SYSTEM, "cassandra"), - equalTo(DbIncubatingAttributes.DB_NAME, parameter.keyspace), equalTo( - DbIncubatingAttributes.DB_STATEMENT, parameter.expectedStatement), - equalTo(DbIncubatingAttributes.DB_OPERATION, parameter.operation), + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_NAME), + parameter.keyspace), equalTo( - DbIncubatingAttributes.DB_CASSANDRA_TABLE, parameter.table)))); + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + parameter.expectedStatement), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + parameter.operation), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_CASSANDRA_TABLE), + parameter.table)))); } else { testing.waitAndAssertTraces( trace -> @@ -138,10 +150,17 @@ void syncTest(Parameter parameter) { equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort), equalTo(DbIncubatingAttributes.DB_SYSTEM, "cassandra"), equalTo( - DbIncubatingAttributes.DB_STATEMENT, parameter.expectedStatement), - equalTo(DbIncubatingAttributes.DB_OPERATION, parameter.operation), + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + parameter.expectedStatement), equalTo( - DbIncubatingAttributes.DB_CASSANDRA_TABLE, parameter.table)))); + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + parameter.operation), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_CASSANDRA_TABLE), + parameter.table)))); } session.close(); @@ -179,7 +198,8 @@ void asyncTest(Parameter parameter) { equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort), equalTo(DbIncubatingAttributes.DB_SYSTEM, "cassandra"), equalTo( - DbIncubatingAttributes.DB_STATEMENT, + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), "USE " + parameter.keyspace))), trace -> trace.hasSpansSatisfyingExactly( @@ -195,11 +215,22 @@ void asyncTest(Parameter parameter) { equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, cassandraIp), equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort), equalTo(DbIncubatingAttributes.DB_SYSTEM, "cassandra"), - equalTo(DbIncubatingAttributes.DB_NAME, parameter.keyspace), equalTo( - DbIncubatingAttributes.DB_STATEMENT, parameter.expectedStatement), - equalTo(DbIncubatingAttributes.DB_OPERATION, parameter.operation), - equalTo(DbIncubatingAttributes.DB_CASSANDRA_TABLE, parameter.table)), + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_NAME), + parameter.keyspace), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + parameter.expectedStatement), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + parameter.operation), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_CASSANDRA_TABLE), + parameter.table)), span -> span.hasName("callbackListener") .hasKind(SpanKind.INTERNAL) @@ -221,9 +252,17 @@ void asyncTest(Parameter parameter) { equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort), equalTo(DbIncubatingAttributes.DB_SYSTEM, "cassandra"), equalTo( - DbIncubatingAttributes.DB_STATEMENT, parameter.expectedStatement), - equalTo(DbIncubatingAttributes.DB_OPERATION, parameter.operation), - equalTo(DbIncubatingAttributes.DB_CASSANDRA_TABLE, parameter.table)), + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + parameter.expectedStatement), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + parameter.operation), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_CASSANDRA_TABLE), + parameter.table)), span -> span.hasName("callbackListener") .hasKind(SpanKind.INTERNAL) diff --git a/instrumentation/cassandra/cassandra-4-common/testing/src/main/java/io/opentelemetry/cassandra/v4/common/AbstractCassandraTest.java b/instrumentation/cassandra/cassandra-4-common/testing/src/main/java/io/opentelemetry/cassandra/v4/common/AbstractCassandraTest.java index e7d34b0fc14b..e8c06ee952c8 100644 --- a/instrumentation/cassandra/cassandra-4-common/testing/src/main/java/io/opentelemetry/cassandra/v4/common/AbstractCassandraTest.java +++ b/instrumentation/cassandra/cassandra-4-common/testing/src/main/java/io/opentelemetry/cassandra/v4/common/AbstractCassandraTest.java @@ -27,6 +27,7 @@ import com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil; import io.opentelemetry.semconv.NetworkAttributes; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; import java.net.InetAddress; @@ -108,11 +109,18 @@ void syncTest(Parameter parameter) { equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, cassandraIp), equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort), equalTo(DB_SYSTEM, "cassandra"), - equalTo(DbIncubatingAttributes.DB_NAME, parameter.keyspace), equalTo( - DbIncubatingAttributes.DB_STATEMENT, + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_NAME), + parameter.keyspace), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), parameter.expectedStatement), - equalTo(DbIncubatingAttributes.DB_OPERATION, parameter.operation), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + parameter.operation), equalTo(DB_CASSANDRA_CONSISTENCY_LEVEL, "LOCAL_ONE"), equalTo(DB_CASSANDRA_COORDINATOR_DC, "datacenter1"), satisfies( @@ -124,7 +132,9 @@ void syncTest(Parameter parameter) { equalTo(DB_CASSANDRA_PAGE_SIZE, 5000), equalTo(DB_CASSANDRA_SPECULATIVE_EXECUTION_COUNT, 0), equalTo( - DbIncubatingAttributes.DB_CASSANDRA_TABLE, parameter.table)))); + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_CASSANDRA_TABLE), + parameter.table)))); session.close(); } @@ -165,11 +175,18 @@ void asyncTest(Parameter parameter) throws Exception { equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, cassandraIp), equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort), equalTo(DB_SYSTEM, "cassandra"), - equalTo(DbIncubatingAttributes.DB_NAME, parameter.keyspace), equalTo( - DbIncubatingAttributes.DB_STATEMENT, + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_NAME), + parameter.keyspace), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), parameter.expectedStatement), - equalTo(DbIncubatingAttributes.DB_OPERATION, parameter.operation), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + parameter.operation), equalTo(DB_CASSANDRA_CONSISTENCY_LEVEL, "LOCAL_ONE"), equalTo(DB_CASSANDRA_COORDINATOR_DC, "datacenter1"), satisfies( @@ -181,7 +198,9 @@ void asyncTest(Parameter parameter) throws Exception { equalTo(DB_CASSANDRA_PAGE_SIZE, 5000), equalTo(DB_CASSANDRA_SPECULATIVE_EXECUTION_COUNT, 0), equalTo( - DbIncubatingAttributes.DB_CASSANDRA_TABLE, parameter.table)), + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_CASSANDRA_TABLE), + parameter.table)), span -> span.hasName("child") .hasKind(SpanKind.INTERNAL) diff --git a/instrumentation/cassandra/cassandra-4.0/javaagent/build.gradle.kts b/instrumentation/cassandra/cassandra-4.0/javaagent/build.gradle.kts index 8c5f2faab149..28eb7cf3f557 100644 --- a/instrumentation/cassandra/cassandra-4.0/javaagent/build.gradle.kts +++ b/instrumentation/cassandra/cassandra-4.0/javaagent/build.gradle.kts @@ -27,4 +27,12 @@ tasks { test { usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) } + + val testStableSemconv by registering(Test::class) { + jvmArgs("-Dotel.semconv-stability.opt-in=database") + } + + check { + dependsOn(testStableSemconv) + } } diff --git a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraRequest.java b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraRequest.java index 9c783cc3f196..e4160bb80495 100644 --- a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraRequest.java +++ b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraRequest.java @@ -11,11 +11,11 @@ @AutoValue public abstract class CassandraRequest { - public static CassandraRequest create(Session session, String statement) { - return new AutoValue_CassandraRequest(session, statement); + public static CassandraRequest create(Session session, String queryText) { + return new AutoValue_CassandraRequest(session, queryText); } public abstract Session getSession(); - public abstract String getStatement(); + public abstract String getQueryText(); } diff --git a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraSqlAttributesGetter.java b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraSqlAttributesGetter.java index b91bfddf4af1..0ac75ae3778c 100644 --- a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraSqlAttributesGetter.java +++ b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraSqlAttributesGetter.java @@ -13,10 +13,11 @@ final class CassandraSqlAttributesGetter implements SqlClientAttributesGetter { @Override - public String getSystem(CassandraRequest request) { + public String getDbSystem(CassandraRequest request) { return DbIncubatingAttributes.DbSystemIncubatingValues.CASSANDRA; } + @Deprecated @Override @Nullable public String getUser(CassandraRequest request) { @@ -25,10 +26,11 @@ public String getUser(CassandraRequest request) { @Override @Nullable - public String getName(CassandraRequest request) { + public String getDbNamespace(CassandraRequest request) { return request.getSession().getKeyspace().map(CqlIdentifier::toString).orElse(null); } + @Deprecated @Override @Nullable public String getConnectionString(CassandraRequest request) { @@ -37,7 +39,7 @@ public String getConnectionString(CassandraRequest request) { @Override @Nullable - public String getRawStatement(CassandraRequest request) { - return request.getStatement(); + public String getRawQueryText(CassandraRequest request) { + return request.getQueryText(); } } diff --git a/instrumentation/cassandra/cassandra-4.4/library/build.gradle.kts b/instrumentation/cassandra/cassandra-4.4/library/build.gradle.kts index c0f0592742a9..963467200f5d 100644 --- a/instrumentation/cassandra/cassandra-4.4/library/build.gradle.kts +++ b/instrumentation/cassandra/cassandra-4.4/library/build.gradle.kts @@ -10,3 +10,13 @@ dependencies { testImplementation(project(":instrumentation:cassandra:cassandra-4.4:testing")) } + +tasks { + val testStableSemconv by registering(Test::class) { + jvmArgs("-Dotel.semconv-stability.opt-in=database") + } + + check { + dependsOn(testStableSemconv) + } +} diff --git a/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraRequest.java b/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraRequest.java index 021dfc7b6c6d..426321e146df 100644 --- a/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraRequest.java +++ b/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraRequest.java @@ -11,11 +11,11 @@ @AutoValue public abstract class CassandraRequest { - public static CassandraRequest create(Session session, String statement) { - return new AutoValue_CassandraRequest(session, statement); + public static CassandraRequest create(Session session, String queryText) { + return new AutoValue_CassandraRequest(session, queryText); } public abstract Session getSession(); - public abstract String getStatement(); + public abstract String getQueryText(); } diff --git a/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraSqlAttributesGetter.java b/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraSqlAttributesGetter.java index a9fcdf879abe..fb14a7abc93f 100644 --- a/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraSqlAttributesGetter.java +++ b/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraSqlAttributesGetter.java @@ -14,10 +14,11 @@ final class CassandraSqlAttributesGetter implements SqlClientAttributesGetter createInstrumenter( OpenTelemetry openTelemetry, boolean statementSanitizationEnabled) { CassandraSqlAttributesGetter attributesGetter = new CassandraSqlAttributesGetter(); diff --git a/instrumentation/cassandra/cassandra-4.4/testing/src/main/java/io/opentelemetry/testing/cassandra/v4_4/AbstractCassandra44Test.java b/instrumentation/cassandra/cassandra-4.4/testing/src/main/java/io/opentelemetry/testing/cassandra/v4_4/AbstractCassandra44Test.java index 46c1d9e6af0a..648ecb86a927 100644 --- a/instrumentation/cassandra/cassandra-4.4/testing/src/main/java/io/opentelemetry/testing/cassandra/v4_4/AbstractCassandra44Test.java +++ b/instrumentation/cassandra/cassandra-4.4/testing/src/main/java/io/opentelemetry/testing/cassandra/v4_4/AbstractCassandra44Test.java @@ -23,6 +23,7 @@ import com.datastax.oss.driver.api.core.CqlSession; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.cassandra.v4.common.AbstractCassandraTest; +import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil; import io.opentelemetry.semconv.NetworkAttributes; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; import java.util.stream.Stream; @@ -68,11 +69,18 @@ void reactiveTest(Parameter parameter) { equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, cassandraIp), equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort), equalTo(DB_SYSTEM, "cassandra"), - equalTo(DbIncubatingAttributes.DB_NAME, parameter.keyspace), equalTo( - DbIncubatingAttributes.DB_STATEMENT, + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_NAME), + parameter.keyspace), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), parameter.expectedStatement), - equalTo(DbIncubatingAttributes.DB_OPERATION, parameter.operation), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + parameter.operation), equalTo(DB_CASSANDRA_CONSISTENCY_LEVEL, "LOCAL_ONE"), equalTo(DB_CASSANDRA_COORDINATOR_DC, "datacenter1"), satisfies( @@ -84,7 +92,9 @@ void reactiveTest(Parameter parameter) { equalTo(DB_CASSANDRA_PAGE_SIZE, 5000), equalTo(DB_CASSANDRA_SPECULATIVE_EXECUTION_COUNT, 0), equalTo( - DbIncubatingAttributes.DB_CASSANDRA_TABLE, parameter.table)), + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_CASSANDRA_TABLE), + parameter.table)), span -> span.hasName("child") .hasKind(SpanKind.INTERNAL) diff --git a/instrumentation/clickhouse-client-0.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/clickhouse/ClickHouseAttributesGetter.java b/instrumentation/clickhouse-client-0.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/clickhouse/ClickHouseAttributesGetter.java index 9554a6fe6499..c8210b53b5b9 100644 --- a/instrumentation/clickhouse-client-0.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/clickhouse/ClickHouseAttributesGetter.java +++ b/instrumentation/clickhouse-client-0.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/clickhouse/ClickHouseAttributesGetter.java @@ -10,9 +10,10 @@ import javax.annotation.Nullable; final class ClickHouseAttributesGetter implements DbClientAttributesGetter { + @Nullable @Override - public String getStatement(ClickHouseDbRequest request) { + public String getDbQueryText(ClickHouseDbRequest request) { if (request.getSqlStatementInfo() == null) { return null; } @@ -21,7 +22,7 @@ public String getStatement(ClickHouseDbRequest request) { @Nullable @Override - public String getOperation(ClickHouseDbRequest request) { + public String getDbOperationName(ClickHouseDbRequest request) { if (request.getSqlStatementInfo() == null) { return null; } @@ -30,10 +31,11 @@ public String getOperation(ClickHouseDbRequest request) { @Nullable @Override - public String getSystem(ClickHouseDbRequest request) { + public String getDbSystem(ClickHouseDbRequest request) { return DbIncubatingAttributes.DbSystemIncubatingValues.CLICKHOUSE; } + @Deprecated @Nullable @Override public String getUser(ClickHouseDbRequest request) { @@ -42,7 +44,7 @@ public String getUser(ClickHouseDbRequest request) { @Nullable @Override - public String getName(ClickHouseDbRequest request) { + public String getDbNamespace(ClickHouseDbRequest request) { String dbName = request.getDbName(); if (dbName == null || dbName.isEmpty()) { return null; @@ -50,6 +52,7 @@ public String getName(ClickHouseDbRequest request) { return dbName; } + @Deprecated @Nullable @Override public String getConnectionString(ClickHouseDbRequest request) { diff --git a/instrumentation/couchbase/couchbase-2.0/javaagent/build.gradle.kts b/instrumentation/couchbase/couchbase-2.0/javaagent/build.gradle.kts index d6504dc00f43..13f696c31334 100644 --- a/instrumentation/couchbase/couchbase-2.0/javaagent/build.gradle.kts +++ b/instrumentation/couchbase/couchbase-2.0/javaagent/build.gradle.kts @@ -31,9 +31,19 @@ dependencies { latestDepTestLibrary("com.couchbase.client:java-client:2.5.+") } -tasks.withType().configureEach { - // required on jdk17 - jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED") - jvmArgs("--add-opens=java.base/java.lang.invoke=ALL-UNNAMED") - jvmArgs("-XX:+IgnoreUnrecognizedVMOptions") +tasks { + val testStableSemconv by registering(Test::class) { + jvmArgs("-Dotel.semconv-stability.opt-in=database") + } + + withType().configureEach { + // required on jdk17 + jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED") + jvmArgs("--add-opens=java.base/java.lang.invoke=ALL-UNNAMED") + jvmArgs("-XX:+IgnoreUnrecognizedVMOptions") + } + + check { + dependsOn(testStableSemconv) + } } diff --git a/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseAttributesGetter.java b/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseAttributesGetter.java index 6585b58622f8..5975b40d76e0 100644 --- a/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseAttributesGetter.java +++ b/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseAttributesGetter.java @@ -12,10 +12,11 @@ final class CouchbaseAttributesGetter implements DbClientAttributesGetter { @Override - public String getSystem(CouchbaseRequestInfo couchbaseRequest) { + public String getDbSystem(CouchbaseRequestInfo couchbaseRequest) { return DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE; } + @Deprecated @Override @Nullable public String getUser(CouchbaseRequestInfo couchbaseRequest) { @@ -24,10 +25,11 @@ public String getUser(CouchbaseRequestInfo couchbaseRequest) { @Override @Nullable - public String getName(CouchbaseRequestInfo couchbaseRequest) { + public String getDbNamespace(CouchbaseRequestInfo couchbaseRequest) { return couchbaseRequest.bucket(); } + @Deprecated @Override @Nullable public String getConnectionString(CouchbaseRequestInfo couchbaseRequest) { @@ -36,13 +38,13 @@ public String getConnectionString(CouchbaseRequestInfo couchbaseRequest) { @Override @Nullable - public String getStatement(CouchbaseRequestInfo couchbaseRequest) { + public String getDbQueryText(CouchbaseRequestInfo couchbaseRequest) { return couchbaseRequest.statement(); } @Override @Nullable - public String getOperation(CouchbaseRequestInfo couchbaseRequest) { + public String getDbOperationName(CouchbaseRequestInfo couchbaseRequest) { return couchbaseRequest.operation(); } } diff --git a/instrumentation/couchbase/couchbase-2.6/javaagent/build.gradle.kts b/instrumentation/couchbase/couchbase-2.6/javaagent/build.gradle.kts index 19428dc07b26..1c68002dfe1e 100644 --- a/instrumentation/couchbase/couchbase-2.6/javaagent/build.gradle.kts +++ b/instrumentation/couchbase/couchbase-2.6/javaagent/build.gradle.kts @@ -34,11 +34,21 @@ dependencies { latestDepTestLibrary("com.couchbase.client:java-client:2.+") } -tasks.withType().configureEach { - // TODO run tests both with and without experimental span attributes - jvmArgs("-Dotel.instrumentation.couchbase.experimental-span-attributes=true") +tasks { + val testStableSemconv by registering(Test::class) { + jvmArgs("-Dotel.semconv-stability.opt-in=database") + } + + withType().configureEach { + // TODO run tests both with and without experimental span attributes + jvmArgs("-Dotel.instrumentation.couchbase.experimental-span-attributes=true") - // required on jdk17 - jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED") - jvmArgs("-XX:+IgnoreUnrecognizedVMOptions") + // required on jdk17 + jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED") + jvmArgs("-XX:+IgnoreUnrecognizedVMOptions") + } + + check { + dependsOn(testStableSemconv) + } } diff --git a/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseAsyncClientTest.java b/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseAsyncClientTest.java index 2f0c39e85f1c..9ee67015fa4c 100644 --- a/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseAsyncClientTest.java +++ b/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseAsyncClientTest.java @@ -21,6 +21,7 @@ import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; import java.util.Collections; import java.util.concurrent.CompletableFuture; @@ -90,7 +91,10 @@ void hasBucket(BucketSettings bucketSettings) equalTo( DbIncubatingAttributes.DB_SYSTEM, DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE), - equalTo(DbIncubatingAttributes.DB_OPERATION, "Cluster.openBucket")), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "Cluster.openBucket")), span -> assertCouchbaseSpan(span, "ClusterManager.hasBucket") .hasParent(trace.getSpan(0)))); @@ -131,7 +135,10 @@ void upsert(BucketSettings bucketSettings) equalTo( DbIncubatingAttributes.DB_SYSTEM, DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE), - equalTo(DbIncubatingAttributes.DB_OPERATION, "Cluster.openBucket")), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "Cluster.openBucket")), span -> assertCouchbaseSpan(span, "Bucket.upsert", bucketSettings.name()) .hasParent(trace.getSpan(1)))); @@ -179,7 +186,10 @@ void upsertAndGet(BucketSettings bucketSettings) equalTo( DbIncubatingAttributes.DB_SYSTEM, DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE), - equalTo(DbIncubatingAttributes.DB_OPERATION, "Cluster.openBucket")), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "Cluster.openBucket")), span -> assertCouchbaseSpan(span, "Bucket.upsert", bucketSettings.name()) .hasParent(trace.getSpan(1)), @@ -224,7 +234,10 @@ void query() throws ExecutionException, InterruptedException, TimeoutException { equalTo( DbIncubatingAttributes.DB_SYSTEM, DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE), - equalTo(DbIncubatingAttributes.DB_OPERATION, "Cluster.openBucket")), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "Cluster.openBucket")), span -> assertCouchbaseSpan( span, diff --git a/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseClientTest.java b/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseClientTest.java index 6d7a561d9cd1..b142e2b592d3 100644 --- a/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseClientTest.java +++ b/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseClientTest.java @@ -22,6 +22,7 @@ import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; import java.util.Collections; import java.util.concurrent.atomic.AtomicReference; @@ -109,7 +110,10 @@ void upsertAndGet(BucketSettings bucketSettings) { equalTo( DbIncubatingAttributes.DB_SYSTEM, DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE), - equalTo(DbIncubatingAttributes.DB_OPERATION, "Cluster.openBucket"))), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "Cluster.openBucket"))), trace -> trace.hasSpansSatisfyingExactly( span -> span.hasName("someTrace").hasKind(SpanKind.INTERNAL).hasNoParent(), @@ -145,7 +149,10 @@ void query() { equalTo( DbIncubatingAttributes.DB_SYSTEM, DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE), - equalTo(DbIncubatingAttributes.DB_OPERATION, "Cluster.openBucket"))), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "Cluster.openBucket"))), trace -> trace.hasSpansSatisfyingExactly( span -> diff --git a/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseTest.java b/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseTest.java index c2dbf6fee235..1331c3e65b61 100644 --- a/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseTest.java +++ b/instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseTest.java @@ -19,6 +19,7 @@ import com.couchbase.mock.httpio.HttpServer; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.test.utils.PortUtils; +import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil; import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; @@ -125,13 +126,21 @@ protected SpanDataAssert assertCouchbaseSpan( DbIncubatingAttributes.DB_SYSTEM, DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE)); if (operation != null) { - assertions.add(equalTo(DbIncubatingAttributes.DB_OPERATION, operation)); + assertions.add( + equalTo( + SemconvStabilityUtil.getAttributeKey(DbIncubatingAttributes.DB_OPERATION), + operation)); } if (bucketName != null) { - assertions.add(equalTo(DbIncubatingAttributes.DB_NAME, bucketName)); + assertions.add( + equalTo( + SemconvStabilityUtil.getAttributeKey(DbIncubatingAttributes.DB_NAME), bucketName)); } if (statement != null) { - assertions.add(satisfies(DbIncubatingAttributes.DB_STATEMENT, s -> s.startsWith(statement))); + assertions.add( + satisfies( + SemconvStabilityUtil.getAttributeKey(DbIncubatingAttributes.DB_STATEMENT), + s -> s.startsWith(statement))); } assertions.addAll(couchbaseAttributes()); diff --git a/instrumentation/elasticsearch/elasticsearch-rest-common/library/src/main/java/io/opentelemetry/instrumentation/elasticsearch/rest/internal/ElasticsearchDbAttributesGetter.java b/instrumentation/elasticsearch/elasticsearch-rest-common/library/src/main/java/io/opentelemetry/instrumentation/elasticsearch/rest/internal/ElasticsearchDbAttributesGetter.java index 336cb6b3b5c8..fc72192dea24 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-common/library/src/main/java/io/opentelemetry/instrumentation/elasticsearch/rest/internal/ElasticsearchDbAttributesGetter.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-common/library/src/main/java/io/opentelemetry/instrumentation/elasticsearch/rest/internal/ElasticsearchDbAttributesGetter.java @@ -37,10 +37,11 @@ final class ElasticsearchDbAttributesGetter } @Override - public String getSystem(ElasticsearchRestRequest request) { + public String getDbSystem(ElasticsearchRestRequest request) { return ELASTICSEARCH; } + @Deprecated @Override @Nullable public String getUser(ElasticsearchRestRequest request) { @@ -49,10 +50,11 @@ public String getUser(ElasticsearchRestRequest request) { @Override @Nullable - public String getName(ElasticsearchRestRequest request) { + public String getDbNamespace(ElasticsearchRestRequest request) { return null; } + @Deprecated @Override @Nullable public String getConnectionString(ElasticsearchRestRequest request) { @@ -61,7 +63,7 @@ public String getConnectionString(ElasticsearchRestRequest request) { @Override @Nullable - public String getStatement(ElasticsearchRestRequest request) { + public String getDbQueryText(ElasticsearchRestRequest request) { ElasticsearchEndpointDefinition epDefinition = request.getEndpointDefinition(); HttpEntity httpEntity = request.getHttpEntity(); if (captureSearchQuery @@ -85,7 +87,7 @@ public String getStatement(ElasticsearchRestRequest request) { @Override @Nullable - public String getOperation(ElasticsearchRestRequest request) { + public String getDbOperationName(ElasticsearchRestRequest request) { ElasticsearchEndpointDefinition endpointDefinition = request.getEndpointDefinition(); return endpointDefinition != null ? endpointDefinition.getEndpointName() : null; } diff --git a/instrumentation/elasticsearch/elasticsearch-rest-common/library/src/main/java/io/opentelemetry/instrumentation/elasticsearch/rest/internal/ElasticsearchSpanNameExtractor.java b/instrumentation/elasticsearch/elasticsearch-rest-common/library/src/main/java/io/opentelemetry/instrumentation/elasticsearch/rest/internal/ElasticsearchSpanNameExtractor.java index 1faf90ee33e2..1fd48256c8d5 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-common/library/src/main/java/io/opentelemetry/instrumentation/elasticsearch/rest/internal/ElasticsearchSpanNameExtractor.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-common/library/src/main/java/io/opentelemetry/instrumentation/elasticsearch/rest/internal/ElasticsearchSpanNameExtractor.java @@ -21,7 +21,7 @@ public ElasticsearchSpanNameExtractor(ElasticsearchDbAttributesGetter dbAttribut @Override public String extract(ElasticsearchRestRequest elasticsearchRestRequest) { - String name = dbAttributesGetter.getOperation(elasticsearchRestRequest); + String name = dbAttributesGetter.getDbOperationName(elasticsearchRestRequest); return name != null ? name : elasticsearchRestRequest.getMethod(); } } diff --git a/instrumentation/elasticsearch/elasticsearch-transport-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticsearchTransportAttributesGetter.java b/instrumentation/elasticsearch/elasticsearch-transport-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticsearchTransportAttributesGetter.java index 90f2e2d09399..cbd713f364f6 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticsearchTransportAttributesGetter.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticsearchTransportAttributesGetter.java @@ -13,36 +13,38 @@ final class ElasticsearchTransportAttributesGetter implements DbClientAttributesGetter { @Override - public String getSystem(ElasticTransportRequest s) { + public String getDbSystem(ElasticTransportRequest request) { return DbIncubatingAttributes.DbSystemIncubatingValues.ELASTICSEARCH; } + @Deprecated @Override @Nullable - public String getUser(ElasticTransportRequest s) { + public String getUser(ElasticTransportRequest request) { return null; } @Override @Nullable - public String getName(ElasticTransportRequest s) { + public String getDbNamespace(ElasticTransportRequest request) { return null; } + @Deprecated @Override @Nullable - public String getConnectionString(ElasticTransportRequest s) { + public String getConnectionString(ElasticTransportRequest request) { return null; } @Override @Nullable - public String getStatement(ElasticTransportRequest s) { + public String getDbQueryText(ElasticTransportRequest request) { return null; } @Override - public String getOperation(ElasticTransportRequest action) { - return action.getAction().getClass().getSimpleName(); + public String getDbOperationName(ElasticTransportRequest request) { + return request.getAction().getClass().getSimpleName(); } } diff --git a/instrumentation/geode-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/geode/GeodeDbAttributesGetter.java b/instrumentation/geode-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/geode/GeodeDbAttributesGetter.java index b119ace0a9b9..0ce010e302ce 100644 --- a/instrumentation/geode-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/geode/GeodeDbAttributesGetter.java +++ b/instrumentation/geode-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/geode/GeodeDbAttributesGetter.java @@ -17,10 +17,11 @@ final class GeodeDbAttributesGetter implements DbClientAttributesGetter DB_NAME = AttributeKey.stringKey("db.name"); + private static final AttributeKey DB_NAMESPACE = AttributeKey.stringKey("db.namespace"); private static final AttributeKey DB_SYSTEM = AttributeKey.stringKey("db.system"); private static final AttributeKey DB_USER = AttributeKey.stringKey("db.user"); private static final AttributeKey DB_CONNECTION_STRING = @@ -39,10 +41,15 @@ public void onEnd( if (dbInfo == null) { return; } + if (SemconvStability.emitStableDatabaseSemconv()) { + internalSet(attributes, DB_NAMESPACE, getName(dbInfo)); + } + if (SemconvStability.emitOldDatabaseSemconv()) { + internalSet(attributes, DB_USER, dbInfo.getUser()); + internalSet(attributes, DB_NAME, getName(dbInfo)); + internalSet(attributes, DB_CONNECTION_STRING, dbInfo.getShortUrl()); + } internalSet(attributes, DB_SYSTEM, dbInfo.getSystem()); - internalSet(attributes, DB_USER, dbInfo.getUser()); - internalSet(attributes, DB_NAME, getName(dbInfo)); - internalSet(attributes, DB_CONNECTION_STRING, dbInfo.getShortUrl()); } private static String getName(DbInfo dbInfo) { diff --git a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/DbRequest.java b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/DbRequest.java index ef22562b3239..f1360d9b1cac 100644 --- a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/DbRequest.java +++ b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/DbRequest.java @@ -37,12 +37,11 @@ public static DbRequest create(Statement statement, String dbStatementString) { return create(extractDbInfo(connection), dbStatementString); } - public static DbRequest create(DbInfo dbInfo, String statement) { - return new AutoValue_DbRequest(dbInfo, statement); + public static DbRequest create(DbInfo dbInfo, String queryText) { + return new AutoValue_DbRequest(dbInfo, queryText); } public abstract DbInfo getDbInfo(); - @Nullable - public abstract String getStatement(); + public abstract String getQueryText(); } diff --git a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcAttributesGetter.java b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcAttributesGetter.java index ba04f3807395..b5623f4d99ce 100644 --- a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcAttributesGetter.java +++ b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcAttributesGetter.java @@ -17,10 +17,11 @@ public final class JdbcAttributesGetter implements SqlClientAttributesGetter { @Override - public String getSystem(JedisRequest request) { + public String getDbSystem(JedisRequest request) { return DbIncubatingAttributes.DbSystemIncubatingValues.REDIS; } + @Deprecated @Override @Nullable public String getUser(JedisRequest request) { @@ -23,22 +24,23 @@ public String getUser(JedisRequest request) { } @Override - public String getName(JedisRequest request) { + public String getDbNamespace(JedisRequest request) { return null; } + @Deprecated @Override public String getConnectionString(JedisRequest request) { return null; } @Override - public String getStatement(JedisRequest request) { + public String getDbQueryText(JedisRequest request) { return request.getStatement(); } @Override - public String getOperation(JedisRequest request) { + public String getDbOperationName(JedisRequest request) { return request.getOperation(); } } diff --git a/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisDbAttributesGetter.java b/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisDbAttributesGetter.java index 0c9c51064c2e..8cdd49df99e8 100644 --- a/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisDbAttributesGetter.java +++ b/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisDbAttributesGetter.java @@ -12,10 +12,11 @@ final class JedisDbAttributesGetter implements DbClientAttributesGetter { @Override - public String getSystem(JedisRequest request) { + public String getDbSystem(JedisRequest request) { return DbIncubatingAttributes.DbSystemIncubatingValues.REDIS; } + @Deprecated @Override @Nullable public String getUser(JedisRequest request) { @@ -23,22 +24,23 @@ public String getUser(JedisRequest request) { } @Override - public String getName(JedisRequest request) { + public String getDbNamespace(JedisRequest request) { return null; } + @Deprecated @Override public String getConnectionString(JedisRequest request) { return null; } @Override - public String getStatement(JedisRequest request) { + public String getDbQueryText(JedisRequest request) { return request.getStatement(); } @Override - public String getOperation(JedisRequest request) { + public String getDbOperationName(JedisRequest request) { return request.getOperation(); } } diff --git a/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectAttributesExtractor.java b/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectAttributesExtractor.java index f9bf36720db1..a37014f8373a 100644 --- a/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectAttributesExtractor.java +++ b/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectAttributesExtractor.java @@ -9,6 +9,7 @@ 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.incubating.DbIncubatingAttributes; import javax.annotation.Nullable; @@ -22,7 +23,13 @@ public void onStart(AttributesBuilder attributes, Context parentContext, RedisUR int database = redisUri.getDatabase(); if (database != 0) { - attributes.put(DbIncubatingAttributes.DB_REDIS_DATABASE_INDEX, (long) database); + if (SemconvStability.emitStableDatabaseSemconv()) { + attributes.put(DbIncubatingAttributes.DB_NAMESPACE, String.valueOf(database)); + } + + if (SemconvStability.emitOldDatabaseSemconv()) { + attributes.put(DbIncubatingAttributes.DB_REDIS_DATABASE_INDEX, (long) database); + } } } diff --git a/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceDbAttributesGetter.java b/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceDbAttributesGetter.java index 00e66c5d3197..b51d06bfea6b 100644 --- a/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceDbAttributesGetter.java +++ b/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceDbAttributesGetter.java @@ -13,10 +13,11 @@ final class LettuceDbAttributesGetter implements DbClientAttributesGetter> { @Override - public String getSystem(RedisCommand request) { + public String getDbSystem(RedisCommand request) { return DbIncubatingAttributes.DbSystemIncubatingValues.REDIS; } + @Deprecated @Override @Nullable public String getUser(RedisCommand request) { @@ -25,10 +26,11 @@ public String getUser(RedisCommand request) { @Override @Nullable - public String getName(RedisCommand request) { + public String getDbNamespace(RedisCommand request) { return null; } + @Deprecated @Override @Nullable public String getConnectionString(RedisCommand request) { @@ -36,12 +38,14 @@ public String getConnectionString(RedisCommand request) { } @Override - public String getStatement(RedisCommand request) { + @Nullable + public String getDbQueryText(RedisCommand request) { return null; } @Override - public String getOperation(RedisCommand request) { + @Nullable + public String getDbOperationName(RedisCommand request) { return request.getType().name(); } } diff --git a/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceConnectAttributesExtractor.java b/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceConnectAttributesExtractor.java index a3906a236630..3a4f3995bf81 100644 --- a/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceConnectAttributesExtractor.java +++ b/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceConnectAttributesExtractor.java @@ -9,6 +9,7 @@ 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.incubating.DbIncubatingAttributes; import javax.annotation.Nullable; @@ -22,7 +23,13 @@ public void onStart(AttributesBuilder attributes, Context parentContext, RedisUR int database = redisUri.getDatabase(); if (database != 0) { - attributes.put(DbIncubatingAttributes.DB_REDIS_DATABASE_INDEX, (long) database); + if (SemconvStability.emitStableDatabaseSemconv()) { + attributes.put(DbIncubatingAttributes.DB_NAMESPACE, String.valueOf(database)); + } + + if (SemconvStability.emitOldDatabaseSemconv()) { + attributes.put(DbIncubatingAttributes.DB_REDIS_DATABASE_INDEX, (long) database); + } } } diff --git a/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceDbAttributesGetter.java b/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceDbAttributesGetter.java index bfa7b876bc24..392f090aceaf 100644 --- a/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceDbAttributesGetter.java +++ b/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceDbAttributesGetter.java @@ -21,10 +21,11 @@ final class LettuceDbAttributesGetter implements DbClientAttributesGetter request) { + public String getDbSystem(RedisCommand request) { return DbIncubatingAttributes.DbSystemIncubatingValues.REDIS; } + @Deprecated @Override @Nullable public String getUser(RedisCommand request) { @@ -33,10 +34,11 @@ public String getUser(RedisCommand request) { @Override @Nullable - public String getName(RedisCommand request) { + public String getDbNamespace(RedisCommand request) { return null; } + @Deprecated @Override @Nullable public String getConnectionString(RedisCommand request) { @@ -44,7 +46,7 @@ public String getConnectionString(RedisCommand request) { } @Override - public String getStatement(RedisCommand request) { + public String getDbQueryText(RedisCommand request) { String command = LettuceInstrumentationUtil.getCommandName(request); List args = request.getArgs() == null @@ -54,7 +56,7 @@ public String getStatement(RedisCommand request) { } @Override - public String getOperation(RedisCommand request) { + public String getDbOperationName(RedisCommand request) { return request.getType().name(); } } diff --git a/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/OpenTelemetryTracing.java b/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/OpenTelemetryTracing.java index 2d7ce56ca7ce..f361ad8014e5 100644 --- a/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/OpenTelemetryTracing.java +++ b/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/OpenTelemetryTracing.java @@ -27,6 +27,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.incubator.semconv.db.RedisCommandSanitizer; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesExtractor; import io.opentelemetry.instrumentation.api.semconv.network.ServerAttributesExtractor; import java.net.InetSocketAddress; @@ -41,6 +42,7 @@ final class OpenTelemetryTracing implements Tracing { // copied from DbIncubatingAttributes private static final AttributeKey DB_SYSTEM = AttributeKey.stringKey("db.system"); private static final AttributeKey DB_STATEMENT = AttributeKey.stringKey("db.statement"); + private static final AttributeKey DB_QUERY_TEXT = AttributeKey.stringKey("db.query.text"); // copied from DbIncubatingAttributes.DbSystemIncubatingValues private static final String REDIS = "redis"; @@ -338,7 +340,12 @@ private void finish(Span span) { if (name != null) { String statement = sanitizer.sanitize(name, argsList != null ? argsList : splitArgs(argsString)); - span.setAttribute(DB_STATEMENT, statement); + if (SemconvStability.emitStableDatabaseSemconv()) { + span.setAttribute(DB_QUERY_TEXT, statement); + } + if (SemconvStability.emitOldDatabaseSemconv()) { + span.setAttribute(DB_STATEMENT, statement); + } } span.end(); } diff --git a/instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/MongoDbAttributesGetter.java b/instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/MongoDbAttributesGetter.java index dd01abc0c563..06ae481de250 100644 --- a/instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/MongoDbAttributesGetter.java +++ b/instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/MongoDbAttributesGetter.java @@ -50,10 +50,11 @@ class MongoDbAttributesGetter implements DbClientAttributesGetter { @Override public String extract(CommandStartedEvent event) { - String operation = dbAttributesGetter.getOperation(event); - String dbName = dbAttributesGetter.getName(event); + String operation = dbAttributesGetter.getDbOperationName(event); + String dbName = dbAttributesGetter.getDbNamespace(event); if (operation == null) { return dbName == null ? DEFAULT_SPAN_NAME : dbName; } diff --git a/instrumentation/opensearch/opensearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opensearch/rest/OpenSearchRestAttributesGetter.java b/instrumentation/opensearch/opensearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opensearch/rest/OpenSearchRestAttributesGetter.java index 005fdcfa1156..aadbeba17015 100644 --- a/instrumentation/opensearch/opensearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opensearch/rest/OpenSearchRestAttributesGetter.java +++ b/instrumentation/opensearch/opensearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opensearch/rest/OpenSearchRestAttributesGetter.java @@ -13,10 +13,11 @@ final class OpenSearchRestAttributesGetter implements DbClientAttributesGetter { @Override - public String getSystem(OpenSearchRestRequest request) { + public String getDbSystem(OpenSearchRestRequest request) { return DbIncubatingAttributes.DbSystemIncubatingValues.OPENSEARCH; } + @Deprecated @Override @Nullable public String getUser(OpenSearchRestRequest request) { @@ -25,10 +26,11 @@ public String getUser(OpenSearchRestRequest request) { @Override @Nullable - public String getName(OpenSearchRestRequest request) { + public String getDbNamespace(OpenSearchRestRequest request) { return null; } + @Deprecated @Override @Nullable public String getConnectionString(OpenSearchRestRequest request) { @@ -37,13 +39,13 @@ public String getConnectionString(OpenSearchRestRequest request) { @Override @Nullable - public String getStatement(OpenSearchRestRequest request) { + public String getDbQueryText(OpenSearchRestRequest request) { return request.getMethod() + " " + request.getOperation(); } @Override @Nullable - public String getOperation(OpenSearchRestRequest request) { + public String getDbOperationName(OpenSearchRestRequest request) { return request.getMethod(); } } diff --git a/instrumentation/r2dbc-1.0/library/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/internal/DbExecution.java b/instrumentation/r2dbc-1.0/library/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/internal/DbExecution.java index e968d07c0568..95284c985c33 100644 --- a/instrumentation/r2dbc-1.0/library/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/internal/DbExecution.java +++ b/instrumentation/r2dbc-1.0/library/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/internal/DbExecution.java @@ -34,7 +34,7 @@ public final class DbExecution { private final String host; private final Integer port; private final String connectionString; - private final String rawStatement; + private final String rawQueryText; private Context context; @@ -66,7 +66,7 @@ public DbExecution(QueryExecutionInfo queryInfo, ConnectionFactoryOptions factor protocol != null ? ":" + protocol : "", host != null ? "//" + host : "", port != null ? ":" + port : ""); - this.rawStatement = + this.rawQueryText = queryInfo.getQueries().stream().map(QueryInfo::getQuery).collect(Collectors.joining(";\n")); } @@ -94,8 +94,8 @@ public String getConnectionString() { return connectionString; } - public String getRawStatement() { - return rawStatement; + public String getRawQueryText() { + return rawQueryText; } public Context getContext() { @@ -127,7 +127,7 @@ public String toString() { + connectionString + '\'' + ", rawStatement='" - + rawStatement + + rawQueryText + '\'' + ", context=" + context diff --git a/instrumentation/r2dbc-1.0/library/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/internal/R2dbcSqlAttributesGetter.java b/instrumentation/r2dbc-1.0/library/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/internal/R2dbcSqlAttributesGetter.java index 6b7bcbb41ff6..9f0a259d5ae9 100644 --- a/instrumentation/r2dbc-1.0/library/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/internal/R2dbcSqlAttributesGetter.java +++ b/instrumentation/r2dbc-1.0/library/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/internal/R2dbcSqlAttributesGetter.java @@ -16,10 +16,11 @@ public enum R2dbcSqlAttributesGetter implements SqlClientAttributesGetter> { @Override - public String getSystem(RedisCommand redisCommand) { + public String getDbSystem(RedisCommand redisCommand) { return DbIncubatingAttributes.DbSystemIncubatingValues.REDIS; } + @Deprecated @Override @Nullable public String getUser(RedisCommand redisCommand) { @@ -26,10 +27,11 @@ public String getUser(RedisCommand redisCommand) { @Override @Nullable - public String getName(RedisCommand redisCommand) { + public String getDbNamespace(RedisCommand redisCommand) { return null; } + @Deprecated @Override @Nullable public String getConnectionString(RedisCommand redisCommand) { @@ -38,12 +40,12 @@ public String getConnectionString(RedisCommand redisCommand) { @Override @Nullable - public String getStatement(RedisCommand redisCommand) { + public String getDbQueryText(RedisCommand redisCommand) { return null; } @Override - public String getOperation(RedisCommand redisCommand) { + public String getDbOperationName(RedisCommand redisCommand) { return redisCommand.getClass().getSimpleName().toUpperCase(Locale.ROOT); } } diff --git a/instrumentation/redisson/redisson-3.17/javaagent/build.gradle.kts b/instrumentation/redisson/redisson-3.17/javaagent/build.gradle.kts index a37e1e87a96e..6e255116700d 100644 --- a/instrumentation/redisson/redisson-3.17/javaagent/build.gradle.kts +++ b/instrumentation/redisson/redisson-3.17/javaagent/build.gradle.kts @@ -24,7 +24,17 @@ dependencies { testImplementation(project(":instrumentation:redisson:redisson-common:testing")) } -tasks.test { - systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean) - usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) +tasks { + val testStableSemconv by registering(Test::class) { + jvmArgs("-Dotel.semconv-stability.opt-in=database") + } + + withType().configureEach { + systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean) + usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) + } + + check { + dependsOn(testStableSemconv) + } } diff --git a/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonDbAttributesGetter.java b/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonDbAttributesGetter.java index 706b06462d63..a2000c8e06c6 100644 --- a/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonDbAttributesGetter.java +++ b/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonDbAttributesGetter.java @@ -12,10 +12,11 @@ final class RedissonDbAttributesGetter implements DbClientAttributesGetter { @Override - public String getSystem(RedissonRequest request) { + public String getDbSystem(RedissonRequest request) { return DbIncubatingAttributes.DbSystemIncubatingValues.REDIS; } + @Deprecated @Nullable @Override public String getUser(RedissonRequest request) { @@ -24,23 +25,24 @@ public String getUser(RedissonRequest request) { @Nullable @Override - public String getName(RedissonRequest request) { + public String getDbNamespace(RedissonRequest request) { return null; } + @Deprecated @Override public String getConnectionString(RedissonRequest request) { return null; } @Override - public String getStatement(RedissonRequest request) { + public String getDbQueryText(RedissonRequest request) { return request.getStatement(); } @Nullable @Override - public String getOperation(RedissonRequest request) { + public String getDbOperationName(RedissonRequest request) { return request.getOperation(); } } diff --git a/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonAsyncClientTest.java b/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonAsyncClientTest.java index 96414293ecc2..2a0936aee1de 100644 --- a/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonAsyncClientTest.java +++ b/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonAsyncClientTest.java @@ -16,6 +16,7 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil; import io.opentelemetry.semconv.NetworkAttributes; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; import java.io.Serializable; @@ -120,8 +121,14 @@ void futureSet() throws ExecutionException, InterruptedException, TimeoutExcepti equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip), equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), - equalTo(DbIncubatingAttributes.DB_STATEMENT, "SET foo ?"), - equalTo(DbIncubatingAttributes.DB_OPERATION, "SET")))); + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + "SET foo ?"), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "SET")))); } @Test @@ -153,8 +160,14 @@ void futureWhenComplete() throws ExecutionException, InterruptedException, Timeo equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip), equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), - equalTo(DbIncubatingAttributes.DB_STATEMENT, "SADD set1 ?"), - equalTo(DbIncubatingAttributes.DB_OPERATION, "SADD")) + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + "SADD set1 ?"), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "SADD")) .hasParent(trace.getSpan(0)), span -> span.hasName("callback").hasKind(INTERNAL).hasParent(trace.getSpan(0)))); } @@ -227,7 +240,10 @@ void atomicBatchCommand() throws ExecutionException, InterruptedException, Timeo equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip), equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), - equalTo(DbIncubatingAttributes.DB_STATEMENT, "MULTI;SET batch1 ?")) + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + "MULTI;SET batch1 ?")) .hasParent(trace.getSpan(0)), span -> span.hasName("SET") @@ -237,8 +253,14 @@ void atomicBatchCommand() throws ExecutionException, InterruptedException, Timeo equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip), equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), - equalTo(DbIncubatingAttributes.DB_STATEMENT, "SET batch2 ?"), - equalTo(DbIncubatingAttributes.DB_OPERATION, "SET")) + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + "SET batch2 ?"), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "SET")) .hasParent(trace.getSpan(0)), span -> span.hasName("EXEC") @@ -248,8 +270,14 @@ void atomicBatchCommand() throws ExecutionException, InterruptedException, Timeo equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip), equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), - equalTo(DbIncubatingAttributes.DB_STATEMENT, "EXEC"), - equalTo(DbIncubatingAttributes.DB_OPERATION, "EXEC")) + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + "EXEC"), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "EXEC")) .hasParent(trace.getSpan(0)), span -> span.hasName("callback").hasKind(INTERNAL).hasParent(trace.getSpan(0)))); } diff --git a/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonClientTest.java b/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonClientTest.java index 2ceb6109c02b..0c9278a6cde2 100644 --- a/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonClientTest.java +++ b/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonClientTest.java @@ -16,6 +16,7 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil; import io.opentelemetry.sdk.testing.assertj.TraceAssert; import io.opentelemetry.semconv.NetworkAttributes; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; @@ -123,8 +124,14 @@ void stringCommand() { equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip), equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), - equalTo(DbIncubatingAttributes.DB_STATEMENT, "SET foo ?"), - equalTo(DbIncubatingAttributes.DB_OPERATION, "SET"))), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + "SET foo ?"), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "SET"))), trace -> trace.hasSpansSatisfyingExactly( span -> @@ -135,8 +142,14 @@ void stringCommand() { equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip), equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), - equalTo(DbIncubatingAttributes.DB_STATEMENT, "GET foo"), - equalTo(DbIncubatingAttributes.DB_OPERATION, "GET")))); + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + "GET foo"), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "GET")))); } @Test @@ -162,7 +175,8 @@ void batchCommand() equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), equalTo( - DbIncubatingAttributes.DB_STATEMENT, + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), "SET batch1 ?;SET batch2 ?")))); } @@ -203,7 +217,10 @@ void atomicBatchCommand() { equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip), equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), - equalTo(DbIncubatingAttributes.DB_STATEMENT, "MULTI;SET batch1 ?")) + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + "MULTI;SET batch1 ?")) .hasParent(trace.getSpan(0)), span -> span.hasName("SET") @@ -213,8 +230,14 @@ void atomicBatchCommand() { equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip), equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), - equalTo(DbIncubatingAttributes.DB_STATEMENT, "SET batch2 ?"), - equalTo(DbIncubatingAttributes.DB_OPERATION, "SET")) + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + "SET batch2 ?"), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "SET")) .hasParent(trace.getSpan(0)), span -> span.hasName("EXEC") @@ -224,8 +247,14 @@ void atomicBatchCommand() { equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip), equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), - equalTo(DbIncubatingAttributes.DB_STATEMENT, "EXEC"), - equalTo(DbIncubatingAttributes.DB_OPERATION, "EXEC")) + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + "EXEC"), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "EXEC")) .hasParent(trace.getSpan(0)))); } @@ -246,8 +275,14 @@ void listCommand() { equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip), equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), - equalTo(DbIncubatingAttributes.DB_STATEMENT, "RPUSH list1 ?"), - equalTo(DbIncubatingAttributes.DB_OPERATION, "RPUSH")) + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + "RPUSH list1 ?"), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "RPUSH")) .hasNoParent())); } @@ -272,9 +307,13 @@ void hashCommand() { equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), equalTo( - DbIncubatingAttributes.DB_STATEMENT, + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), String.format("EVAL %s 1 map1 ? ?", script)), - equalTo(DbIncubatingAttributes.DB_OPERATION, "EVAL"))), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "EVAL"))), trace -> trace.hasSpansSatisfyingExactly( span -> @@ -285,8 +324,14 @@ void hashCommand() { equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip), equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), - equalTo(DbIncubatingAttributes.DB_STATEMENT, "HGET map1 key1"), - equalTo(DbIncubatingAttributes.DB_OPERATION, "HGET")))); + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + "HGET map1 key1"), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "HGET")))); } @Test @@ -306,8 +351,14 @@ void setCommand() { equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip), equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), - equalTo(DbIncubatingAttributes.DB_STATEMENT, "SADD set1 ?"), - equalTo(DbIncubatingAttributes.DB_OPERATION, "SADD")))); + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + "SADD set1 ?"), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "SADD")))); } @Test @@ -335,8 +386,13 @@ void sortedSetCommand() equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), equalTo( - DbIncubatingAttributes.DB_STATEMENT, "ZADD sort_set1 ? ? ? ? ? ?"), - equalTo(DbIncubatingAttributes.DB_OPERATION, "ZADD")))); + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + "ZADD sort_set1 ? ? ? ? ? ?"), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "ZADD")))); } private static void invokeAddAll(RScoredSortedSet object, Map arg) @@ -361,8 +417,14 @@ void atomicLongCommand() { equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip), equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), - equalTo(DbIncubatingAttributes.DB_STATEMENT, "INCR AtomicLong"), - equalTo(DbIncubatingAttributes.DB_OPERATION, "INCR")))); + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), + "INCR AtomicLong"), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "INCR")))); } @Test @@ -387,9 +449,13 @@ void lockCommand() { equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip), equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), - equalTo(DbIncubatingAttributes.DB_OPERATION, "EVAL"), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "EVAL"), satisfies( - DbIncubatingAttributes.DB_STATEMENT, + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), stringAssert -> stringAssert.startsWith("EVAL"))))); traceAsserts.add( trace -> @@ -402,9 +468,13 @@ void lockCommand() { equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip), equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), - equalTo(DbIncubatingAttributes.DB_OPERATION, "EVAL"), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "EVAL"), satisfies( - DbIncubatingAttributes.DB_STATEMENT, + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), stringAssert -> stringAssert.startsWith("EVAL"))))); if (lockHas3Traces()) { traceAsserts.add( @@ -418,9 +488,13 @@ void lockCommand() { equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip), equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), - equalTo(DbIncubatingAttributes.DB_OPERATION, "DEL"), + equalTo( + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_OPERATION), + "DEL"), satisfies( - DbIncubatingAttributes.DB_STATEMENT, + SemconvStabilityUtil.getAttributeKey( + DbIncubatingAttributes.DB_STATEMENT), stringAssert -> stringAssert.startsWith("DEL"))))); } diff --git a/instrumentation/spymemcached-2.12/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spymemcached/SpymemcachedAttributesGetter.java b/instrumentation/spymemcached-2.12/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spymemcached/SpymemcachedAttributesGetter.java index b5778dc96a32..086c2dc65693 100644 --- a/instrumentation/spymemcached-2.12/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spymemcached/SpymemcachedAttributesGetter.java +++ b/instrumentation/spymemcached-2.12/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spymemcached/SpymemcachedAttributesGetter.java @@ -11,10 +11,11 @@ public class SpymemcachedAttributesGetter implements DbClientAttributesGetter { @Override - public String getSystem(SpymemcachedRequest spymemcachedRequest) { + public String getDbSystem(SpymemcachedRequest spymemcachedRequest) { return "memcached"; } + @Deprecated @Override @Nullable public String getUser(SpymemcachedRequest spymemcachedRequest) { @@ -23,10 +24,11 @@ public String getUser(SpymemcachedRequest spymemcachedRequest) { @Override @Nullable - public String getName(SpymemcachedRequest spymemcachedRequest) { + public String getDbNamespace(SpymemcachedRequest spymemcachedRequest) { return null; } + @Deprecated @Override @Nullable public String getConnectionString(SpymemcachedRequest spymemcachedRequest) { @@ -35,13 +37,13 @@ public String getConnectionString(SpymemcachedRequest spymemcachedRequest) { @Override @Nullable - public String getStatement(SpymemcachedRequest spymemcachedRequest) { + public String getDbQueryText(SpymemcachedRequest spymemcachedRequest) { return null; } @Override @Nullable - public String getOperation(SpymemcachedRequest spymemcachedRequest) { + public String getDbOperationName(SpymemcachedRequest spymemcachedRequest) { return spymemcachedRequest.dbOperation(); } } diff --git a/instrumentation/vertx/vertx-redis-client-4.0/javaagent/build.gradle.kts b/instrumentation/vertx/vertx-redis-client-4.0/javaagent/build.gradle.kts index 748df2ab83cf..0199413110d6 100644 --- a/instrumentation/vertx/vertx-redis-client-4.0/javaagent/build.gradle.kts +++ b/instrumentation/vertx/vertx-redis-client-4.0/javaagent/build.gradle.kts @@ -24,4 +24,12 @@ tasks { withType().configureEach { usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) } + + val testStableSemconv by registering(Test::class) { + jvmArgs("-Dotel.semconv-stability.opt-in=database") + } + + check { + dependsOn(testStableSemconv) + } } diff --git a/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientAttributesExtractor.java b/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientAttributesExtractor.java index 463558d2d5ad..b8fa8fd3796b 100644 --- a/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientAttributesExtractor.java +++ b/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientAttributesExtractor.java @@ -10,6 +10,7 @@ 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.incubating.DbIncubatingAttributes; import javax.annotation.Nullable; @@ -21,8 +22,10 @@ enum VertxRedisClientAttributesExtractor @Override public void onStart( AttributesBuilder attributes, Context parentContext, VertxRedisClientRequest request) { - internalSet( - attributes, DbIncubatingAttributes.DB_REDIS_DATABASE_INDEX, request.getDatabaseIndex()); + if (SemconvStability.emitOldDatabaseSemconv()) { + internalSet( + attributes, DbIncubatingAttributes.DB_REDIS_DATABASE_INDEX, request.getDatabaseIndex()); + } } @Override diff --git a/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientAttributesGetter.java b/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientAttributesGetter.java index 46fc0526cda2..928ca141b154 100644 --- a/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientAttributesGetter.java +++ b/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientAttributesGetter.java @@ -7,6 +7,7 @@ import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesGetter; import io.opentelemetry.instrumentation.api.incubator.semconv.db.RedisCommandSanitizer; +import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; import javax.annotation.Nullable; @@ -19,10 +20,11 @@ public enum VertxRedisClientAttributesGetter RedisCommandSanitizer.create(AgentCommonConfig.get().isStatementSanitizationEnabled()); @Override - public String getSystem(VertxRedisClientRequest request) { + public String getDbSystem(VertxRedisClientRequest request) { return DbIncubatingAttributes.DbSystemIncubatingValues.REDIS; } + @Deprecated @Override @Nullable public String getUser(VertxRedisClientRequest request) { @@ -31,10 +33,14 @@ public String getUser(VertxRedisClientRequest request) { @Override @Nullable - public String getName(VertxRedisClientRequest request) { + public String getDbNamespace(VertxRedisClientRequest request) { + if (SemconvStability.emitStableDatabaseSemconv()) { + return String.valueOf(request.getDatabaseIndex()); + } return null; } + @Deprecated @Override @Nullable public String getConnectionString(VertxRedisClientRequest request) { @@ -42,13 +48,13 @@ public String getConnectionString(VertxRedisClientRequest request) { } @Override - public String getStatement(VertxRedisClientRequest request) { + public String getDbQueryText(VertxRedisClientRequest request) { return sanitizer.sanitize(request.getCommand(), request.getArgs()); } @Nullable @Override - public String getOperation(VertxRedisClientRequest request) { + public String getDbOperationName(VertxRedisClientRequest request) { return request.getCommand(); } } diff --git a/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientSingletons.java b/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientSingletons.java index b5164522897c..64d1942e99e8 100644 --- a/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientSingletons.java +++ b/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientSingletons.java @@ -9,7 +9,6 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesExtractor; -import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientSpanNameExtractor; import io.opentelemetry.instrumentation.api.incubator.semconv.net.PeerServiceAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; @@ -36,8 +35,10 @@ public final class VertxRedisClientSingletons { VirtualField.find(RedisStandaloneConnection.class, RedisURI.class); static { + // Redis semantic conventions don't follow the regular pattern of adding the db.namespace to + // the span name SpanNameExtractor spanNameExtractor = - DbClientSpanNameExtractor.create(VertxRedisClientAttributesGetter.INSTANCE); + VertxRedisClientRequest::getCommand; InstrumenterBuilder builder = Instrumenter.builder( diff --git a/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientTest.java b/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientTest.java index a49a6acfb611..5df51cf79108 100644 --- a/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientTest.java +++ b/instrumentation/vertx/vertx-redis-client-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/redis/VertxRedisClientTest.java @@ -8,7 +8,9 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; @@ -201,15 +203,29 @@ void commandWithNoArguments() throws Exception { @SuppressWarnings("deprecation") // using deprecated semconv private static AttributeAssertion[] redisSpanAttributes(String operation, String statement) { - return new AttributeAssertion[] { - equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), - equalTo(DbIncubatingAttributes.DB_STATEMENT, statement), - equalTo(DbIncubatingAttributes.DB_OPERATION, operation), - equalTo(DbIncubatingAttributes.DB_REDIS_DATABASE_INDEX, 1), - equalTo(ServerAttributes.SERVER_ADDRESS, host), - equalTo(ServerAttributes.SERVER_PORT, port), - equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), - equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip) - }; + // not testing database/dup + if (SemconvStability.emitStableDatabaseSemconv()) { + return new AttributeAssertion[] { + equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), + equalTo(AttributeKey.stringKey("db.query.text"), statement), + equalTo(AttributeKey.stringKey("db.operation.name"), operation), + equalTo(AttributeKey.stringKey("db.namespace"), "1"), + equalTo(ServerAttributes.SERVER_ADDRESS, host), + equalTo(ServerAttributes.SERVER_PORT, port), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip) + }; + } else { + return new AttributeAssertion[] { + equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"), + equalTo(DbIncubatingAttributes.DB_STATEMENT, statement), + equalTo(DbIncubatingAttributes.DB_OPERATION, operation), + equalTo(DbIncubatingAttributes.DB_REDIS_DATABASE_INDEX, 1), + equalTo(ServerAttributes.SERVER_ADDRESS, host), + equalTo(ServerAttributes.SERVER_PORT, port), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip) + }; + } } } diff --git a/instrumentation/vertx/vertx-sql-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/sql/VertxSqlClientAttributesGetter.java b/instrumentation/vertx/vertx-sql-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/sql/VertxSqlClientAttributesGetter.java index 4fa4a6ea5359..92c27b4ddb19 100644 --- a/instrumentation/vertx/vertx-sql-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/sql/VertxSqlClientAttributesGetter.java +++ b/instrumentation/vertx/vertx-sql-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/sql/VertxSqlClientAttributesGetter.java @@ -13,10 +13,11 @@ public enum VertxSqlClientAttributesGetter INSTANCE; @Override - public String getSystem(VertxSqlClientRequest request) { + public String getDbSystem(VertxSqlClientRequest request) { return null; } + @Deprecated @Override @Nullable public String getUser(VertxSqlClientRequest request) { @@ -25,10 +26,11 @@ public String getUser(VertxSqlClientRequest request) { @Override @Nullable - public String getName(VertxSqlClientRequest request) { + public String getDbNamespace(VertxSqlClientRequest request) { return request.getDatabase(); } + @Deprecated @Override @Nullable public String getConnectionString(VertxSqlClientRequest request) { @@ -37,7 +39,7 @@ public String getConnectionString(VertxSqlClientRequest request) { @Override @Nullable - public String getRawStatement(VertxSqlClientRequest request) { - return request.getStatement(); + public String getRawQueryText(VertxSqlClientRequest request) { + return request.getQueryText(); } } diff --git a/instrumentation/vertx/vertx-sql-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/sql/VertxSqlClientRequest.java b/instrumentation/vertx/vertx-sql-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/sql/VertxSqlClientRequest.java index d644d8b9a742..6355fd3f6e24 100644 --- a/instrumentation/vertx/vertx-sql-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/sql/VertxSqlClientRequest.java +++ b/instrumentation/vertx/vertx-sql-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/sql/VertxSqlClientRequest.java @@ -8,16 +8,16 @@ import io.vertx.sqlclient.SqlConnectOptions; public final class VertxSqlClientRequest { - private final String statement; + private final String queryText; private final SqlConnectOptions sqlConnectOptions; - public VertxSqlClientRequest(String statement, SqlConnectOptions sqlConnectOptions) { - this.statement = statement; + public VertxSqlClientRequest(String queryText, SqlConnectOptions sqlConnectOptions) { + this.queryText = queryText; this.sqlConnectOptions = sqlConnectOptions; } - public String getStatement() { - return statement; + public String getQueryText() { + return queryText; } public String getUser() { diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/db/SemconvStabilityUtil.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/db/SemconvStabilityUtil.java new file mode 100644 index 000000000000..06d25bd9ec79 --- /dev/null +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/db/SemconvStabilityUtil.java @@ -0,0 +1,56 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.testing.junit.db; + +import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_CASSANDRA_TABLE; +import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_COSMOSDB_CONTAINER; +import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_MONGODB_COLLECTION; +import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_NAME; +import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION; +import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SQL_TABLE; +import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_STATEMENT; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.instrumentation.api.internal.SemconvStability; +import java.util.HashMap; +import java.util.Map; + +// until old database semconv are dropped in 3.0 +public class SemconvStabilityUtil { + + private static final AttributeKey DB_NAMESPACE = AttributeKey.stringKey("db.namespace"); + private static final AttributeKey DB_QUERY_TEXT = AttributeKey.stringKey("db.query.text"); + private static final AttributeKey DB_OPERATION_NAME = + AttributeKey.stringKey("db.operation.name"); + private static final AttributeKey DB_COLLECTION_NAME = + AttributeKey.stringKey("db.collection.name"); + + private static final Map, AttributeKey> oldToNewMap = buildMap(); + + @SuppressWarnings("deprecation") // using deprecated semconv + private static Map, AttributeKey> buildMap() { + Map, AttributeKey> map = new HashMap<>(); + map.put(DB_NAME, DB_NAMESPACE); + map.put(DB_STATEMENT, DB_QUERY_TEXT); + map.put(DB_OPERATION, DB_OPERATION_NAME); + map.put(DB_SQL_TABLE, DB_COLLECTION_NAME); + map.put(DB_CASSANDRA_TABLE, DB_COLLECTION_NAME); + map.put(DB_MONGODB_COLLECTION, DB_COLLECTION_NAME); + map.put(DB_COSMOSDB_CONTAINER, DB_COLLECTION_NAME); + return map; + } + + private SemconvStabilityUtil() {} + + @SuppressWarnings("unchecked") + public static AttributeKey getAttributeKey(AttributeKey oldKey) { + // not testing database/dup + if (SemconvStability.emitStableDatabaseSemconv()) { + return (AttributeKey) oldToNewMap.get(oldKey); + } + return oldKey; + } +}