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 279f3171d192..18a2cfd8434d 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 @@ -12,6 +12,11 @@ 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 io.opentelemetry.instrumentation.api.semconv.network.ServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.semconv.network.internal.InternalNetworkAttributesExtractor; +import javax.annotation.Nullable; /** * Extractor of - extends DbClientCommonAttributesExtractor< - REQUEST, RESPONSE, DbClientAttributesGetter> { + implements AttributesExtractor, SpanKeyProvider { // 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 = + AttributeKey.stringKey("db.connection_string"); private static final AttributeKey DB_STATEMENT = AttributeKey.stringKey("db.statement"); private static final AttributeKey DB_QUERY_TEXT = AttributeKey.stringKey("db.query.text"); @@ -33,27 +43,59 @@ public final class DbClientAttributesExtractor private static final AttributeKey DB_OPERATION_NAME = AttributeKey.stringKey("db.operation.name"); + private final DbClientAttributesGetter getter; + private final InternalNetworkAttributesExtractor internalNetworkExtractor; + private final ServerAttributesExtractor serverAttributesExtractor; + /** Creates the database client attributes extractor with default configuration. */ public static AttributesExtractor create( - DbClientAttributesGetter getter) { + DbClientAttributesGetter getter) { return new DbClientAttributesExtractor<>(getter); } - DbClientAttributesExtractor(DbClientAttributesGetter getter) { - super(getter); + DbClientAttributesExtractor(DbClientAttributesGetter getter) { + this.getter = getter; + internalNetworkExtractor = + new InternalNetworkAttributesExtractor<>( + getter, SemconvStability.emitOldDatabaseSemconv(), false); + serverAttributesExtractor = ServerAttributesExtractor.create(getter); } @Override + @SuppressWarnings("deprecation") // using deprecated semconv public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { - super.onStart(attributes, parentContext, request); - + internalSet(attributes, DB_SYSTEM, getter.getDbSystem(request)); if (SemconvStability.emitStableDatabaseSemconv()) { + internalSet(attributes, DB_NAMESPACE, getter.getDbNamespace(request)); internalSet(attributes, DB_QUERY_TEXT, getter.getDbQueryText(request)); internalSet(attributes, DB_OPERATION_NAME, getter.getDbOperationName(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)); internalSet(attributes, DB_STATEMENT, getter.getDbQueryText(request)); internalSet(attributes, DB_OPERATION, getter.getDbOperationName(request)); } + serverAttributesExtractor.onStart(attributes, parentContext, request); + } + + @Override + public void onEnd( + AttributesBuilder attributes, + Context context, + REQUEST request, + @Nullable RESPONSE response, + @Nullable Throwable error) { + internalNetworkExtractor.onEnd(attributes, request, response); + } + + /** + * This method is internal and is hence not for public use. Its API is unstable and can change at + * any time. + */ + @Override + public SpanKey internalGetSpanKey() { + return SpanKey.DB_CLIENT; } } 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 ddf9f8f07a1a..2f86a88b4976 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 @@ -5,6 +5,8 @@ package io.opentelemetry.instrumentation.api.incubator.semconv.db; +import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter; +import io.opentelemetry.instrumentation.api.semconv.network.ServerAttributesGetter; import javax.annotation.Nullable; /** @@ -18,7 +20,43 @@ * from the attribute methods, but implement as many as possible for best compliance with the * OpenTelemetry specification. */ -public interface DbClientAttributesGetter extends DbClientCommonAttributesGetter { +public interface DbClientAttributesGetter + extends NetworkAttributesGetter, ServerAttributesGetter { + + @Deprecated + @Nullable + 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 + default String getDbNamespace(REQUEST request) { + return getName(request); + } + + @Deprecated + @Nullable + String getConnectionString(REQUEST request); /** * @deprecated Use {@link #getDbQueryText(REQUEST)} instead. 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 deleted file mode 100644 index 9cbf4fb97895..000000000000 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientCommonAttributesExtractor.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.incubator.semconv.db; - -import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet; - -import io.opentelemetry.api.common.AttributeKey; -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; - -abstract class DbClientCommonAttributesExtractor< - REQUEST, RESPONSE, GETTER extends DbClientCommonAttributesGetter> - implements AttributesExtractor, SpanKeyProvider { - - // 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 = - AttributeKey.stringKey("db.connection_string"); - - final GETTER getter; - - DbClientCommonAttributesExtractor(GETTER getter) { - 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.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 - public final void onEnd( - AttributesBuilder attributes, - Context context, - REQUEST request, - @Nullable RESPONSE response, - @Nullable Throwable error) {} - - /** - * This method is internal and is hence not for public use. Its API is unstable and can change at - * any time. - */ - @Override - public SpanKey internalGetSpanKey() { - return SpanKey.DB_CLIENT; - } -} 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 deleted file mode 100644 index bc9a335f4e76..000000000000 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientCommonAttributesGetter.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.incubator.semconv.db; - -import javax.annotation.Nullable; - -/** An interface for getting attributes common to database clients. */ -public interface DbClientCommonAttributesGetter { - - @Deprecated - @Nullable - 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 - 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 58eb91b08b09..8da6d2c50170 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 @@ -18,7 +18,7 @@ public abstract class DbClientSpanNameExtractor implements SpanNameExtr * @see DbClientAttributesGetter#getDbNamespace(Object) used to extract {@code }. */ public static SpanNameExtractor create( - DbClientAttributesGetter getter) { + DbClientAttributesGetter getter) { return new GenericDbClientSpanNameExtractor<>(getter); } @@ -32,7 +32,7 @@ public static SpanNameExtractor create( * procedure name. */ public static SpanNameExtractor create( - SqlClientAttributesGetter getter) { + SqlClientAttributesGetter getter) { return new SqlClientSpanNameExtractor<>(getter); } @@ -65,9 +65,9 @@ protected String computeSpanName(String dbName, String operation, String mainIde private static final class GenericDbClientSpanNameExtractor extends DbClientSpanNameExtractor { - private final DbClientAttributesGetter getter; + private final DbClientAttributesGetter getter; - private GenericDbClientSpanNameExtractor(DbClientAttributesGetter getter) { + private GenericDbClientSpanNameExtractor(DbClientAttributesGetter getter) { this.getter = getter; } @@ -85,9 +85,9 @@ private static final class SqlClientSpanNameExtractor // a dedicated sanitizer just for extracting the operation and identifier name private static final SqlStatementSanitizer sanitizer = SqlStatementSanitizer.create(true); - private final SqlClientAttributesGetter getter; + private final SqlClientAttributesGetter getter; - private SqlClientSpanNameExtractor(SqlClientAttributesGetter getter) { + private SqlClientSpanNameExtractor(SqlClientAttributesGetter getter) { this.getter = getter; } 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 fc5f29efe81b..e8f4a7b6ef99 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 @@ -12,6 +12,9 @@ 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; /** * Extractor of - extends DbClientCommonAttributesExtractor< - REQUEST, RESPONSE, SqlClientAttributesGetter> { + implements AttributesExtractor, SpanKeyProvider { // copied from DbIncubatingAttributes private static final AttributeKey DB_OPERATION = AttributeKey.stringKey("db.operation"); @@ -38,7 +40,7 @@ public final class SqlClientAttributesExtractor /** Creates the SQL client attributes extractor with default configuration. */ public static AttributesExtractor create( - SqlClientAttributesGetter getter) { + SqlClientAttributesGetter getter) { return SqlClientAttributesExtractor.builder(getter).build(); } @@ -47,7 +49,7 @@ public static AttributesExtractor create( * client attributes extractor. */ public static SqlClientAttributesExtractorBuilder builder( - SqlClientAttributesGetter getter) { + SqlClientAttributesGetter getter) { return new SqlClientAttributesExtractorBuilder<>(getter); } @@ -58,18 +60,22 @@ public static SqlClientAttributesExtractorBuilder oldSemconvTableAttribute; private final boolean statementSanitizationEnabled; + private final AttributesExtractor delegate; + private final SqlClientAttributesGetter getter; + SqlClientAttributesExtractor( - SqlClientAttributesGetter getter, + SqlClientAttributesGetter getter, AttributeKey oldSemconvTableAttribute, boolean statementSanitizationEnabled) { - super(getter); + this.delegate = DbClientAttributesExtractor.create(getter); this.oldSemconvTableAttribute = oldSemconvTableAttribute; this.statementSanitizationEnabled = statementSanitizationEnabled; + this.getter = getter; } @Override public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { - super.onStart(attributes, parentContext, request); + delegate.onStart(attributes, parentContext, request); String rawQueryText = getter.getRawQueryText(request); SqlStatementInfo sanitizedStatement = sanitizer.sanitize(rawQueryText); @@ -97,4 +103,23 @@ public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST } } } + + @Override + public void onEnd( + AttributesBuilder attributes, + Context context, + REQUEST request, + @Nullable RESPONSE response, + @Nullable Throwable error) { + delegate.onEnd(attributes, context, request, response, error); + } + + /** + * This method is internal and is hence not for public use. Its API is unstable and can change at + * any time. + */ + @Override + public SpanKey internalGetSpanKey() { + return SpanKey.DB_CLIENT; + } } diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractorBuilder.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractorBuilder.java index 4e7672e94285..43cbc63062bd 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractorBuilder.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractorBuilder.java @@ -17,11 +17,11 @@ public final class SqlClientAttributesExtractorBuilder { // copied from DbIncubatingAttributes private static final AttributeKey DB_SQL_TABLE = AttributeKey.stringKey("db.sql.table"); - final SqlClientAttributesGetter getter; + final SqlClientAttributesGetter getter; AttributeKey oldSemconvTableAttribute = DB_SQL_TABLE; boolean statementSanitizationEnabled = true; - SqlClientAttributesExtractorBuilder(SqlClientAttributesGetter getter) { + SqlClientAttributesExtractorBuilder(SqlClientAttributesGetter getter) { this.getter = getter; } 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 d0817d63e460..b275faa8199a 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 @@ -18,8 +18,8 @@ * from the attribute methods, but implement as many as possible for best compliance with the * OpenTelemetry specification. */ -public interface SqlClientAttributesGetter - extends DbClientCommonAttributesGetter { +public interface SqlClientAttributesGetter + extends DbClientAttributesGetter { /** * Get the raw SQL statement. The value returned by this method is later sanitized by the {@link 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 4836a85e359c..079c48f2aa94 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 @@ -22,7 +22,8 @@ class DbClientAttributesExtractorTest { - static final class TestAttributesGetter implements DbClientAttributesGetter> { + static final class TestAttributesGetter + implements DbClientAttributesGetter, Void> { @Override public String getDbSystem(Map map) { return map.get("db.system"); 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 1e05cef5a37e..47c2a12678c2 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 @@ -16,8 +16,8 @@ @ExtendWith(MockitoExtension.class) class DbClientSpanNameExtractorTest { - @Mock DbClientAttributesGetter dbAttributesGetter; - @Mock SqlClientAttributesGetter sqlAttributesGetter; + @Mock DbClientAttributesGetter dbAttributesGetter; + @Mock SqlClientAttributesGetter sqlAttributesGetter; @Test void shouldExtractFullSpanName() { 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 f0b31197a3e2..0e46ad96465e 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 @@ -24,7 +24,7 @@ class SqlClientAttributesExtractorTest { static final class TestAttributesGetter - implements SqlClientAttributesGetter> { + implements SqlClientAttributesGetter, Void> { @Override public String getRawQueryText(Map map) { diff --git a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraNetworkAttributesGetter.java b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraNetworkAttributesGetter.java deleted file mode 100644 index 5e6f41fecdee..000000000000 --- a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraNetworkAttributesGetter.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.cassandra.v3_0; - -import com.datastax.driver.core.ExecutionInfo; -import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter; -import java.net.InetSocketAddress; -import javax.annotation.Nullable; - -final class CassandraNetworkAttributesGetter - implements NetworkAttributesGetter { - - @Override - @Nullable - public InetSocketAddress getNetworkPeerInetSocketAddress( - CassandraRequest request, @Nullable ExecutionInfo executionInfo) { - return executionInfo == null ? null : executionInfo.getQueriedHost().getSocketAddress(); - } -} diff --git a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraSingletons.java b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraSingletons.java index 5598d2fcb994..4403fc2c680e 100644 --- a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraSingletons.java +++ b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraSingletons.java @@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.incubator.semconv.db.SqlClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; -import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; @@ -37,8 +36,6 @@ public final class CassandraSingletons { .setStatementSanitizationEnabled( AgentCommonConfig.get().isStatementSanitizationEnabled()) .build()) - .addAttributesExtractor( - NetworkAttributesExtractor.create(new CassandraNetworkAttributesGetter())) .addAttributesExtractor(new CassandraAttributesExtractor()) .buildInstrumenter(SpanKindExtractor.alwaysClient()); } 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 516f1133bea6..88acfb35ff5c 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 @@ -5,11 +5,14 @@ package io.opentelemetry.javaagent.instrumentation.cassandra.v3_0; +import com.datastax.driver.core.ExecutionInfo; import io.opentelemetry.instrumentation.api.incubator.semconv.db.SqlClientAttributesGetter; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; +import java.net.InetSocketAddress; import javax.annotation.Nullable; -final class CassandraSqlAttributesGetter implements SqlClientAttributesGetter { +final class CassandraSqlAttributesGetter + implements SqlClientAttributesGetter { @Override public String getDbSystem(CassandraRequest request) { @@ -41,4 +44,11 @@ public String getConnectionString(CassandraRequest request) { public String getRawQueryText(CassandraRequest request) { return request.getQueryText(); } + + @Override + @Nullable + public InetSocketAddress getNetworkPeerInetSocketAddress( + CassandraRequest request, @Nullable ExecutionInfo executionInfo) { + return executionInfo == null ? null : executionInfo.getQueriedHost().getSocketAddress(); + } } 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 3373c0e76277..68fca3ee8d67 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 @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS; @@ -102,7 +103,7 @@ void syncTest(Parameter parameter) { .hasKind(SpanKind.CLIENT) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(SERVER_ADDRESS, cassandraHost), equalTo(SERVER_PORT, cassandraPort), equalTo(NETWORK_PEER_ADDRESS, cassandraIp), @@ -116,7 +117,7 @@ void syncTest(Parameter parameter) { .hasKind(SpanKind.CLIENT) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(SERVER_ADDRESS, cassandraHost), equalTo(SERVER_PORT, cassandraPort), equalTo(NETWORK_PEER_ADDRESS, cassandraIp), @@ -135,7 +136,7 @@ void syncTest(Parameter parameter) { .hasKind(SpanKind.CLIENT) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(SERVER_ADDRESS, cassandraHost), equalTo(SERVER_PORT, cassandraPort), equalTo(NETWORK_PEER_ADDRESS, cassandraIp), @@ -174,7 +175,7 @@ void asyncTest(Parameter parameter) { .hasKind(SpanKind.CLIENT) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(SERVER_ADDRESS, cassandraHost), equalTo(SERVER_PORT, cassandraPort), equalTo(NETWORK_PEER_ADDRESS, cassandraIp), @@ -189,7 +190,7 @@ void asyncTest(Parameter parameter) { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(SERVER_ADDRESS, cassandraHost), equalTo(SERVER_PORT, cassandraPort), equalTo(NETWORK_PEER_ADDRESS, cassandraIp), @@ -213,7 +214,7 @@ void asyncTest(Parameter parameter) { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(SERVER_ADDRESS, cassandraHost), equalTo(SERVER_PORT, cassandraPort), equalTo(NETWORK_PEER_ADDRESS, cassandraIp), 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 b49fb7da01ab..6ed9ba013027 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 @@ -5,6 +5,7 @@ package io.opentelemetry.cassandra.v4.common; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; @@ -104,10 +105,15 @@ void syncTest(Parameter parameter) { .hasAttributesSatisfyingExactly( satisfies( NETWORK_TYPE, - val -> + val -> { + if (emitStableDatabaseSemconv()) { + val.isNull(); + } else { val.satisfiesAnyOf( v -> assertThat(v).isEqualTo("ipv4"), - v -> assertThat(v).isEqualTo("ipv6"))), + v -> assertThat(v).isEqualTo("ipv6")); + } + }), equalTo(SERVER_ADDRESS, cassandraHost), equalTo(SERVER_PORT, cassandraPort), equalTo(NETWORK_PEER_ADDRESS, cassandraIp), @@ -158,10 +164,15 @@ void asyncTest(Parameter parameter) throws Exception { .hasAttributesSatisfyingExactly( satisfies( NETWORK_TYPE, - val -> + val -> { + if (emitStableDatabaseSemconv()) { + val.isNull(); + } else { val.satisfiesAnyOf( v -> assertThat(v).isEqualTo("ipv4"), - v -> assertThat(v).isEqualTo("ipv6"))), + v -> assertThat(v).isEqualTo("ipv6")); + } + }), equalTo(SERVER_ADDRESS, cassandraHost), equalTo(SERVER_PORT, cassandraPort), equalTo(NETWORK_PEER_ADDRESS, cassandraIp), diff --git a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraNetworkAttributesGetter.java b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraNetworkAttributesGetter.java deleted file mode 100644 index 44ed4e1e851d..000000000000 --- a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraNetworkAttributesGetter.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.cassandra.v4_0; - -import com.datastax.oss.driver.api.core.cql.ExecutionInfo; -import com.datastax.oss.driver.api.core.metadata.Node; -import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import javax.annotation.Nullable; - -final class CassandraNetworkAttributesGetter - implements NetworkAttributesGetter { - - @Override - @Nullable - public InetSocketAddress getNetworkPeerInetSocketAddress( - CassandraRequest request, @Nullable ExecutionInfo executionInfo) { - if (executionInfo == null) { - return null; - } - Node coordinator = executionInfo.getCoordinator(); - if (coordinator == null) { - return null; - } - // resolve() returns an existing InetSocketAddress, it does not do a dns resolve, - // at least in the only current EndPoint implementation (DefaultEndPoint) - SocketAddress address = coordinator.getEndPoint().resolve(); - return address instanceof InetSocketAddress ? (InetSocketAddress) address : null; - } -} diff --git a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraSingletons.java b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraSingletons.java index 668cf2f50974..c98c9f9f6b8d 100644 --- a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraSingletons.java +++ b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraSingletons.java @@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.incubator.semconv.db.SqlClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; -import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; @@ -36,8 +35,6 @@ public final class CassandraSingletons { .setStatementSanitizationEnabled( AgentCommonConfig.get().isStatementSanitizationEnabled()) .build()) - .addAttributesExtractor( - NetworkAttributesExtractor.create(new CassandraNetworkAttributesGetter())) .addAttributesExtractor(new CassandraAttributesExtractor()) .buildInstrumenter(SpanKindExtractor.alwaysClient()); } 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 0ac75ae3778c..3e686fa956f2 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 @@ -6,11 +6,16 @@ package io.opentelemetry.javaagent.instrumentation.cassandra.v4_0; import com.datastax.oss.driver.api.core.CqlIdentifier; +import com.datastax.oss.driver.api.core.cql.ExecutionInfo; +import com.datastax.oss.driver.api.core.metadata.Node; import io.opentelemetry.instrumentation.api.incubator.semconv.db.SqlClientAttributesGetter; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; +import java.net.InetSocketAddress; +import java.net.SocketAddress; import javax.annotation.Nullable; -final class CassandraSqlAttributesGetter implements SqlClientAttributesGetter { +final class CassandraSqlAttributesGetter + implements SqlClientAttributesGetter { @Override public String getDbSystem(CassandraRequest request) { @@ -42,4 +47,21 @@ public String getConnectionString(CassandraRequest request) { public String getRawQueryText(CassandraRequest request) { return request.getQueryText(); } + + @Override + @Nullable + public InetSocketAddress getNetworkPeerInetSocketAddress( + CassandraRequest request, @Nullable ExecutionInfo executionInfo) { + if (executionInfo == null) { + return null; + } + Node coordinator = executionInfo.getCoordinator(); + if (coordinator == null) { + return null; + } + // resolve() returns an existing InetSocketAddress, it does not do a dns resolve, + // at least in the only current EndPoint implementation (DefaultEndPoint) + SocketAddress address = coordinator.getEndPoint().resolve(); + return address instanceof InetSocketAddress ? (InetSocketAddress) address : null; + } } diff --git a/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraNetworkAttributesGetter.java b/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraNetworkAttributesGetter.java deleted file mode 100644 index 532dcb0646f6..000000000000 --- a/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraNetworkAttributesGetter.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.cassandra.v4_4; - -import com.datastax.oss.driver.api.core.cql.ExecutionInfo; -import com.datastax.oss.driver.api.core.metadata.EndPoint; -import com.datastax.oss.driver.api.core.metadata.Node; -import com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint; -import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter; -import java.net.InetSocketAddress; -import javax.annotation.Nullable; - -final class CassandraNetworkAttributesGetter - implements NetworkAttributesGetter { - - @Override - @Nullable - public InetSocketAddress getNetworkPeerInetSocketAddress( - CassandraRequest request, @Nullable ExecutionInfo executionInfo) { - if (executionInfo == null) { - return null; - } - Node coordinator = executionInfo.getCoordinator(); - if (coordinator == null) { - return null; - } - EndPoint endPoint = coordinator.getEndPoint(); - if (endPoint instanceof DefaultEndPoint) { - // resolve() returns an existing InetSocketAddress, it does not do a dns resolve, - return (InetSocketAddress) endPoint.resolve(); - } - return null; - } -} 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 fb14a7abc93f..9647f8f1c68b 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 @@ -6,10 +6,16 @@ package io.opentelemetry.instrumentation.cassandra.v4_4; import com.datastax.oss.driver.api.core.CqlIdentifier; +import com.datastax.oss.driver.api.core.cql.ExecutionInfo; +import com.datastax.oss.driver.api.core.metadata.EndPoint; +import com.datastax.oss.driver.api.core.metadata.Node; +import com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint; import io.opentelemetry.instrumentation.api.incubator.semconv.db.SqlClientAttributesGetter; +import java.net.InetSocketAddress; import javax.annotation.Nullable; -final class CassandraSqlAttributesGetter implements SqlClientAttributesGetter { +final class CassandraSqlAttributesGetter + implements SqlClientAttributesGetter { // copied from DbIncubatingAttributes.DbSystemIncubatingValues private static final String CASSANDRA = "cassandra"; @@ -43,4 +49,23 @@ public String getConnectionString(CassandraRequest request) { public String getRawQueryText(CassandraRequest request) { return request.getQueryText(); } + + @Override + @Nullable + public InetSocketAddress getNetworkPeerInetSocketAddress( + CassandraRequest request, @Nullable ExecutionInfo executionInfo) { + if (executionInfo == null) { + return null; + } + Node coordinator = executionInfo.getCoordinator(); + if (coordinator == null) { + return null; + } + EndPoint endPoint = coordinator.getEndPoint(); + if (endPoint instanceof DefaultEndPoint) { + // resolve() returns an existing InetSocketAddress, it does not do a dns resolve, + return (InetSocketAddress) endPoint.resolve(); + } + return null; + } } diff --git a/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraTelemetryBuilder.java b/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraTelemetryBuilder.java index d5a92eb7d936..dd49356b0b09 100644 --- a/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraTelemetryBuilder.java +++ b/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraTelemetryBuilder.java @@ -13,7 +13,6 @@ import io.opentelemetry.instrumentation.api.incubator.semconv.db.SqlClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; -import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesExtractor; /** A builder of {@link CassandraTelemetry}. */ public class CassandraTelemetryBuilder { @@ -62,8 +61,6 @@ protected Instrumenter createInstrumenter( .setTableAttribute(DB_CASSANDRA_TABLE) .setStatementSanitizationEnabled(statementSanitizationEnabled) .build()) - .addAttributesExtractor( - NetworkAttributesExtractor.create(new CassandraNetworkAttributesGetter())) .addAttributesExtractor(new CassandraAttributesExtractor()) .buildInstrumenter(SpanKindExtractor.alwaysClient()); } 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 a5319f49df4e..f670596b0953 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 @@ -5,6 +5,7 @@ package io.opentelemetry.testing.cassandra.v4_4; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; @@ -64,10 +65,15 @@ void reactiveTest(Parameter parameter) { .hasAttributesSatisfyingExactly( satisfies( NETWORK_TYPE, - val -> + val -> { + if (emitStableDatabaseSemconv()) { + val.isNull(); + } else { val.satisfiesAnyOf( v -> assertThat(v).isEqualTo("ipv4"), - v -> assertThat(v).isEqualTo("ipv6"))), + v -> assertThat(v).isEqualTo("ipv6")); + } + }), equalTo(SERVER_ADDRESS, cassandraHost), equalTo(SERVER_PORT, cassandraPort), equalTo(NETWORK_PEER_ADDRESS, cassandraIp), 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 c8210b53b5b9..87960436151a 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 @@ -9,7 +9,8 @@ import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; import javax.annotation.Nullable; -final class ClickHouseAttributesGetter implements DbClientAttributesGetter { +final class ClickHouseAttributesGetter + implements DbClientAttributesGetter { @Nullable @Override 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 5975b40d76e0..1313982c75fb 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 @@ -7,9 +7,12 @@ import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesGetter; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; +import java.net.InetSocketAddress; +import java.net.SocketAddress; import javax.annotation.Nullable; -final class CouchbaseAttributesGetter implements DbClientAttributesGetter { +final class CouchbaseAttributesGetter + implements DbClientAttributesGetter { @Override public String getDbSystem(CouchbaseRequestInfo couchbaseRequest) { @@ -47,4 +50,15 @@ public String getDbQueryText(CouchbaseRequestInfo couchbaseRequest) { public String getDbOperationName(CouchbaseRequestInfo couchbaseRequest) { return couchbaseRequest.operation(); } + + @Nullable + @Override + public InetSocketAddress getNetworkPeerInetSocketAddress( + CouchbaseRequestInfo couchbaseRequest, @Nullable Void unused) { + SocketAddress peerAddress = couchbaseRequest.getPeerAddress(); + if (peerAddress instanceof InetSocketAddress) { + return (InetSocketAddress) peerAddress; + } + return null; + } } diff --git a/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseNetworkAttributesGetter.java b/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseNetworkAttributesGetter.java deleted file mode 100644 index a551acdb322b..000000000000 --- a/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseNetworkAttributesGetter.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.couchbase.v2_0; - -import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import javax.annotation.Nullable; - -public class CouchbaseNetworkAttributesGetter - implements NetworkAttributesGetter { - - @Nullable - @Override - public InetSocketAddress getNetworkPeerInetSocketAddress( - CouchbaseRequestInfo couchbaseRequest, @Nullable Void unused) { - SocketAddress peerAddress = couchbaseRequest.getPeerAddress(); - if (peerAddress instanceof InetSocketAddress) { - return (InetSocketAddress) peerAddress; - } - return null; - } -} diff --git a/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseSingletons.java b/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseSingletons.java index 0e6c3eee550a..6fb754da9d7d 100644 --- a/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseSingletons.java +++ b/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseSingletons.java @@ -12,7 +12,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig; public final class CouchbaseSingletons { @@ -25,13 +24,11 @@ public final class CouchbaseSingletons { CouchbaseAttributesGetter couchbaseAttributesGetter = new CouchbaseAttributesGetter(); SpanNameExtractor spanNameExtractor = new CouchbaseSpanNameExtractor(DbClientSpanNameExtractor.create(couchbaseAttributesGetter)); - CouchbaseNetworkAttributesGetter netAttributesGetter = new CouchbaseNetworkAttributesGetter(); InstrumenterBuilder builder = Instrumenter.builder( GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanNameExtractor) .addAttributesExtractor(DbClientAttributesExtractor.create(couchbaseAttributesGetter)) - .addAttributesExtractor(NetworkAttributesExtractor.create(netAttributesGetter)) .addContextCustomizer( (context, couchbaseRequest, startAttributes) -> CouchbaseRequestInfo.init(context, couchbaseRequest)); 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 fc72192dea24..c929905bb62f 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 @@ -16,13 +16,14 @@ import java.util.stream.Collectors; import javax.annotation.Nullable; import org.apache.http.HttpEntity; +import org.elasticsearch.client.Response; /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ final class ElasticsearchDbAttributesGetter - implements DbClientAttributesGetter { + implements DbClientAttributesGetter { private static final Logger logger = Logger.getLogger(ElasticsearchDbAttributesGetter.class.getName()); diff --git a/instrumentation/elasticsearch/elasticsearch-transport-6.0/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/AbstractElasticsearch6TransportClientTest.java b/instrumentation/elasticsearch/elasticsearch-transport-6.0/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/AbstractElasticsearch6TransportClientTest.java index b36d5210f9cd..8995dfd1f7ce 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-6.0/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/AbstractElasticsearch6TransportClientTest.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-6.0/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/AbstractElasticsearch6TransportClientTest.java @@ -7,6 +7,7 @@ import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING; +import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.AbstractElasticsearchTransportClientTest; import java.io.File; import java.util.Collections; @@ -111,6 +112,6 @@ protected int getPort() { @Override protected boolean hasNetworkType() { - return true; + return SemconvStability.emitOldDatabaseSemconv(); } } 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 cbd713f364f6..714e8c8fe821 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 @@ -8,9 +8,10 @@ import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesGetter; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; import javax.annotation.Nullable; +import org.elasticsearch.action.ActionResponse; final class ElasticsearchTransportAttributesGetter - implements DbClientAttributesGetter { + implements DbClientAttributesGetter { @Override public String getDbSystem(ElasticTransportRequest request) { 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 0ce010e302ce..ce6000f53956 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 @@ -11,7 +11,7 @@ import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; import javax.annotation.Nullable; -final class GeodeDbAttributesGetter implements DbClientAttributesGetter { +final class GeodeDbAttributesGetter implements DbClientAttributesGetter { private static final SqlStatementSanitizer sanitizer = SqlStatementSanitizer.create(AgentCommonConfig.get().isStatementSanitizationEnabled()); diff --git a/instrumentation/influxdb-2.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbAttributesGetter.java b/instrumentation/influxdb-2.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbAttributesGetter.java index 39460c14a135..a4c5ef73c0be 100644 --- a/instrumentation/influxdb-2.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbAttributesGetter.java +++ b/instrumentation/influxdb-2.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbAttributesGetter.java @@ -8,7 +8,7 @@ import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesGetter; import javax.annotation.Nullable; -final class InfluxDbAttributesGetter implements DbClientAttributesGetter { +final class InfluxDbAttributesGetter implements DbClientAttributesGetter { @Nullable @Override diff --git a/instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/JdbcSingletons.java b/instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/JdbcSingletons.java index afc92f2fcad9..36d3e4cc1a8c 100644 --- a/instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/JdbcSingletons.java +++ b/instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/JdbcSingletons.java @@ -13,10 +13,8 @@ import io.opentelemetry.instrumentation.api.incubator.semconv.net.PeerServiceAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; -import io.opentelemetry.instrumentation.api.semconv.network.ServerAttributesExtractor; import io.opentelemetry.instrumentation.jdbc.internal.DbRequest; import io.opentelemetry.instrumentation.jdbc.internal.JdbcAttributesGetter; -import io.opentelemetry.instrumentation.jdbc.internal.JdbcNetworkAttributesGetter; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig; import io.opentelemetry.javaagent.bootstrap.jdbc.DbInfo; @@ -31,7 +29,6 @@ public final class JdbcSingletons { static { JdbcAttributesGetter dbAttributesGetter = new JdbcAttributesGetter(); - JdbcNetworkAttributesGetter netAttributesGetter = new JdbcNetworkAttributesGetter(); STATEMENT_INSTRUMENTER = Instrumenter.builder( @@ -46,10 +43,9 @@ public final class JdbcSingletons { "otel.instrumentation.jdbc.statement-sanitizer.enabled", AgentCommonConfig.get().isStatementSanitizationEnabled())) .build()) - .addAttributesExtractor(ServerAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create( - netAttributesGetter, AgentCommonConfig.get().getPeerServiceResolver())) + dbAttributesGetter, AgentCommonConfig.get().getPeerServiceResolver())) .buildInstrumenter(SpanKindExtractor.alwaysClient()); } 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 b5623f4d99ce..64a23da14680 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 @@ -13,7 +13,7 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public final class JdbcAttributesGetter implements SqlClientAttributesGetter { +public final class JdbcAttributesGetter implements SqlClientAttributesGetter { @Nullable @Override @@ -47,4 +47,16 @@ public String getConnectionString(DbRequest request) { public String getRawQueryText(DbRequest request) { return request.getQueryText(); } + + @Nullable + @Override + public String getServerAddress(DbRequest request) { + return request.getDbInfo().getHost(); + } + + @Nullable + @Override + public Integer getServerPort(DbRequest request) { + return request.getDbInfo().getPort(); + } } diff --git a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcInstrumenterFactory.java b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcInstrumenterFactory.java index 2e0b1e583bb7..809243624e69 100644 --- a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcInstrumenterFactory.java +++ b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcInstrumenterFactory.java @@ -14,7 +14,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil; -import io.opentelemetry.instrumentation.api.semconv.network.ServerAttributesExtractor; import io.opentelemetry.instrumentation.jdbc.internal.dbinfo.DbInfo; import javax.sql.DataSource; @@ -25,8 +24,6 @@ public final class JdbcInstrumenterFactory { public static final String INSTRUMENTATION_NAME = "io.opentelemetry.jdbc"; private static final JdbcAttributesGetter dbAttributesGetter = new JdbcAttributesGetter(); - private static final JdbcNetworkAttributesGetter netAttributesGetter = - new JdbcNetworkAttributesGetter(); public static Instrumenter createStatementInstrumenter() { return createStatementInstrumenter(GlobalOpenTelemetry.get()); @@ -51,7 +48,6 @@ public static Instrumenter createStatementInstrumenter( SqlClientAttributesExtractor.builder(dbAttributesGetter) .setStatementSanitizationEnabled(statementSanitizationEnabled) .build()) - .addAttributesExtractor(ServerAttributesExtractor.create(netAttributesGetter)) .setEnabled(enabled) .buildInstrumenter(SpanKindExtractor.alwaysClient()); } diff --git a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcNetworkAttributesGetter.java b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcNetworkAttributesGetter.java index a09ca312672b..002d4b3bd49d 100644 --- a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcNetworkAttributesGetter.java +++ b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcNetworkAttributesGetter.java @@ -6,23 +6,9 @@ package io.opentelemetry.instrumentation.jdbc.internal; import io.opentelemetry.instrumentation.api.semconv.network.ServerAttributesGetter; -import javax.annotation.Nullable; /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public final class JdbcNetworkAttributesGetter implements ServerAttributesGetter { - - @Nullable - @Override - public String getServerAddress(DbRequest request) { - return request.getDbInfo().getHost(); - } - - @Nullable - @Override - public Integer getServerPort(DbRequest request) { - return request.getDbInfo().getPort(); - } -} +public final class JdbcNetworkAttributesGetter implements ServerAttributesGetter {} diff --git a/instrumentation/jedis/jedis-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisDbAttributesGetter.java b/instrumentation/jedis/jedis-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisDbAttributesGetter.java index b50e312e4f97..c295ec6c32ac 100644 --- a/instrumentation/jedis/jedis-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisDbAttributesGetter.java +++ b/instrumentation/jedis/jedis-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisDbAttributesGetter.java @@ -11,7 +11,7 @@ import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; import javax.annotation.Nullable; -final class JedisDbAttributesGetter implements DbClientAttributesGetter { +final class JedisDbAttributesGetter implements DbClientAttributesGetter { private static final RedisCommandSanitizer sanitizer = RedisCommandSanitizer.create(AgentCommonConfig.get().isStatementSanitizationEnabled()); diff --git a/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisDbAttributesGetter.java b/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisDbAttributesGetter.java index 40a7d3faf279..c070ca9712be 100644 --- a/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisDbAttributesGetter.java +++ b/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisDbAttributesGetter.java @@ -9,7 +9,7 @@ import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; import javax.annotation.Nullable; -final class JedisDbAttributesGetter implements DbClientAttributesGetter { +final class JedisDbAttributesGetter implements DbClientAttributesGetter { @Override public String getDbSystem(JedisRequest request) { diff --git a/instrumentation/jedis/jedis-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/Jedis30ClientTest.java b/instrumentation/jedis/jedis-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/Jedis30ClientTest.java index 921610937bc1..8b6af1615193 100644 --- a/instrumentation/jedis/jedis-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/Jedis30ClientTest.java +++ b/instrumentation/jedis/jedis-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/Jedis30ClientTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.jedis.v3_0; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; @@ -85,7 +86,7 @@ void setCommand() { equalTo(maybeStable(DB_OPERATION), "SET"), equalTo(SERVER_ADDRESS, host), equalTo(SERVER_PORT, port), - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), satisfies(NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative)))); } @@ -109,7 +110,7 @@ void getCommand() { equalTo(maybeStable(DB_OPERATION), "SET"), equalTo(SERVER_ADDRESS, host), equalTo(SERVER_PORT, port), - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), satisfies(NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative))), trace -> @@ -123,7 +124,7 @@ void getCommand() { equalTo(maybeStable(DB_OPERATION), "GET"), equalTo(SERVER_ADDRESS, host), equalTo(SERVER_PORT, port), - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), satisfies(NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative)))); } @@ -147,7 +148,7 @@ void commandWithNoArguments() { equalTo(maybeStable(DB_OPERATION), "SET"), equalTo(SERVER_ADDRESS, host), equalTo(SERVER_PORT, port), - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), satisfies(NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative))), trace -> @@ -161,7 +162,7 @@ void commandWithNoArguments() { equalTo(maybeStable(DB_OPERATION), "RANDOMKEY"), equalTo(SERVER_ADDRESS, host), equalTo(SERVER_PORT, port), - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), satisfies(NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative)))); } 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 8cdd49df99e8..d3a36275752f 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 @@ -7,9 +7,11 @@ import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesGetter; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; +import java.net.InetSocketAddress; +import java.net.SocketAddress; import javax.annotation.Nullable; -final class JedisDbAttributesGetter implements DbClientAttributesGetter { +final class JedisDbAttributesGetter implements DbClientAttributesGetter { @Override public String getDbSystem(JedisRequest request) { @@ -43,4 +45,15 @@ public String getDbQueryText(JedisRequest request) { public String getDbOperationName(JedisRequest request) { return request.getOperation(); } + + @Override + @Nullable + public InetSocketAddress getNetworkPeerInetSocketAddress( + JedisRequest jedisRequest, @Nullable Void unused) { + SocketAddress socketAddress = jedisRequest.getRemoteSocketAddress(); + if (socketAddress instanceof InetSocketAddress) { + return (InetSocketAddress) socketAddress; + } + return null; + } } diff --git a/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisNetworkAttributesGetter.java b/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisNetworkAttributesGetter.java deleted file mode 100644 index 900ba8e08e69..000000000000 --- a/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisNetworkAttributesGetter.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.jedis.v4_0; - -import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import javax.annotation.Nullable; - -final class JedisNetworkAttributesGetter implements NetworkAttributesGetter { - - @Override - @Nullable - public InetSocketAddress getNetworkPeerInetSocketAddress( - JedisRequest jedisRequest, @Nullable Void unused) { - SocketAddress socketAddress = jedisRequest.getRemoteSocketAddress(); - if (socketAddress instanceof InetSocketAddress) { - return (InetSocketAddress) socketAddress; - } - return null; - } -} diff --git a/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisSingletons.java b/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisSingletons.java index b22c482227a0..929387ae3a4a 100644 --- a/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisSingletons.java +++ b/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisSingletons.java @@ -10,7 +10,6 @@ import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; -import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesExtractor; public final class JedisSingletons { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jedis-4.0"; @@ -19,7 +18,6 @@ public final class JedisSingletons { static { JedisDbAttributesGetter dbAttributesGetter = new JedisDbAttributesGetter(); - JedisNetworkAttributesGetter netAttributesGetter = new JedisNetworkAttributesGetter(); INSTRUMENTER = Instrumenter.builder( @@ -27,7 +25,6 @@ public final class JedisSingletons { INSTRUMENTATION_NAME, DbClientSpanNameExtractor.create(dbAttributesGetter)) .addAttributesExtractor(DbClientAttributesExtractor.create(dbAttributesGetter)) - .addAttributesExtractor(NetworkAttributesExtractor.create(netAttributesGetter)) .buildInstrumenter(SpanKindExtractor.alwaysClient()); } diff --git a/instrumentation/jedis/jedis-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/Jedis40ClientTest.java b/instrumentation/jedis/jedis-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/Jedis40ClientTest.java index 9e965ee16b99..fa16b2f762b0 100644 --- a/instrumentation/jedis/jedis-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/Jedis40ClientTest.java +++ b/instrumentation/jedis/jedis-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/Jedis40ClientTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.jedis.v4_0; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS; @@ -76,7 +77,7 @@ void setCommand() { equalTo(DB_SYSTEM, "redis"), equalTo(maybeStable(DB_STATEMENT), "SET foo ?"), equalTo(maybeStable(DB_OPERATION), "SET"), - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_PORT, port), equalTo(NETWORK_PEER_ADDRESS, ip)))); } @@ -98,7 +99,7 @@ void getCommand() { equalTo(DB_SYSTEM, "redis"), equalTo(maybeStable(DB_STATEMENT), "SET foo ?"), equalTo(maybeStable(DB_OPERATION), "SET"), - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_PORT, port), equalTo(NETWORK_PEER_ADDRESS, ip))), trace -> @@ -110,7 +111,7 @@ void getCommand() { equalTo(DB_SYSTEM, "redis"), equalTo(maybeStable(DB_STATEMENT), "GET foo"), equalTo(maybeStable(DB_OPERATION), "GET"), - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_PORT, port), equalTo(NETWORK_PEER_ADDRESS, ip)))); } @@ -132,7 +133,7 @@ void commandWithNoArguments() { equalTo(DB_SYSTEM, "redis"), equalTo(maybeStable(DB_STATEMENT), "SET foo ?"), equalTo(maybeStable(DB_OPERATION), "SET"), - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_PORT, port), equalTo(NETWORK_PEER_ADDRESS, ip))), trace -> @@ -144,7 +145,7 @@ void commandWithNoArguments() { equalTo(DB_SYSTEM, "redis"), equalTo(maybeStable(DB_STATEMENT), "RANDOMKEY"), equalTo(maybeStable(DB_OPERATION), "RANDOMKEY"), - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_PORT, port), equalTo(NETWORK_PEER_ADDRESS, ip)))); } 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 b51d06bfea6b..bd9077cc2649 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 @@ -10,7 +10,8 @@ import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; import javax.annotation.Nullable; -final class LettuceDbAttributesGetter implements DbClientAttributesGetter> { +final class LettuceDbAttributesGetter + implements DbClientAttributesGetter, Void> { @Override public String getDbSystem(RedisCommand request) { 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 392f090aceaf..9f9c51b84597 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 @@ -15,7 +15,8 @@ import java.util.List; import javax.annotation.Nullable; -final class LettuceDbAttributesGetter implements DbClientAttributesGetter> { +final class LettuceDbAttributesGetter + implements DbClientAttributesGetter, Void> { private static final RedisCommandSanitizer sanitizer = RedisCommandSanitizer.create(AgentCommonConfig.get().isStatementSanitizationEnabled()); diff --git a/instrumentation/lettuce/lettuce-5.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_1/LettuceReactiveClientTest.java b/instrumentation/lettuce/lettuce-5.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_1/LettuceReactiveClientTest.java index 4324b7cc1199..9718765f5db3 100644 --- a/instrumentation/lettuce/lettuce-5.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_1/LettuceReactiveClientTest.java +++ b/instrumentation/lettuce/lettuce-5.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_1/LettuceReactiveClientTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.lettuce.v5_1; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS; @@ -59,7 +60,8 @@ void testAsyncSubscriberWithSpecificThreadPool() { .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -75,7 +77,8 @@ void testAsyncSubscriberWithSpecificThreadPool() { .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), diff --git a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceAsyncClientTest.java b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceAsyncClientTest.java index 9a65d02a37f3..ce3b521ac190 100644 --- a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceAsyncClientTest.java +++ b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceAsyncClientTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.lettuce.v5_1; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS; @@ -161,7 +162,8 @@ void testSetCommandUsingFutureGetWithTimeout() throws Exception { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -207,7 +209,9 @@ void testGetCommandChainedWithThenAccept() throws Exception { .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, + emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -286,7 +290,9 @@ void testGetNonExistentKeyCommandWithHandleAsyncAndChainedWithThenApply() throws .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, + emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -353,7 +359,9 @@ void testCommandWithNoArgumentsUsingBiconsumer() throws Exception { .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, + emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -413,7 +421,8 @@ void testHashSetAndThenNestApplyToHashGetall() throws Exception { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -432,7 +441,8 @@ void testHashSetAndThenNestApplyToHashGetall() throws Exception { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), diff --git a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceReactiveClientTest.java b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceReactiveClientTest.java index 93b20a87be7b..277bcac75ad4 100644 --- a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceReactiveClientTest.java +++ b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceReactiveClientTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.lettuce.v5_1; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS; @@ -99,7 +100,8 @@ void testSetCommandWithSubscribeOnDefinedConsumer() throws Exception { .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -138,7 +140,8 @@ void testGetCommandWithLambdaFunction() throws Exception { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -188,7 +191,8 @@ void testGetNonExistentKeyCommand() throws Exception { .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -226,7 +230,8 @@ void testCommandWithNoArguments() throws Exception { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -251,7 +256,8 @@ void testCommandFluxPublisher() { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -297,7 +303,8 @@ void testBlockingSubscriber() { .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -313,7 +320,8 @@ void testBlockingSubscriber() { .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -343,7 +351,8 @@ void testAsyncSubscriber() { .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -359,7 +368,8 @@ void testAsyncSubscriber() { .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), diff --git a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientAuthTest.java b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientAuthTest.java index 76a467798000..d0cf85fe6a43 100644 --- a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientAuthTest.java +++ b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientAuthTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.lettuce.v5_1; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; @@ -76,7 +77,9 @@ void testAuthCommand() throws Exception { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, + emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -92,7 +95,9 @@ void testAuthCommand() throws Exception { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, + emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -109,7 +114,9 @@ void testAuthCommand() throws Exception { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, + emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -130,7 +137,9 @@ void testAuthCommand() throws Exception { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, + emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), diff --git a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientTest.java b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientTest.java index f09ec6b687c2..d4138337676f 100644 --- a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientTest.java +++ b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.lettuce.v5_1; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; @@ -125,7 +126,8 @@ void testSetCommand() { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -151,7 +153,8 @@ void testGetCommand() { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -177,7 +180,8 @@ void testGetNonExistentKeyCommand() { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -203,7 +207,8 @@ void testCommandWithNoArguments() { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -239,7 +244,8 @@ void testListCommand() { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, containerConnection.port), equalTo(SERVER_ADDRESS, host), @@ -265,7 +271,8 @@ void testHashSetCommand() { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -293,7 +300,8 @@ void testHashGetallCommand() { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -326,7 +334,8 @@ void testEvalCommand() { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -355,7 +364,8 @@ void testMsetCommand() { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, port), equalTo(SERVER_ADDRESS, host), @@ -385,7 +395,9 @@ void testDebugSegfaultCommandWithNoArgumentProducesNoSpan() { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, + emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, containerConnection.port), equalTo(SERVER_ADDRESS, host), @@ -401,7 +413,9 @@ void testDebugSegfaultCommandWithNoArgumentProducesNoSpan() { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, + emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, containerConnection.port), equalTo(SERVER_ADDRESS, host), @@ -418,7 +432,9 @@ void testDebugSegfaultCommandWithNoArgumentProducesNoSpan() { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, + emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, containerConnection.port), equalTo(SERVER_ADDRESS, host), @@ -435,7 +451,9 @@ void testDebugSegfaultCommandWithNoArgumentProducesNoSpan() { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, + emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, containerConnection.port), equalTo(SERVER_ADDRESS, host), @@ -475,7 +493,8 @@ void testShutdownCommandProducesNoSpan() { .hasException(new RedisException("Connection disconnected")) .hasAttributesSatisfyingExactly( addExtraAttributes( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, containerConnection.port), equalTo(SERVER_ADDRESS, host), @@ -491,7 +510,8 @@ void testShutdownCommandProducesNoSpan() { addExtraAttributes( equalTo( AttributeKey.stringKey("error"), "Connection disconnected"), - equalTo(NETWORK_TYPE, "ipv4"), + equalTo( + NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, containerConnection.port), equalTo(SERVER_ADDRESS, host), 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 06ae481de250..d5c6182ca1d9 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 @@ -23,7 +23,7 @@ import org.bson.json.JsonWriter; import org.bson.json.JsonWriterSettings; -class MongoDbAttributesGetter implements DbClientAttributesGetter { +class MongoDbAttributesGetter implements DbClientAttributesGetter { // copied from DbIncubatingAttributes.DbSystemIncubatingValues private static final String MONGODB = "mongodb"; 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 aadbeba17015..b6362e1e6dd9 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 @@ -8,9 +8,10 @@ import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesGetter; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; import javax.annotation.Nullable; +import org.opensearch.client.Response; final class OpenSearchRestAttributesGetter - implements DbClientAttributesGetter { + implements DbClientAttributesGetter { @Override public String getDbSystem(OpenSearchRestRequest request) { diff --git a/instrumentation/r2dbc-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/r2dbc/v1_0/R2dbcSingletons.java b/instrumentation/r2dbc-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/r2dbc/v1_0/R2dbcSingletons.java index 36ebe81accbf..39e41f6ae771 100644 --- a/instrumentation/r2dbc-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/r2dbc/v1_0/R2dbcSingletons.java +++ b/instrumentation/r2dbc-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/r2dbc/v1_0/R2dbcSingletons.java @@ -8,7 +8,7 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.incubator.semconv.net.PeerServiceAttributesExtractor; import io.opentelemetry.instrumentation.r2dbc.v1_0.internal.shaded.R2dbcTelemetry; -import io.opentelemetry.instrumentation.r2dbc.v1_0.internal.shaded.internal.R2dbcNetAttributesGetter; +import io.opentelemetry.instrumentation.r2dbc.v1_0.internal.shaded.internal.R2dbcSqlAttributesGetter; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig; @@ -23,7 +23,7 @@ public final class R2dbcSingletons { AgentCommonConfig.get().isStatementSanitizationEnabled())) .addAttributeExtractor( PeerServiceAttributesExtractor.create( - R2dbcNetAttributesGetter.INSTANCE, + R2dbcSqlAttributesGetter.INSTANCE, AgentCommonConfig.get().getPeerServiceResolver())) .build(); diff --git a/instrumentation/r2dbc-1.0/library/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/internal/R2dbcInstrumenterBuilder.java b/instrumentation/r2dbc-1.0/library/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/internal/R2dbcInstrumenterBuilder.java index 0b15861ff915..22a8fc782e5d 100644 --- a/instrumentation/r2dbc-1.0/library/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/internal/R2dbcInstrumenterBuilder.java +++ b/instrumentation/r2dbc-1.0/library/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/internal/R2dbcInstrumenterBuilder.java @@ -13,7 +13,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.network.ServerAttributesExtractor; import java.util.ArrayList; import java.util.List; import java.util.function.Function; @@ -46,6 +45,7 @@ public Instrumenter build( Function, ? extends SpanNameExtractor> spanNameExtractorTransformer, boolean statementSanitizationEnabled) { + SpanNameExtractor spanNameExtractor = spanNameExtractorTransformer.apply( DbClientSpanNameExtractor.create(R2dbcSqlAttributesGetter.INSTANCE)); @@ -56,7 +56,6 @@ public Instrumenter build( SqlClientAttributesExtractor.builder(R2dbcSqlAttributesGetter.INSTANCE) .setStatementSanitizationEnabled(statementSanitizationEnabled) .build()) - .addAttributesExtractor(ServerAttributesExtractor.create(R2dbcNetAttributesGetter.INSTANCE)) .addAttributesExtractors(additionalExtractors) .buildInstrumenter(SpanKindExtractor.alwaysClient()); } diff --git a/instrumentation/r2dbc-1.0/library/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/internal/R2dbcNetAttributesGetter.java b/instrumentation/r2dbc-1.0/library/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/internal/R2dbcNetAttributesGetter.java deleted file mode 100644 index a50799c26984..000000000000 --- a/instrumentation/r2dbc-1.0/library/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/internal/R2dbcNetAttributesGetter.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.r2dbc.v1_0.internal; - -import io.opentelemetry.instrumentation.api.semconv.network.ServerAttributesGetter; -import javax.annotation.Nullable; - -/** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. - */ -public enum R2dbcNetAttributesGetter implements ServerAttributesGetter { - INSTANCE; - - @Nullable - @Override - public String getServerAddress(DbExecution request) { - return request.getHost(); - } - - @Nullable - @Override - public Integer getServerPort(DbExecution request) { - return request.getPort(); - } -} 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 9f0a259d5ae9..cc19846e2862 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 @@ -12,7 +12,7 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public enum R2dbcSqlAttributesGetter implements SqlClientAttributesGetter { +public enum R2dbcSqlAttributesGetter implements SqlClientAttributesGetter { INSTANCE; @Override @@ -45,4 +45,16 @@ public String getConnectionString(DbExecution request) { public String getRawQueryText(DbExecution request) { return request.getRawQueryText(); } + + @Nullable + @Override + public String getServerAddress(DbExecution request) { + return request.getHost(); + } + + @Nullable + @Override + public Integer getServerPort(DbExecution request) { + return request.getPort(); + } } diff --git a/instrumentation/rediscala-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rediscala/RediscalaAttributesGetter.java b/instrumentation/rediscala-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rediscala/RediscalaAttributesGetter.java index a103eddf771c..30e32e89a050 100644 --- a/instrumentation/rediscala-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rediscala/RediscalaAttributesGetter.java +++ b/instrumentation/rediscala-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rediscala/RediscalaAttributesGetter.java @@ -11,7 +11,8 @@ import javax.annotation.Nullable; import redis.RedisCommand; -final class RediscalaAttributesGetter implements DbClientAttributesGetter> { +final class RediscalaAttributesGetter + implements DbClientAttributesGetter, Void> { @Override public String getDbSystem(RedisCommand redisCommand) { 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 a2000c8e06c6..d028a47a3827 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 @@ -7,9 +7,10 @@ import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesGetter; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; +import java.net.InetSocketAddress; import javax.annotation.Nullable; -final class RedissonDbAttributesGetter implements DbClientAttributesGetter { +final class RedissonDbAttributesGetter implements DbClientAttributesGetter { @Override public String getDbSystem(RedissonRequest request) { @@ -45,4 +46,10 @@ public String getDbQueryText(RedissonRequest request) { public String getDbOperationName(RedissonRequest request) { return request.getOperation(); } + + @Override + public InetSocketAddress getNetworkPeerInetSocketAddress( + RedissonRequest request, @Nullable Void unused) { + return request.getAddress(); + } } diff --git a/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonInstrumenterFactory.java b/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonInstrumenterFactory.java index 39dc2034ec19..da09abdaf1bd 100644 --- a/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonInstrumenterFactory.java +++ b/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonInstrumenterFactory.java @@ -10,20 +10,17 @@ import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; -import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesExtractor; public final class RedissonInstrumenterFactory { public static Instrumenter createInstrumenter(String instrumentationName) { RedissonDbAttributesGetter dbAttributesGetter = new RedissonDbAttributesGetter(); - RedissonNetAttributesGetter netAttributesGetter = new RedissonNetAttributesGetter(); return Instrumenter.builder( GlobalOpenTelemetry.get(), instrumentationName, DbClientSpanNameExtractor.create(dbAttributesGetter)) .addAttributesExtractor(DbClientAttributesExtractor.create(dbAttributesGetter)) - .addAttributesExtractor(NetworkAttributesExtractor.create(netAttributesGetter)) .buildInstrumenter(SpanKindExtractor.alwaysClient()); } diff --git a/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonNetAttributesGetter.java b/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonNetAttributesGetter.java deleted file mode 100644 index a1739cff1104..000000000000 --- a/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonNetAttributesGetter.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.redisson; - -import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter; -import java.net.InetSocketAddress; -import javax.annotation.Nullable; - -final class RedissonNetAttributesGetter implements NetworkAttributesGetter { - - @Override - public InetSocketAddress getNetworkPeerInetSocketAddress( - RedissonRequest request, @Nullable Void unused) { - return request.getAddress(); - } -} 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 219884a0415f..525db6ff8e9e 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 @@ -7,6 +7,7 @@ import static io.opentelemetry.api.trace.SpanKind.CLIENT; import static io.opentelemetry.api.trace.SpanKind.INTERNAL; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil.orderByRootSpanKind; import static io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil.orderByRootSpanName; @@ -121,7 +122,7 @@ void futureSet() throws ExecutionException, InterruptedException, TimeoutExcepti span.hasName("SET") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), @@ -154,7 +155,7 @@ void futureWhenComplete() throws ExecutionException, InterruptedException, Timeo span.hasName("SADD") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), @@ -228,7 +229,7 @@ void atomicBatchCommand() throws ExecutionException, InterruptedException, Timeo span.hasName("DB Query") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), @@ -238,7 +239,7 @@ void atomicBatchCommand() throws ExecutionException, InterruptedException, Timeo span.hasName("SET") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), @@ -249,7 +250,7 @@ void atomicBatchCommand() throws ExecutionException, InterruptedException, Timeo span.hasName("EXEC") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), 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 81360d8edb1c..5a328ab240cd 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 @@ -7,6 +7,7 @@ import static io.opentelemetry.api.trace.SpanKind.CLIENT; import static io.opentelemetry.api.trace.SpanKind.INTERNAL; +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; import static io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil.orderByRootSpanKind; import static io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil.orderByRootSpanName; @@ -124,7 +125,7 @@ void stringCommand() { span.hasName("SET") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), @@ -136,7 +137,7 @@ void stringCommand() { span.hasName("GET") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), @@ -162,7 +163,7 @@ void batchCommand() span.hasName("DB Query") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), @@ -202,7 +203,7 @@ void atomicBatchCommand() { span.hasName("DB Query") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), @@ -212,7 +213,7 @@ void atomicBatchCommand() { span.hasName("SET") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), @@ -223,7 +224,7 @@ void atomicBatchCommand() { span.hasName("EXEC") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), @@ -245,7 +246,7 @@ void listCommand() { span.hasName("RPUSH") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), @@ -270,7 +271,7 @@ void hashCommand() { span.hasName("EVAL") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), @@ -284,7 +285,7 @@ void hashCommand() { span.hasName("HGET") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), @@ -305,7 +306,7 @@ void setCommand() { span.hasName("SADD") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), @@ -333,7 +334,7 @@ void sortedSetCommand() span.hasName("ZADD") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), @@ -359,7 +360,7 @@ void atomicLongCommand() { span.hasName("INCR") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), @@ -385,7 +386,7 @@ void lockCommand() { span.hasName("EVAL") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), @@ -400,7 +401,7 @@ void lockCommand() { span.hasName("EVAL") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), @@ -416,7 +417,7 @@ void lockCommand() { span.hasName("DEL") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"), equalTo(NETWORK_PEER_ADDRESS, ip), equalTo(NETWORK_PEER_PORT, (long) port), equalTo(DB_SYSTEM, "redis"), 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 086c2dc65693..6eed4eb79d6f 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 @@ -8,7 +8,8 @@ import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesGetter; import javax.annotation.Nullable; -public class SpymemcachedAttributesGetter implements DbClientAttributesGetter { +public class SpymemcachedAttributesGetter + implements DbClientAttributesGetter { @Override public String getDbSystem(SpymemcachedRequest spymemcachedRequest) { 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 928ca141b154..a0803eba3bc0 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 @@ -13,7 +13,7 @@ import javax.annotation.Nullable; public enum VertxRedisClientAttributesGetter - implements DbClientAttributesGetter { + implements DbClientAttributesGetter { INSTANCE; private static final RedisCommandSanitizer sanitizer = 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 92c27b4ddb19..91cdce26d45d 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 @@ -9,7 +9,7 @@ import javax.annotation.Nullable; public enum VertxSqlClientAttributesGetter - implements SqlClientAttributesGetter { + implements SqlClientAttributesGetter { INSTANCE; @Override