diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractor.java index c05e5957af31..a0b8eea0d91c 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractor.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.db; +import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; @@ -25,7 +26,10 @@ public abstract class DbAttributesExtractor protected void onStart(AttributesBuilder attributes, REQUEST request) { set(attributes, SemanticAttributes.DB_SYSTEM, system(request)); set(attributes, SemanticAttributes.DB_USER, user(request)); - set(attributes, SemanticAttributes.DB_NAME, name(request)); + AttributeKey nameAttribute = dbNameAttribute(); + if (nameAttribute != null) { + set(attributes, nameAttribute, name(request)); + } set(attributes, SemanticAttributes.DB_CONNECTION_STRING, connectionString(request)); set(attributes, SemanticAttributes.DB_STATEMENT, statement(request)); set(attributes, SemanticAttributes.DB_OPERATION, operation(request)); @@ -52,4 +56,8 @@ protected final void onEnd( @Nullable protected abstract String operation(REQUEST request); + + protected AttributeKey dbNameAttribute() { + return SemanticAttributes.DB_NAME; + } } diff --git a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraInstrumenters.java b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraInstrumenters.java index b80a272e728a..56f82e321d06 100644 --- a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraInstrumenters.java +++ b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraInstrumenters.java @@ -30,7 +30,6 @@ public final class CassandraInstrumenters { GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanName) .addAttributesExtractor(attributesExtractor) .addAttributesExtractor(new CassandraNetAttributesExtractor()) - .addAttributesExtractor(new CassandraKeyspaceExtractor()) .newInstrumenter(SpanKindExtractor.alwaysClient()); } diff --git a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraKeyspaceExtractor.java b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraKeyspaceExtractor.java deleted file mode 100644 index e32c123db17d..000000000000 --- a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraKeyspaceExtractor.java +++ /dev/null @@ -1,25 +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.api.common.AttributesBuilder; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; - -final class CassandraKeyspaceExtractor - extends AttributesExtractor { - - @Override - protected void onStart(AttributesBuilder attributes, CassandraRequest request) { - attributes.put( - SemanticAttributes.DB_CASSANDRA_KEYSPACE, request.getSession().getLoggedKeyspace()); - } - - @Override - protected void onEnd( - AttributesBuilder attributes, CassandraRequest request, ExecutionInfo response) {} -} diff --git a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraSqlAttributesExtractor.java b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraSqlAttributesExtractor.java index fe17f7345167..3f33eba4aeca 100644 --- a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraSqlAttributesExtractor.java +++ b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraSqlAttributesExtractor.java @@ -37,6 +37,11 @@ protected String connectionString(CassandraRequest request) { return null; } + @Override + protected AttributeKey dbNameAttribute() { + return SemanticAttributes.DB_CASSANDRA_KEYSPACE; + } + @Override protected AttributeKey dbTableAttribute() { return SemanticAttributes.DB_CASSANDRA_TABLE; diff --git a/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/groovy/CassandraClientTest.groovy b/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/groovy/CassandraClientTest.groovy index 30c813d07dae..f3a5e17ea52e 100644 --- a/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/groovy/CassandraClientTest.groovy +++ b/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/groovy/CassandraClientTest.groovy @@ -141,7 +141,6 @@ class CassandraClientTest extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_PEER_IP.key" "127.0.0.1" "$SemanticAttributes.NET_PEER_PORT.key" cassandraPort "$SemanticAttributes.DB_SYSTEM.key" "cassandra" - "$SemanticAttributes.DB_NAME.key" keyspace "$SemanticAttributes.DB_STATEMENT.key" statement "$SemanticAttributes.DB_OPERATION.key" operation "$SemanticAttributes.DB_CASSANDRA_KEYSPACE.key" keyspace diff --git a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraAttributesExtractor.java b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraAttributesExtractor.java index 033cee366a8d..35a07d3c4490 100644 --- a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraAttributesExtractor.java +++ b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraAttributesExtractor.java @@ -5,7 +5,6 @@ package io.opentelemetry.javaagent.instrumentation.cassandra.v4_0; -import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.core.config.DefaultDriverOption; import com.datastax.oss.driver.api.core.config.DriverExecutionProfile; import com.datastax.oss.driver.api.core.cql.ExecutionInfo; @@ -20,12 +19,7 @@ final class CassandraAttributesExtractor extends AttributesExtractor { @Override - protected void onStart(AttributesBuilder attributes, CassandraRequest request) { - set( - attributes, - SemanticAttributes.DB_CASSANDRA_KEYSPACE, - request.getSession().getKeyspace().map(CqlIdentifier::toString).orElse(null)); - } + protected void onStart(AttributesBuilder attributes, CassandraRequest request) {} @Override protected void onEnd( diff --git a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraSqlAttributesExtractor.java b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraSqlAttributesExtractor.java index 37661aab6cf4..c20278acb402 100644 --- a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraSqlAttributesExtractor.java +++ b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraSqlAttributesExtractor.java @@ -26,6 +26,11 @@ protected String user(CassandraRequest request) { return null; } + @Override + protected AttributeKey dbNameAttribute() { + return SemanticAttributes.DB_CASSANDRA_KEYSPACE; + } + @Override @Nullable protected String name(CassandraRequest request) { diff --git a/instrumentation/cassandra/cassandra-4.0/javaagent/src/test/groovy/CassandraClientTest.groovy b/instrumentation/cassandra/cassandra-4.0/javaagent/src/test/groovy/CassandraClientTest.groovy index 338d9dd2b411..0b778bb1f833 100644 --- a/instrumentation/cassandra/cassandra-4.0/javaagent/src/test/groovy/CassandraClientTest.groovy +++ b/instrumentation/cassandra/cassandra-4.0/javaagent/src/test/groovy/CassandraClientTest.groovy @@ -111,7 +111,6 @@ class CassandraClientTest extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_PEER_IP.key" "127.0.0.1" "$SemanticAttributes.NET_PEER_PORT.key" cassandraPort "$SemanticAttributes.DB_SYSTEM.key" "cassandra" - "$SemanticAttributes.DB_NAME.key" keyspace "$SemanticAttributes.DB_STATEMENT.key" statement "$SemanticAttributes.DB_OPERATION.key" operation "$SemanticAttributes.DB_CASSANDRA_CONSISTENCY_LEVEL.key" "LOCAL_ONE"