From 844c2ac2828458827e73f129735b01f2f85bdfa8 Mon Sep 17 00:00:00 2001 From: Nikita Salnikov-Tarnovski Date: Tue, 29 Sep 2020 10:52:02 +0300 Subject: [PATCH 1/3] Review DB semantic conventions --- docs/semantic-conventions.md | 17 ++++++++ .../api/tracer/DatabaseClientTracer.java | 40 ++++++++++++------- .../v3_0/CassandraDatabaseClientTracer.java | 13 +++--- .../v4_0/CassandraDatabaseClientTracer.java | 10 ++--- .../couchbase/v2_0/CouchbaseClientTracer.java | 15 ++----- .../rest/ElasticsearchRestClientTracer.java | 15 ++----- .../ElasticsearchTransportClientTracer.java | 15 ++----- .../auto/geode/GeodeTracer.java | 12 ++---- .../instrumentation/auto/jdbc/JdbcTracer.java | 5 ++- .../auto/jedis/v1_4/JedisClientTracer.java | 15 ++----- .../auto/jedis/v3_0/JedisClientTracer.java | 15 ++----- .../LettuceAbstractDatabaseClientTracer.java | 23 ++++------- ...LettuceConnectionDatabaseClientTracer.java | 4 +- .../v4_0/LettuceDatabaseClientTracer.java | 3 +- .../test/groovy/LettuceAsyncClientTest.groovy | 2 - .../test/groovy/LettuceSyncClientTest.groovy | 2 - .../LettuceAbstractDatabaseClientTracer.java | 19 +++------ ...LettuceConnectionDatabaseClientTracer.java | 4 +- .../v5_0/LettuceDatabaseClientTracer.java | 3 +- .../test/groovy/LettuceAsyncClientTest.groovy | 2 - .../test/groovy/LettuceSyncClientTest.groovy | 2 - .../auto/mongo/MongoClientTracer.java | 10 ++--- .../auto/rediscala/RediscalaClientTracer.java | 15 ++----- .../auto/redisson/RedissonClientTracer.java | 15 ++----- .../spymemcached/MemcacheClientTracer.java | 15 ++----- 25 files changed, 111 insertions(+), 180 deletions(-) diff --git a/docs/semantic-conventions.md b/docs/semantic-conventions.md index fca189d3cc30..e261ce43531f 100644 --- a/docs/semantic-conventions.md +++ b/docs/semantic-conventions.md @@ -72,3 +72,20 @@ not values defined by spec. | `rpc.system` | Y | + | | `rpc.service` | N | + | | `rpc.method` | N | + | + +## Database + +| Attribute | Required | Implemented? | +| -------------- | :---: | :---: | +| `db.system` | Y | + | +| `db.connection_string` | N | only set for Redis, JDBC and MongoDB | +| `db.user` | N | only set for JDBC| +| `db.jdbc.driver_classname` | N | - | +| `db.mssql.instance_name` | N | - | +| `db.name` | N | only set of JDBC, Mongo, Geode and MongoDB | +| `db.statement` | N | +, except for ElasticSearch and Memcached, see `db.operation` | +| `db.operation` | N | only set of ElasticSearch and Memcached | +| `db.cassandra.keyspace` | Y | + | +| `db.hbase` | Y | -, HBase is not supported | +| `db.redis.database_index` | N | only set for Lettuce driver, not for Jedis | +| `db.mongodb.collection` | Y | - | diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/DatabaseClientTracer.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/DatabaseClientTracer.java index 9e0c68a66a5a..9519145add35 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/DatabaseClientTracer.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/DatabaseClientTracer.java @@ -30,6 +30,7 @@ import io.opentelemetry.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; import java.util.concurrent.ExecutionException; +import org.checkerframework.checker.nullness.qual.NonNull; public abstract class DatabaseClientTracer extends BaseTracer { @@ -46,14 +47,14 @@ public Span startSpan(CONNECTION connection, QUERY query) { Span span = tracer - .spanBuilder(spanName(normalizedQuery)) + .spanBuilder(spanName(normalizedQuery, connection)) .setSpanKind(CLIENT) .setAttribute(SemanticAttributes.DB_SYSTEM, dbSystem(connection)) .startSpan(); if (connection != null) { onConnection(span, connection); - onPeerConnection(span, connection); + setNetSemanticConvention(span, connection); } onStatement(span, normalizedQuery); @@ -111,7 +112,7 @@ protected void onError(Span span, Throwable throwable) { } } - protected void onPeerConnection(Span span, CONNECTION connection) { + protected void setNetSemanticConvention(Span span, CONNECTION connection) { NetPeerUtils.setNetPeer(span, peerAddress(connection)); } @@ -119,24 +120,35 @@ protected void onStatement(Span span, String statement) { span.setAttribute(SemanticAttributes.DB_STATEMENT, statement); } - // TODO: "When it's impossible to get any meaningful representation of the span name, it can be - // populated using the same value as db.name" (c) spec - protected String spanName(String query) { - return query == null ? DB_QUERY : query; - } - - protected abstract String normalizeQuery(QUERY query); + protected abstract @NonNull String normalizeQuery(QUERY query); - protected abstract String dbSystem(CONNECTION connection); + protected abstract @NonNull String dbSystem(CONNECTION connection); - protected abstract String dbUser(CONNECTION connection); + protected String dbUser(CONNECTION connection) { + return null; + } - protected abstract String dbName(CONNECTION connection); + protected String dbName(CONNECTION connection) { + return null; + } - // TODO make abstract after implementing in all subclasses protected String dbConnectionString(CONNECTION connection) { return null; } protected abstract InetSocketAddress peerAddress(CONNECTION connection); + + // TODO: "When it's impossible to get any meaningful representation of the span name, it can be + // populated using the same value as db.name" (c) spec + private String spanName(String query, CONNECTION connection) { + if (query != null) { + return query; + } + + String result = null; + if (connection != null) { + result = dbName(connection); + } + return result == null ? DB_QUERY : result; + } } diff --git a/instrumentation/cassandra/cassandra-3.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v3_0/CassandraDatabaseClientTracer.java b/instrumentation/cassandra/cassandra-3.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v3_0/CassandraDatabaseClientTracer.java index 8feaf11d2266..16c7d6f50a4b 100644 --- a/instrumentation/cassandra/cassandra-3.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v3_0/CassandraDatabaseClientTracer.java +++ b/instrumentation/cassandra/cassandra-3.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v3_0/CassandraDatabaseClientTracer.java @@ -23,7 +23,9 @@ import io.opentelemetry.instrumentation.api.tracer.utils.NetPeerUtils; import io.opentelemetry.instrumentation.auto.api.jdbc.DbSystem; import io.opentelemetry.trace.Span; +import io.opentelemetry.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; +import org.checkerframework.checker.nullness.qual.NonNull; public class CassandraDatabaseClientTracer extends DatabaseClientTracer { public static final CassandraDatabaseClientTracer TRACER = new CassandraDatabaseClientTracer(); @@ -34,23 +36,24 @@ protected String getInstrumentationName() { } @Override - protected String normalizeQuery(String query) { + protected @NonNull String normalizeQuery(String query) { return query; } @Override - protected String dbSystem(Session session) { + protected @NonNull String dbSystem(Session session) { return DbSystem.CASSANDRA; } @Override - protected String dbUser(Session session) { + protected String dbName(Session session) { return null; } @Override - protected String dbName(Session session) { - return session.getLoggedKeyspace(); + protected Span onConnection(Span span, Session session) { + span.setAttribute(SemanticAttributes.CASSANDRA_KEYSPACE, session.getLoggedKeyspace()); + return super.onConnection(span, session); } @Override diff --git a/instrumentation/cassandra/cassandra-4.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v4_0/CassandraDatabaseClientTracer.java b/instrumentation/cassandra/cassandra-4.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v4_0/CassandraDatabaseClientTracer.java index 3267d40e7433..23afee131550 100644 --- a/instrumentation/cassandra/cassandra-4.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v4_0/CassandraDatabaseClientTracer.java +++ b/instrumentation/cassandra/cassandra-4.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v4_0/CassandraDatabaseClientTracer.java @@ -26,6 +26,7 @@ import io.opentelemetry.trace.Span; import java.net.InetSocketAddress; import java.util.Optional; +import org.checkerframework.checker.nullness.qual.NonNull; public class CassandraDatabaseClientTracer extends DatabaseClientTracer { public static final CassandraDatabaseClientTracer TRACER = new CassandraDatabaseClientTracer(); @@ -36,20 +37,15 @@ protected String getInstrumentationName() { } @Override - protected String normalizeQuery(String query) { + protected @NonNull String normalizeQuery(String query) { return query; } @Override - protected String dbSystem(CqlSession session) { + protected @NonNull String dbSystem(CqlSession session) { return DbSystem.CASSANDRA; } - @Override - protected String dbUser(CqlSession session) { - return null; - } - @Override protected String dbName(CqlSession session) { return session.getKeyspace().map(CqlIdentifier::toString).orElse(null); diff --git a/instrumentation/couchbase/couchbase-2.0/src/main/java/io/opentelemetry/instrumentation/auto/couchbase/v2_0/CouchbaseClientTracer.java b/instrumentation/couchbase/couchbase-2.0/src/main/java/io/opentelemetry/instrumentation/auto/couchbase/v2_0/CouchbaseClientTracer.java index 71db420801bc..f517e5d6ac92 100644 --- a/instrumentation/couchbase/couchbase-2.0/src/main/java/io/opentelemetry/instrumentation/auto/couchbase/v2_0/CouchbaseClientTracer.java +++ b/instrumentation/couchbase/couchbase-2.0/src/main/java/io/opentelemetry/instrumentation/auto/couchbase/v2_0/CouchbaseClientTracer.java @@ -20,12 +20,13 @@ import io.opentelemetry.instrumentation.auto.api.jdbc.DbSystem; import java.lang.reflect.Method; import java.net.InetSocketAddress; +import org.checkerframework.checker.nullness.qual.NonNull; public class CouchbaseClientTracer extends DatabaseClientTracer { public static final CouchbaseClientTracer TRACER = new CouchbaseClientTracer(); @Override - protected String normalizeQuery(Method method) { + protected @NonNull String normalizeQuery(Method method) { Class declaringClass = method.getDeclaringClass(); String className = declaringClass.getSimpleName().replace("CouchbaseAsync", "").replace("DefaultAsync", ""); @@ -33,20 +34,10 @@ protected String normalizeQuery(Method method) { } @Override - protected String dbSystem(Void connection) { + protected @NonNull String dbSystem(Void connection) { return DbSystem.COUCHBASE; } - @Override - protected String dbUser(Void connection) { - return null; - } - - @Override - protected String dbName(Void connection) { - return null; - } - @Override protected InetSocketAddress peerAddress(Void connection) { return null; diff --git a/instrumentation/elasticsearch/elasticsearch-rest-common/src/main/java/io/opentelemetry/instrumentation/auto/elasticsearch/rest/ElasticsearchRestClientTracer.java b/instrumentation/elasticsearch/elasticsearch-rest-common/src/main/java/io/opentelemetry/instrumentation/auto/elasticsearch/rest/ElasticsearchRestClientTracer.java index 1c00ee960bf4..4617dfd5b02b 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-common/src/main/java/io/opentelemetry/instrumentation/auto/elasticsearch/rest/ElasticsearchRestClientTracer.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-common/src/main/java/io/opentelemetry/instrumentation/auto/elasticsearch/rest/ElasticsearchRestClientTracer.java @@ -21,6 +21,7 @@ import io.opentelemetry.trace.Span; import io.opentelemetry.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; +import org.checkerframework.checker.nullness.qual.NonNull; import org.elasticsearch.client.Response; public class ElasticsearchRestClientTracer extends DatabaseClientTracer { @@ -46,25 +47,15 @@ protected void onStatement(Span span, String statement) { } @Override - protected String normalizeQuery(String query) { + protected @NonNull String normalizeQuery(String query) { return query; } @Override - protected String dbSystem(Void connection) { + protected @NonNull String dbSystem(Void connection) { return "elasticsearch"; } - @Override - protected String dbUser(Void connection) { - return null; - } - - @Override - protected String dbName(Void connection) { - return null; - } - @Override protected InetSocketAddress peerAddress(Void connection) { return null; diff --git a/instrumentation/elasticsearch/elasticsearch-transport-common/src/main/java/io/opentelemetry/instrumentation/auto/elasticsearch/transport/ElasticsearchTransportClientTracer.java b/instrumentation/elasticsearch/elasticsearch-transport-common/src/main/java/io/opentelemetry/instrumentation/auto/elasticsearch/transport/ElasticsearchTransportClientTracer.java index 864f9ca406e3..4bd892bd15ff 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-common/src/main/java/io/opentelemetry/instrumentation/auto/elasticsearch/transport/ElasticsearchTransportClientTracer.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-common/src/main/java/io/opentelemetry/instrumentation/auto/elasticsearch/transport/ElasticsearchTransportClientTracer.java @@ -20,6 +20,7 @@ import io.opentelemetry.trace.Span; import io.opentelemetry.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; +import org.checkerframework.checker.nullness.qual.NonNull; import org.elasticsearch.action.Action; public class ElasticsearchTransportClientTracer @@ -34,25 +35,15 @@ public Span onRequest(Span span, Class action, Class request) { } @Override - protected String normalizeQuery(Action query) { + protected @NonNull String normalizeQuery(Action query) { return query.getClass().getSimpleName(); } @Override - protected String dbSystem(Void connection) { + protected @NonNull String dbSystem(Void connection) { return "elasticsearch"; } - @Override - protected String dbUser(Void connection) { - return null; - } - - @Override - protected String dbName(Void connection) { - return null; - } - @Override protected InetSocketAddress peerAddress(Void connection) { return null; diff --git a/instrumentation/geode-1.4/src/main/java/io/opentelemetry/instrumentation/auto/geode/GeodeTracer.java b/instrumentation/geode-1.4/src/main/java/io/opentelemetry/instrumentation/auto/geode/GeodeTracer.java index 6e8d6d373f0d..57c143db0aec 100644 --- a/instrumentation/geode-1.4/src/main/java/io/opentelemetry/instrumentation/auto/geode/GeodeTracer.java +++ b/instrumentation/geode-1.4/src/main/java/io/opentelemetry/instrumentation/auto/geode/GeodeTracer.java @@ -24,6 +24,7 @@ import io.opentelemetry.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; import org.apache.geode.cache.Region; +import org.checkerframework.checker.nullness.qual.NonNull; public class GeodeTracer extends DatabaseClientTracer, String> { public static GeodeTracer TRACER = new GeodeTracer(); @@ -40,27 +41,22 @@ public Span startSpan(String operation, Region connection, String query) { .startSpan(); onConnection(span, connection); - onPeerConnection(span, connection); + setNetSemanticConvention(span, connection); onStatement(span, normalizedQuery); return span; } @Override - protected String normalizeQuery(String query) { + protected @NonNull String normalizeQuery(String query) { return query; } @Override - protected String dbSystem(Region region) { + protected @NonNull String dbSystem(Region region) { return DbSystem.GEODE; } - @Override - protected String dbUser(Region region) { - return null; - } - @Override protected String dbName(Region region) { return region.getName(); diff --git a/instrumentation/jdbc/src/main/java/io/opentelemetry/instrumentation/auto/jdbc/JdbcTracer.java b/instrumentation/jdbc/src/main/java/io/opentelemetry/instrumentation/auto/jdbc/JdbcTracer.java index f335e43aaee0..8ab957c79bd5 100644 --- a/instrumentation/jdbc/src/main/java/io/opentelemetry/instrumentation/auto/jdbc/JdbcTracer.java +++ b/instrumentation/jdbc/src/main/java/io/opentelemetry/instrumentation/auto/jdbc/JdbcTracer.java @@ -30,6 +30,7 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; +import org.checkerframework.checker.nullness.qual.NonNull; public class JdbcTracer extends DatabaseClientTracer { public static final JdbcTracer TRACER = new JdbcTracer(); @@ -40,7 +41,7 @@ protected String getInstrumentationName() { } @Override - protected String dbSystem(DBInfo info) { + protected @NonNull String dbSystem(DBInfo info) { return info.getSystem(); } @@ -89,7 +90,7 @@ public Span startSpan(Statement statement, String query) { } @Override - protected String normalizeQuery(String query) { + protected @NonNull String normalizeQuery(String query) { return JDBCUtils.normalizeSql(query); } diff --git a/instrumentation/jedis/jedis-1.4/src/main/java/io/opentelemetry/instrumentation/auto/jedis/v1_4/JedisClientTracer.java b/instrumentation/jedis/jedis-1.4/src/main/java/io/opentelemetry/instrumentation/auto/jedis/v1_4/JedisClientTracer.java index b4af4aaf090b..18edd6a16bd2 100644 --- a/instrumentation/jedis/jedis-1.4/src/main/java/io/opentelemetry/instrumentation/auto/jedis/v1_4/JedisClientTracer.java +++ b/instrumentation/jedis/jedis-1.4/src/main/java/io/opentelemetry/instrumentation/auto/jedis/v1_4/JedisClientTracer.java @@ -19,6 +19,7 @@ import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer; import io.opentelemetry.instrumentation.auto.api.jdbc.DbSystem; import java.net.InetSocketAddress; +import org.checkerframework.checker.nullness.qual.NonNull; import redis.clients.jedis.Connection; import redis.clients.jedis.Protocol.Command; @@ -26,25 +27,15 @@ public class JedisClientTracer extends DatabaseClientTracer public static final JedisClientTracer TRACER = new JedisClientTracer(); @Override - protected String normalizeQuery(Command command) { + protected @NonNull String normalizeQuery(Command command) { return command.name(); } @Override - protected String dbSystem(Connection connection) { + protected @NonNull String dbSystem(Connection connection) { return DbSystem.REDIS; } - @Override - protected String dbUser(Connection connection) { - return null; - } - - @Override - protected String dbName(Connection connection) { - return null; - } - @Override protected String dbConnectionString(Connection connection) { return connection.getHost() + ":" + connection.getPort(); diff --git a/instrumentation/jedis/jedis-3.0/src/main/java/io/opentelemetry/instrumentation/auto/jedis/v3_0/JedisClientTracer.java b/instrumentation/jedis/jedis-3.0/src/main/java/io/opentelemetry/instrumentation/auto/jedis/v3_0/JedisClientTracer.java index 112dad7372ef..3559365b1cb4 100644 --- a/instrumentation/jedis/jedis-3.0/src/main/java/io/opentelemetry/instrumentation/auto/jedis/v3_0/JedisClientTracer.java +++ b/instrumentation/jedis/jedis-3.0/src/main/java/io/opentelemetry/instrumentation/auto/jedis/v3_0/JedisClientTracer.java @@ -20,6 +20,7 @@ import io.opentelemetry.instrumentation.auto.api.jdbc.DbSystem; import java.net.InetSocketAddress; import java.nio.charset.StandardCharsets; +import org.checkerframework.checker.nullness.qual.NonNull; import redis.clients.jedis.Connection; import redis.clients.jedis.Protocol; import redis.clients.jedis.commands.ProtocolCommand; @@ -28,7 +29,7 @@ public class JedisClientTracer extends DatabaseClientTracer extends DatabaseClientTracer { @Override - protected String dbSystem(RedisURI connection) { + protected @NonNull String dbSystem(RedisURI connection) { return DbSystem.REDIS; } - @Override - protected String dbUser(RedisURI connection) { - return null; - } - - @Override - protected String dbName(RedisURI connection) { - return null; - } - @Override protected InetSocketAddress peerAddress(RedisURI redisURI) { - return null; + return new InetSocketAddress(redisURI.getHost(), redisURI.getPort()); } @Override public Span onConnection(Span span, RedisURI connection) { - if (connection != null) { - NetPeerUtils.setNetPeer(span, connection.getHost(), connection.getPort()); - span.setAttribute("db.redis.dbIndex", connection.getDatabase()); + if (connection != null && connection.getDatabase() != 0) { + span.setAttribute( + SemanticAttributes.REDIS_DATABASE_INDEX, String.valueOf(connection.getDatabase())); } return super.onConnection(span, connection); } diff --git a/instrumentation/lettuce/lettuce-4.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v4_0/LettuceConnectionDatabaseClientTracer.java b/instrumentation/lettuce/lettuce-4.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v4_0/LettuceConnectionDatabaseClientTracer.java index f256349bdc0e..357ddff88074 100644 --- a/instrumentation/lettuce/lettuce-4.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v4_0/LettuceConnectionDatabaseClientTracer.java +++ b/instrumentation/lettuce/lettuce-4.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v4_0/LettuceConnectionDatabaseClientTracer.java @@ -16,6 +16,8 @@ package io.opentelemetry.instrumentation.auto.lettuce.v4_0; +import org.checkerframework.checker.nullness.qual.NonNull; + public class LettuceConnectionDatabaseClientTracer extends LettuceAbstractDatabaseClientTracer { @@ -23,7 +25,7 @@ public class LettuceConnectionDatabaseClientTracer new LettuceConnectionDatabaseClientTracer(); @Override - protected String normalizeQuery(String command) { + protected @NonNull String normalizeQuery(String command) { return command; } } diff --git a/instrumentation/lettuce/lettuce-4.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v4_0/LettuceDatabaseClientTracer.java b/instrumentation/lettuce/lettuce-4.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v4_0/LettuceDatabaseClientTracer.java index f1fb27e7af1e..b0cd5a64aba0 100644 --- a/instrumentation/lettuce/lettuce-4.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v4_0/LettuceDatabaseClientTracer.java +++ b/instrumentation/lettuce/lettuce-4.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v4_0/LettuceDatabaseClientTracer.java @@ -17,6 +17,7 @@ package io.opentelemetry.instrumentation.auto.lettuce.v4_0; import com.lambdaworks.redis.protocol.RedisCommand; +import org.checkerframework.checker.nullness.qual.NonNull; public class LettuceDatabaseClientTracer extends LettuceAbstractDatabaseClientTracer> { @@ -24,7 +25,7 @@ public class LettuceDatabaseClientTracer public static final LettuceDatabaseClientTracer TRACER = new LettuceDatabaseClientTracer(); @Override - protected String normalizeQuery(RedisCommand command) { + protected @NonNull String normalizeQuery(RedisCommand command) { return command.getType().name(); } } diff --git a/instrumentation/lettuce/lettuce-4.0/src/test/groovy/LettuceAsyncClientTest.groovy b/instrumentation/lettuce/lettuce-4.0/src/test/groovy/LettuceAsyncClientTest.groovy index 7095a3b8d798..9a7433cd8bb5 100644 --- a/instrumentation/lettuce/lettuce-4.0/src/test/groovy/LettuceAsyncClientTest.groovy +++ b/instrumentation/lettuce/lettuce-4.0/src/test/groovy/LettuceAsyncClientTest.groovy @@ -135,7 +135,6 @@ class LettuceAsyncClientTest extends AgentTestRunner { "${SemanticAttributes.NET_PEER_PORT.key()}" port "${SemanticAttributes.DB_SYSTEM.key()}" "redis" "${SemanticAttributes.DB_STATEMENT.key()}" "CONNECT" - "db.redis.dbIndex" 0 } } } @@ -170,7 +169,6 @@ class LettuceAsyncClientTest extends AgentTestRunner { "${SemanticAttributes.NET_PEER_PORT.key()}" incorrectPort "${SemanticAttributes.DB_SYSTEM.key()}" "redis" "${SemanticAttributes.DB_STATEMENT.key()}" "CONNECT" - "db.redis.dbIndex" 0 } } } diff --git a/instrumentation/lettuce/lettuce-4.0/src/test/groovy/LettuceSyncClientTest.groovy b/instrumentation/lettuce/lettuce-4.0/src/test/groovy/LettuceSyncClientTest.groovy index f362cda9b154..2befa5a685ea 100644 --- a/instrumentation/lettuce/lettuce-4.0/src/test/groovy/LettuceSyncClientTest.groovy +++ b/instrumentation/lettuce/lettuce-4.0/src/test/groovy/LettuceSyncClientTest.groovy @@ -117,7 +117,6 @@ class LettuceSyncClientTest extends AgentTestRunner { "${SemanticAttributes.NET_PEER_PORT.key()}" port "${SemanticAttributes.DB_SYSTEM.key()}" "redis" "${SemanticAttributes.DB_STATEMENT.key()}" "CONNECT" - "db.redis.dbIndex" 0 } } } @@ -150,7 +149,6 @@ class LettuceSyncClientTest extends AgentTestRunner { "${SemanticAttributes.NET_PEER_PORT.key()}" incorrectPort "${SemanticAttributes.DB_SYSTEM.key()}" "redis" "${SemanticAttributes.DB_STATEMENT.key()}" "CONNECT" - "db.redis.dbIndex" 0 } } } diff --git a/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceAbstractDatabaseClientTracer.java b/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceAbstractDatabaseClientTracer.java index c54bc1bb97aa..df5890bf047a 100644 --- a/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceAbstractDatabaseClientTracer.java +++ b/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceAbstractDatabaseClientTracer.java @@ -20,7 +20,9 @@ import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer; import io.opentelemetry.instrumentation.auto.api.jdbc.DbSystem; import io.opentelemetry.trace.Span; +import io.opentelemetry.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; +import org.checkerframework.checker.nullness.qual.NonNull; public abstract class LettuceAbstractDatabaseClientTracer extends DatabaseClientTracer { @@ -30,20 +32,10 @@ protected String getInstrumentationName() { } @Override - protected String dbSystem(RedisURI connection) { + protected @NonNull String dbSystem(RedisURI connection) { return DbSystem.REDIS; } - @Override - protected String dbUser(RedisURI connection) { - return null; - } - - @Override - protected String dbName(RedisURI connection) { - return null; - } - @Override protected InetSocketAddress peerAddress(RedisURI redisURI) { return new InetSocketAddress(redisURI.getHost(), redisURI.getPort()); @@ -51,8 +43,9 @@ protected InetSocketAddress peerAddress(RedisURI redisURI) { @Override public Span onConnection(Span span, RedisURI connection) { - if (connection != null) { - span.setAttribute("db.redis.dbIndex", connection.getDatabase()); + if (connection != null && connection.getDatabase() != 0) { + span.setAttribute( + SemanticAttributes.REDIS_DATABASE_INDEX, String.valueOf(connection.getDatabase())); } return super.onConnection(span, connection); } diff --git a/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceConnectionDatabaseClientTracer.java b/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceConnectionDatabaseClientTracer.java index c44e285ad4c7..bffa744cb46a 100644 --- a/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceConnectionDatabaseClientTracer.java +++ b/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceConnectionDatabaseClientTracer.java @@ -16,13 +16,15 @@ package io.opentelemetry.instrumentation.auto.lettuce.v5_0; +import org.checkerframework.checker.nullness.qual.NonNull; + public class LettuceConnectionDatabaseClientTracer extends LettuceAbstractDatabaseClientTracer { public static final LettuceConnectionDatabaseClientTracer TRACER = new LettuceConnectionDatabaseClientTracer(); @Override - protected String normalizeQuery(String query) { + protected @NonNull String normalizeQuery(String query) { return query; } } diff --git a/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceDatabaseClientTracer.java b/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceDatabaseClientTracer.java index 53b223971061..3d8a883128f2 100644 --- a/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceDatabaseClientTracer.java +++ b/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceDatabaseClientTracer.java @@ -17,13 +17,14 @@ package io.opentelemetry.instrumentation.auto.lettuce.v5_0; import io.lettuce.core.protocol.RedisCommand; +import org.checkerframework.checker.nullness.qual.NonNull; public class LettuceDatabaseClientTracer extends LettuceAbstractDatabaseClientTracer> { public static final LettuceDatabaseClientTracer TRACER = new LettuceDatabaseClientTracer(); @Override - protected String normalizeQuery(RedisCommand command) { + protected @NonNull String normalizeQuery(RedisCommand command) { return LettuceInstrumentationUtil.getCommandName(command); } } diff --git a/instrumentation/lettuce/lettuce-5.0/src/test/groovy/LettuceAsyncClientTest.groovy b/instrumentation/lettuce/lettuce-5.0/src/test/groovy/LettuceAsyncClientTest.groovy index 4ecb644374b0..a66a0709f7c6 100644 --- a/instrumentation/lettuce/lettuce-5.0/src/test/groovy/LettuceAsyncClientTest.groovy +++ b/instrumentation/lettuce/lettuce-5.0/src/test/groovy/LettuceAsyncClientTest.groovy @@ -139,7 +139,6 @@ class LettuceAsyncClientTest extends AgentTestRunner { "${SemanticAttributes.NET_PEER_PORT.key()}" port "${SemanticAttributes.DB_SYSTEM.key()}" "redis" "${SemanticAttributes.DB_STATEMENT.key()}" "CONNECT" - "db.redis.dbIndex" 0 } } } @@ -175,7 +174,6 @@ class LettuceAsyncClientTest extends AgentTestRunner { "${SemanticAttributes.NET_PEER_PORT.key()}" incorrectPort "${SemanticAttributes.DB_SYSTEM.key()}" "redis" "${SemanticAttributes.DB_STATEMENT.key()}" "CONNECT" - "db.redis.dbIndex" 0 } } } diff --git a/instrumentation/lettuce/lettuce-5.0/src/test/groovy/LettuceSyncClientTest.groovy b/instrumentation/lettuce/lettuce-5.0/src/test/groovy/LettuceSyncClientTest.groovy index ddd0a7c102cb..8d0b1f3343d5 100644 --- a/instrumentation/lettuce/lettuce-5.0/src/test/groovy/LettuceSyncClientTest.groovy +++ b/instrumentation/lettuce/lettuce-5.0/src/test/groovy/LettuceSyncClientTest.groovy @@ -119,7 +119,6 @@ class LettuceSyncClientTest extends AgentTestRunner { "${SemanticAttributes.NET_PEER_PORT.key()}" port "${SemanticAttributes.DB_SYSTEM.key()}" "redis" "${SemanticAttributes.DB_STATEMENT.key()}" "CONNECT" - "db.redis.dbIndex" 0 } } } @@ -152,7 +151,6 @@ class LettuceSyncClientTest extends AgentTestRunner { "${SemanticAttributes.NET_PEER_PORT.key()}" incorrectPort "${SemanticAttributes.DB_SYSTEM.key()}" "redis" "${SemanticAttributes.DB_STATEMENT.key()}" "CONNECT" - "db.redis.dbIndex" 0 } } } diff --git a/instrumentation/mongo/mongo-common/src/main/java/io/opentelemetry/instrumentation/auto/mongo/MongoClientTracer.java b/instrumentation/mongo/mongo-common/src/main/java/io/opentelemetry/instrumentation/auto/mongo/MongoClientTracer.java index 0f1d5773df04..24ee087beddd 100644 --- a/instrumentation/mongo/mongo-common/src/main/java/io/opentelemetry/instrumentation/auto/mongo/MongoClientTracer.java +++ b/instrumentation/mongo/mongo-common/src/main/java/io/opentelemetry/instrumentation/auto/mongo/MongoClientTracer.java @@ -32,6 +32,7 @@ import org.bson.BsonDocument; import org.bson.BsonString; import org.bson.BsonValue; +import org.checkerframework.checker.nullness.qual.NonNull; public class MongoClientTracer extends DatabaseClientTracer { public static final MongoClientTracer TRACER = new MongoClientTracer(); @@ -43,15 +44,10 @@ protected String getInstrumentationName() { } @Override - protected String dbSystem(CommandStartedEvent event) { + protected @NonNull String dbSystem(CommandStartedEvent event) { return DbSystem.MONGODB; } - @Override - protected String dbUser(CommandStartedEvent event) { - return null; - } - @Override protected String dbName(CommandStartedEvent event) { // Use description if set. @@ -103,7 +99,7 @@ protected String dbConnectionString(CommandStartedEvent event) { } @Override - public String normalizeQuery(BsonDocument statement) { + public @NonNull String normalizeQuery(BsonDocument statement) { // scrub the Mongo command so that parameters are removed from the string BsonDocument scrubbed = scrub(statement); return scrubbed.toString(); diff --git a/instrumentation/rediscala-1.8/src/main/java/io/opentelemetry/instrumentation/auto/rediscala/RediscalaClientTracer.java b/instrumentation/rediscala-1.8/src/main/java/io/opentelemetry/instrumentation/auto/rediscala/RediscalaClientTracer.java index 91879757db7d..a1dbcfdf9719 100644 --- a/instrumentation/rediscala-1.8/src/main/java/io/opentelemetry/instrumentation/auto/rediscala/RediscalaClientTracer.java +++ b/instrumentation/rediscala-1.8/src/main/java/io/opentelemetry/instrumentation/auto/rediscala/RediscalaClientTracer.java @@ -19,6 +19,7 @@ import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer; import io.opentelemetry.instrumentation.auto.api.jdbc.DbSystem; import java.net.InetSocketAddress; +import org.checkerframework.checker.nullness.qual.NonNull; import redis.RedisCommand; public class RediscalaClientTracer @@ -27,22 +28,12 @@ public class RediscalaClientTracer public static final RediscalaClientTracer TRACER = new RediscalaClientTracer(); @Override - protected String dbUser(RedisCommand command) { - return null; - } - - @Override - protected String dbName(RedisCommand command) { - return null; - } - - @Override - protected String normalizeQuery(RedisCommand redisCommand) { + protected @NonNull String normalizeQuery(RedisCommand redisCommand) { return spanNameForClass(redisCommand.getClass()); } @Override - protected String dbSystem(RedisCommand redisCommand) { + protected @NonNull String dbSystem(RedisCommand redisCommand) { return DbSystem.REDIS; } diff --git a/instrumentation/redisson-3.0/src/main/java/io/opentelemetry/instrumentation/auto/redisson/RedissonClientTracer.java b/instrumentation/redisson-3.0/src/main/java/io/opentelemetry/instrumentation/auto/redisson/RedissonClientTracer.java index 85e02dd8e558..c31d064bf12c 100644 --- a/instrumentation/redisson-3.0/src/main/java/io/opentelemetry/instrumentation/auto/redisson/RedissonClientTracer.java +++ b/instrumentation/redisson-3.0/src/main/java/io/opentelemetry/instrumentation/auto/redisson/RedissonClientTracer.java @@ -21,6 +21,7 @@ import io.opentelemetry.instrumentation.auto.api.jdbc.DbSystem; import java.net.InetSocketAddress; import java.util.List; +import org.checkerframework.checker.nullness.qual.NonNull; import org.redisson.client.RedisConnection; import org.redisson.client.protocol.CommandData; import org.redisson.client.protocol.CommandsData; @@ -35,7 +36,7 @@ protected String getInstrumentationName() { } @Override - protected String normalizeQuery(Object args) { + protected @NonNull String normalizeQuery(Object args) { // get command if (args instanceof CommandsData) { List> commands = ((CommandsData) args).getCommands(); @@ -54,20 +55,10 @@ protected String normalizeQuery(Object args) { } @Override - protected String dbSystem(RedisConnection connection) { + protected @NonNull String dbSystem(RedisConnection connection) { return DbSystem.REDIS; } - @Override - protected String dbUser(RedisConnection o) { - return null; - } - - @Override - protected String dbName(RedisConnection o) { - return null; - } - @Override protected InetSocketAddress peerAddress(RedisConnection connection) { Channel channel = connection.getChannel(); diff --git a/instrumentation/spymemcached-2.12/src/main/java/io/opentelemetry/instrumentation/auto/spymemcached/MemcacheClientTracer.java b/instrumentation/spymemcached-2.12/src/main/java/io/opentelemetry/instrumentation/auto/spymemcached/MemcacheClientTracer.java index ec2cb05abc16..2a90cd601960 100644 --- a/instrumentation/spymemcached-2.12/src/main/java/io/opentelemetry/instrumentation/auto/spymemcached/MemcacheClientTracer.java +++ b/instrumentation/spymemcached-2.12/src/main/java/io/opentelemetry/instrumentation/auto/spymemcached/MemcacheClientTracer.java @@ -21,25 +21,16 @@ import io.opentelemetry.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; import net.spy.memcached.MemcachedConnection; +import org.checkerframework.checker.nullness.qual.NonNull; public class MemcacheClientTracer extends DatabaseClientTracer { public static final MemcacheClientTracer TRACER = new MemcacheClientTracer(); @Override - protected String dbSystem(MemcachedConnection memcachedConnection) { + protected @NonNull String dbSystem(MemcachedConnection memcachedConnection) { return "memcached"; } - @Override - protected String dbUser(MemcachedConnection session) { - return null; - } - - @Override - protected String dbName(MemcachedConnection connection) { - return null; - } - @Override protected InetSocketAddress peerAddress(MemcachedConnection memcachedConnection) { return null; @@ -51,7 +42,7 @@ protected void onStatement(Span span, String statement) { } @Override - protected String normalizeQuery(String query) { + protected @NonNull String normalizeQuery(String query) { char[] chars = query .replaceFirst("^async", "") From 747c546cd45c6cd89588551fa77f53b7f024e5b2 Mon Sep 17 00:00:00 2001 From: Nikita Salnikov-Tarnovski Date: Thu, 1 Oct 2020 15:13:20 +0300 Subject: [PATCH 2/3] Polish --- .../instrumentation/api/tracer/DatabaseClientTracer.java | 7 ++----- .../auto/cassandra/v3_0/CassandraDatabaseClientTracer.java | 5 ++--- .../auto/cassandra/v4_0/CassandraDatabaseClientTracer.java | 5 ++--- .../auto/couchbase/v2_0/CouchbaseClientTracer.java | 5 ++--- .../elasticsearch/rest/ElasticsearchRestClientTracer.java | 5 ++--- .../transport/ElasticsearchTransportClientTracer.java | 5 ++--- .../instrumentation/auto/geode/GeodeTracer.java | 5 ++--- .../instrumentation/auto/jdbc/JdbcTracer.java | 5 ++--- .../instrumentation/auto/jedis/v1_4/JedisClientTracer.java | 5 ++--- .../instrumentation/auto/jedis/v3_0/JedisClientTracer.java | 5 ++--- .../lettuce/v4_0/LettuceAbstractDatabaseClientTracer.java | 3 +-- .../v4_0/LettuceConnectionDatabaseClientTracer.java | 4 +--- .../auto/lettuce/v4_0/LettuceDatabaseClientTracer.java | 3 +-- .../lettuce/v5_0/LettuceAbstractDatabaseClientTracer.java | 3 +-- .../v5_0/LettuceConnectionDatabaseClientTracer.java | 4 +--- .../auto/lettuce/v5_0/LettuceDatabaseClientTracer.java | 3 +-- .../instrumentation/auto/mongo/MongoClientTracer.java | 5 ++--- .../auto/rediscala/RediscalaClientTracer.java | 5 ++--- .../auto/redisson/RedissonClientTracer.java | 5 ++--- .../auto/spymemcached/MemcacheClientTracer.java | 5 ++--- 20 files changed, 34 insertions(+), 58 deletions(-) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/DatabaseClientTracer.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/DatabaseClientTracer.java index 9519145add35..22fb89a67716 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/DatabaseClientTracer.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/DatabaseClientTracer.java @@ -30,7 +30,6 @@ import io.opentelemetry.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; import java.util.concurrent.ExecutionException; -import org.checkerframework.checker.nullness.qual.NonNull; public abstract class DatabaseClientTracer extends BaseTracer { @@ -120,9 +119,9 @@ protected void onStatement(Span span, String statement) { span.setAttribute(SemanticAttributes.DB_STATEMENT, statement); } - protected abstract @NonNull String normalizeQuery(QUERY query); + protected abstract String normalizeQuery(QUERY query); - protected abstract @NonNull String dbSystem(CONNECTION connection); + protected abstract String dbSystem(CONNECTION connection); protected String dbUser(CONNECTION connection) { return null; @@ -138,8 +137,6 @@ protected String dbConnectionString(CONNECTION connection) { protected abstract InetSocketAddress peerAddress(CONNECTION connection); - // TODO: "When it's impossible to get any meaningful representation of the span name, it can be - // populated using the same value as db.name" (c) spec private String spanName(String query, CONNECTION connection) { if (query != null) { return query; diff --git a/instrumentation/cassandra/cassandra-3.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v3_0/CassandraDatabaseClientTracer.java b/instrumentation/cassandra/cassandra-3.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v3_0/CassandraDatabaseClientTracer.java index 16c7d6f50a4b..22cffedb2a0e 100644 --- a/instrumentation/cassandra/cassandra-3.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v3_0/CassandraDatabaseClientTracer.java +++ b/instrumentation/cassandra/cassandra-3.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v3_0/CassandraDatabaseClientTracer.java @@ -25,7 +25,6 @@ import io.opentelemetry.trace.Span; import io.opentelemetry.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; -import org.checkerframework.checker.nullness.qual.NonNull; public class CassandraDatabaseClientTracer extends DatabaseClientTracer { public static final CassandraDatabaseClientTracer TRACER = new CassandraDatabaseClientTracer(); @@ -36,12 +35,12 @@ protected String getInstrumentationName() { } @Override - protected @NonNull String normalizeQuery(String query) { + protected String normalizeQuery(String query) { return query; } @Override - protected @NonNull String dbSystem(Session session) { + protected String dbSystem(Session session) { return DbSystem.CASSANDRA; } diff --git a/instrumentation/cassandra/cassandra-4.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v4_0/CassandraDatabaseClientTracer.java b/instrumentation/cassandra/cassandra-4.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v4_0/CassandraDatabaseClientTracer.java index 23afee131550..28bacba41e38 100644 --- a/instrumentation/cassandra/cassandra-4.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v4_0/CassandraDatabaseClientTracer.java +++ b/instrumentation/cassandra/cassandra-4.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v4_0/CassandraDatabaseClientTracer.java @@ -26,7 +26,6 @@ import io.opentelemetry.trace.Span; import java.net.InetSocketAddress; import java.util.Optional; -import org.checkerframework.checker.nullness.qual.NonNull; public class CassandraDatabaseClientTracer extends DatabaseClientTracer { public static final CassandraDatabaseClientTracer TRACER = new CassandraDatabaseClientTracer(); @@ -37,12 +36,12 @@ protected String getInstrumentationName() { } @Override - protected @NonNull String normalizeQuery(String query) { + protected String normalizeQuery(String query) { return query; } @Override - protected @NonNull String dbSystem(CqlSession session) { + protected String dbSystem(CqlSession session) { return DbSystem.CASSANDRA; } diff --git a/instrumentation/couchbase/couchbase-2.0/src/main/java/io/opentelemetry/instrumentation/auto/couchbase/v2_0/CouchbaseClientTracer.java b/instrumentation/couchbase/couchbase-2.0/src/main/java/io/opentelemetry/instrumentation/auto/couchbase/v2_0/CouchbaseClientTracer.java index f517e5d6ac92..ec98ff902c30 100644 --- a/instrumentation/couchbase/couchbase-2.0/src/main/java/io/opentelemetry/instrumentation/auto/couchbase/v2_0/CouchbaseClientTracer.java +++ b/instrumentation/couchbase/couchbase-2.0/src/main/java/io/opentelemetry/instrumentation/auto/couchbase/v2_0/CouchbaseClientTracer.java @@ -20,13 +20,12 @@ import io.opentelemetry.instrumentation.auto.api.jdbc.DbSystem; import java.lang.reflect.Method; import java.net.InetSocketAddress; -import org.checkerframework.checker.nullness.qual.NonNull; public class CouchbaseClientTracer extends DatabaseClientTracer { public static final CouchbaseClientTracer TRACER = new CouchbaseClientTracer(); @Override - protected @NonNull String normalizeQuery(Method method) { + protected String normalizeQuery(Method method) { Class declaringClass = method.getDeclaringClass(); String className = declaringClass.getSimpleName().replace("CouchbaseAsync", "").replace("DefaultAsync", ""); @@ -34,7 +33,7 @@ public class CouchbaseClientTracer extends DatabaseClientTracer { } @Override - protected @NonNull String dbSystem(Void connection) { + protected String dbSystem(Void connection) { return DbSystem.COUCHBASE; } diff --git a/instrumentation/elasticsearch/elasticsearch-rest-common/src/main/java/io/opentelemetry/instrumentation/auto/elasticsearch/rest/ElasticsearchRestClientTracer.java b/instrumentation/elasticsearch/elasticsearch-rest-common/src/main/java/io/opentelemetry/instrumentation/auto/elasticsearch/rest/ElasticsearchRestClientTracer.java index 4617dfd5b02b..3f8ab3b27daa 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-common/src/main/java/io/opentelemetry/instrumentation/auto/elasticsearch/rest/ElasticsearchRestClientTracer.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-common/src/main/java/io/opentelemetry/instrumentation/auto/elasticsearch/rest/ElasticsearchRestClientTracer.java @@ -21,7 +21,6 @@ import io.opentelemetry.trace.Span; import io.opentelemetry.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; -import org.checkerframework.checker.nullness.qual.NonNull; import org.elasticsearch.client.Response; public class ElasticsearchRestClientTracer extends DatabaseClientTracer { @@ -47,12 +46,12 @@ protected void onStatement(Span span, String statement) { } @Override - protected @NonNull String normalizeQuery(String query) { + protected String normalizeQuery(String query) { return query; } @Override - protected @NonNull String dbSystem(Void connection) { + protected String dbSystem(Void connection) { return "elasticsearch"; } diff --git a/instrumentation/elasticsearch/elasticsearch-transport-common/src/main/java/io/opentelemetry/instrumentation/auto/elasticsearch/transport/ElasticsearchTransportClientTracer.java b/instrumentation/elasticsearch/elasticsearch-transport-common/src/main/java/io/opentelemetry/instrumentation/auto/elasticsearch/transport/ElasticsearchTransportClientTracer.java index 4bd892bd15ff..a482f8eef12d 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-common/src/main/java/io/opentelemetry/instrumentation/auto/elasticsearch/transport/ElasticsearchTransportClientTracer.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-common/src/main/java/io/opentelemetry/instrumentation/auto/elasticsearch/transport/ElasticsearchTransportClientTracer.java @@ -20,7 +20,6 @@ import io.opentelemetry.trace.Span; import io.opentelemetry.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; -import org.checkerframework.checker.nullness.qual.NonNull; import org.elasticsearch.action.Action; public class ElasticsearchTransportClientTracer @@ -35,12 +34,12 @@ public Span onRequest(Span span, Class action, Class request) { } @Override - protected @NonNull String normalizeQuery(Action query) { + protected String normalizeQuery(Action query) { return query.getClass().getSimpleName(); } @Override - protected @NonNull String dbSystem(Void connection) { + protected String dbSystem(Void connection) { return "elasticsearch"; } diff --git a/instrumentation/geode-1.4/src/main/java/io/opentelemetry/instrumentation/auto/geode/GeodeTracer.java b/instrumentation/geode-1.4/src/main/java/io/opentelemetry/instrumentation/auto/geode/GeodeTracer.java index 57c143db0aec..c93d11271cb8 100644 --- a/instrumentation/geode-1.4/src/main/java/io/opentelemetry/instrumentation/auto/geode/GeodeTracer.java +++ b/instrumentation/geode-1.4/src/main/java/io/opentelemetry/instrumentation/auto/geode/GeodeTracer.java @@ -24,7 +24,6 @@ import io.opentelemetry.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; import org.apache.geode.cache.Region; -import org.checkerframework.checker.nullness.qual.NonNull; public class GeodeTracer extends DatabaseClientTracer, String> { public static GeodeTracer TRACER = new GeodeTracer(); @@ -48,12 +47,12 @@ public Span startSpan(String operation, Region connection, String query) { } @Override - protected @NonNull String normalizeQuery(String query) { + protected String normalizeQuery(String query) { return query; } @Override - protected @NonNull String dbSystem(Region region) { + protected String dbSystem(Region region) { return DbSystem.GEODE; } diff --git a/instrumentation/jdbc/src/main/java/io/opentelemetry/instrumentation/auto/jdbc/JdbcTracer.java b/instrumentation/jdbc/src/main/java/io/opentelemetry/instrumentation/auto/jdbc/JdbcTracer.java index 8ab957c79bd5..f335e43aaee0 100644 --- a/instrumentation/jdbc/src/main/java/io/opentelemetry/instrumentation/auto/jdbc/JdbcTracer.java +++ b/instrumentation/jdbc/src/main/java/io/opentelemetry/instrumentation/auto/jdbc/JdbcTracer.java @@ -30,7 +30,6 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; -import org.checkerframework.checker.nullness.qual.NonNull; public class JdbcTracer extends DatabaseClientTracer { public static final JdbcTracer TRACER = new JdbcTracer(); @@ -41,7 +40,7 @@ protected String getInstrumentationName() { } @Override - protected @NonNull String dbSystem(DBInfo info) { + protected String dbSystem(DBInfo info) { return info.getSystem(); } @@ -90,7 +89,7 @@ public Span startSpan(Statement statement, String query) { } @Override - protected @NonNull String normalizeQuery(String query) { + protected String normalizeQuery(String query) { return JDBCUtils.normalizeSql(query); } diff --git a/instrumentation/jedis/jedis-1.4/src/main/java/io/opentelemetry/instrumentation/auto/jedis/v1_4/JedisClientTracer.java b/instrumentation/jedis/jedis-1.4/src/main/java/io/opentelemetry/instrumentation/auto/jedis/v1_4/JedisClientTracer.java index 18edd6a16bd2..c67e518915cf 100644 --- a/instrumentation/jedis/jedis-1.4/src/main/java/io/opentelemetry/instrumentation/auto/jedis/v1_4/JedisClientTracer.java +++ b/instrumentation/jedis/jedis-1.4/src/main/java/io/opentelemetry/instrumentation/auto/jedis/v1_4/JedisClientTracer.java @@ -19,7 +19,6 @@ import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer; import io.opentelemetry.instrumentation.auto.api.jdbc.DbSystem; import java.net.InetSocketAddress; -import org.checkerframework.checker.nullness.qual.NonNull; import redis.clients.jedis.Connection; import redis.clients.jedis.Protocol.Command; @@ -27,12 +26,12 @@ public class JedisClientTracer extends DatabaseClientTracer public static final JedisClientTracer TRACER = new JedisClientTracer(); @Override - protected @NonNull String normalizeQuery(Command command) { + protected String normalizeQuery(Command command) { return command.name(); } @Override - protected @NonNull String dbSystem(Connection connection) { + protected String dbSystem(Connection connection) { return DbSystem.REDIS; } diff --git a/instrumentation/jedis/jedis-3.0/src/main/java/io/opentelemetry/instrumentation/auto/jedis/v3_0/JedisClientTracer.java b/instrumentation/jedis/jedis-3.0/src/main/java/io/opentelemetry/instrumentation/auto/jedis/v3_0/JedisClientTracer.java index 3559365b1cb4..376772fd0e6d 100644 --- a/instrumentation/jedis/jedis-3.0/src/main/java/io/opentelemetry/instrumentation/auto/jedis/v3_0/JedisClientTracer.java +++ b/instrumentation/jedis/jedis-3.0/src/main/java/io/opentelemetry/instrumentation/auto/jedis/v3_0/JedisClientTracer.java @@ -20,7 +20,6 @@ import io.opentelemetry.instrumentation.auto.api.jdbc.DbSystem; import java.net.InetSocketAddress; import java.nio.charset.StandardCharsets; -import org.checkerframework.checker.nullness.qual.NonNull; import redis.clients.jedis.Connection; import redis.clients.jedis.Protocol; import redis.clients.jedis.commands.ProtocolCommand; @@ -29,7 +28,7 @@ public class JedisClientTracer extends DatabaseClientTracer extends DatabaseClientTracer { @Override - protected @NonNull String dbSystem(RedisURI connection) { + protected String dbSystem(RedisURI connection) { return DbSystem.REDIS; } diff --git a/instrumentation/lettuce/lettuce-4.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v4_0/LettuceConnectionDatabaseClientTracer.java b/instrumentation/lettuce/lettuce-4.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v4_0/LettuceConnectionDatabaseClientTracer.java index 357ddff88074..f256349bdc0e 100644 --- a/instrumentation/lettuce/lettuce-4.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v4_0/LettuceConnectionDatabaseClientTracer.java +++ b/instrumentation/lettuce/lettuce-4.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v4_0/LettuceConnectionDatabaseClientTracer.java @@ -16,8 +16,6 @@ package io.opentelemetry.instrumentation.auto.lettuce.v4_0; -import org.checkerframework.checker.nullness.qual.NonNull; - public class LettuceConnectionDatabaseClientTracer extends LettuceAbstractDatabaseClientTracer { @@ -25,7 +23,7 @@ public class LettuceConnectionDatabaseClientTracer new LettuceConnectionDatabaseClientTracer(); @Override - protected @NonNull String normalizeQuery(String command) { + protected String normalizeQuery(String command) { return command; } } diff --git a/instrumentation/lettuce/lettuce-4.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v4_0/LettuceDatabaseClientTracer.java b/instrumentation/lettuce/lettuce-4.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v4_0/LettuceDatabaseClientTracer.java index b0cd5a64aba0..f1fb27e7af1e 100644 --- a/instrumentation/lettuce/lettuce-4.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v4_0/LettuceDatabaseClientTracer.java +++ b/instrumentation/lettuce/lettuce-4.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v4_0/LettuceDatabaseClientTracer.java @@ -17,7 +17,6 @@ package io.opentelemetry.instrumentation.auto.lettuce.v4_0; import com.lambdaworks.redis.protocol.RedisCommand; -import org.checkerframework.checker.nullness.qual.NonNull; public class LettuceDatabaseClientTracer extends LettuceAbstractDatabaseClientTracer> { @@ -25,7 +24,7 @@ public class LettuceDatabaseClientTracer public static final LettuceDatabaseClientTracer TRACER = new LettuceDatabaseClientTracer(); @Override - protected @NonNull String normalizeQuery(RedisCommand command) { + protected String normalizeQuery(RedisCommand command) { return command.getType().name(); } } diff --git a/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceAbstractDatabaseClientTracer.java b/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceAbstractDatabaseClientTracer.java index df5890bf047a..72be5c2e032b 100644 --- a/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceAbstractDatabaseClientTracer.java +++ b/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceAbstractDatabaseClientTracer.java @@ -22,7 +22,6 @@ import io.opentelemetry.trace.Span; import io.opentelemetry.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; -import org.checkerframework.checker.nullness.qual.NonNull; public abstract class LettuceAbstractDatabaseClientTracer extends DatabaseClientTracer { @@ -32,7 +31,7 @@ protected String getInstrumentationName() { } @Override - protected @NonNull String dbSystem(RedisURI connection) { + protected String dbSystem(RedisURI connection) { return DbSystem.REDIS; } diff --git a/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceConnectionDatabaseClientTracer.java b/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceConnectionDatabaseClientTracer.java index bffa744cb46a..c44e285ad4c7 100644 --- a/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceConnectionDatabaseClientTracer.java +++ b/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceConnectionDatabaseClientTracer.java @@ -16,15 +16,13 @@ package io.opentelemetry.instrumentation.auto.lettuce.v5_0; -import org.checkerframework.checker.nullness.qual.NonNull; - public class LettuceConnectionDatabaseClientTracer extends LettuceAbstractDatabaseClientTracer { public static final LettuceConnectionDatabaseClientTracer TRACER = new LettuceConnectionDatabaseClientTracer(); @Override - protected @NonNull String normalizeQuery(String query) { + protected String normalizeQuery(String query) { return query; } } diff --git a/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceDatabaseClientTracer.java b/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceDatabaseClientTracer.java index 3d8a883128f2..53b223971061 100644 --- a/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceDatabaseClientTracer.java +++ b/instrumentation/lettuce/lettuce-5.0/src/main/java/io/opentelemetry/instrumentation/auto/lettuce/v5_0/LettuceDatabaseClientTracer.java @@ -17,14 +17,13 @@ package io.opentelemetry.instrumentation.auto.lettuce.v5_0; import io.lettuce.core.protocol.RedisCommand; -import org.checkerframework.checker.nullness.qual.NonNull; public class LettuceDatabaseClientTracer extends LettuceAbstractDatabaseClientTracer> { public static final LettuceDatabaseClientTracer TRACER = new LettuceDatabaseClientTracer(); @Override - protected @NonNull String normalizeQuery(RedisCommand command) { + protected String normalizeQuery(RedisCommand command) { return LettuceInstrumentationUtil.getCommandName(command); } } diff --git a/instrumentation/mongo/mongo-common/src/main/java/io/opentelemetry/instrumentation/auto/mongo/MongoClientTracer.java b/instrumentation/mongo/mongo-common/src/main/java/io/opentelemetry/instrumentation/auto/mongo/MongoClientTracer.java index 24ee087beddd..f73ee4c74b7c 100644 --- a/instrumentation/mongo/mongo-common/src/main/java/io/opentelemetry/instrumentation/auto/mongo/MongoClientTracer.java +++ b/instrumentation/mongo/mongo-common/src/main/java/io/opentelemetry/instrumentation/auto/mongo/MongoClientTracer.java @@ -32,7 +32,6 @@ import org.bson.BsonDocument; import org.bson.BsonString; import org.bson.BsonValue; -import org.checkerframework.checker.nullness.qual.NonNull; public class MongoClientTracer extends DatabaseClientTracer { public static final MongoClientTracer TRACER = new MongoClientTracer(); @@ -44,7 +43,7 @@ protected String getInstrumentationName() { } @Override - protected @NonNull String dbSystem(CommandStartedEvent event) { + protected String dbSystem(CommandStartedEvent event) { return DbSystem.MONGODB; } @@ -99,7 +98,7 @@ protected String dbConnectionString(CommandStartedEvent event) { } @Override - public @NonNull String normalizeQuery(BsonDocument statement) { + public String normalizeQuery(BsonDocument statement) { // scrub the Mongo command so that parameters are removed from the string BsonDocument scrubbed = scrub(statement); return scrubbed.toString(); diff --git a/instrumentation/rediscala-1.8/src/main/java/io/opentelemetry/instrumentation/auto/rediscala/RediscalaClientTracer.java b/instrumentation/rediscala-1.8/src/main/java/io/opentelemetry/instrumentation/auto/rediscala/RediscalaClientTracer.java index a1dbcfdf9719..4ba1e1d2df54 100644 --- a/instrumentation/rediscala-1.8/src/main/java/io/opentelemetry/instrumentation/auto/rediscala/RediscalaClientTracer.java +++ b/instrumentation/rediscala-1.8/src/main/java/io/opentelemetry/instrumentation/auto/rediscala/RediscalaClientTracer.java @@ -19,7 +19,6 @@ import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer; import io.opentelemetry.instrumentation.auto.api.jdbc.DbSystem; import java.net.InetSocketAddress; -import org.checkerframework.checker.nullness.qual.NonNull; import redis.RedisCommand; public class RediscalaClientTracer @@ -28,12 +27,12 @@ public class RediscalaClientTracer public static final RediscalaClientTracer TRACER = new RediscalaClientTracer(); @Override - protected @NonNull String normalizeQuery(RedisCommand redisCommand) { + protected String normalizeQuery(RedisCommand redisCommand) { return spanNameForClass(redisCommand.getClass()); } @Override - protected @NonNull String dbSystem(RedisCommand redisCommand) { + protected String dbSystem(RedisCommand redisCommand) { return DbSystem.REDIS; } diff --git a/instrumentation/redisson-3.0/src/main/java/io/opentelemetry/instrumentation/auto/redisson/RedissonClientTracer.java b/instrumentation/redisson-3.0/src/main/java/io/opentelemetry/instrumentation/auto/redisson/RedissonClientTracer.java index c31d064bf12c..01591848d0f9 100644 --- a/instrumentation/redisson-3.0/src/main/java/io/opentelemetry/instrumentation/auto/redisson/RedissonClientTracer.java +++ b/instrumentation/redisson-3.0/src/main/java/io/opentelemetry/instrumentation/auto/redisson/RedissonClientTracer.java @@ -21,7 +21,6 @@ import io.opentelemetry.instrumentation.auto.api.jdbc.DbSystem; import java.net.InetSocketAddress; import java.util.List; -import org.checkerframework.checker.nullness.qual.NonNull; import org.redisson.client.RedisConnection; import org.redisson.client.protocol.CommandData; import org.redisson.client.protocol.CommandsData; @@ -36,7 +35,7 @@ protected String getInstrumentationName() { } @Override - protected @NonNull String normalizeQuery(Object args) { + protected String normalizeQuery(Object args) { // get command if (args instanceof CommandsData) { List> commands = ((CommandsData) args).getCommands(); @@ -55,7 +54,7 @@ protected String getInstrumentationName() { } @Override - protected @NonNull String dbSystem(RedisConnection connection) { + protected String dbSystem(RedisConnection connection) { return DbSystem.REDIS; } diff --git a/instrumentation/spymemcached-2.12/src/main/java/io/opentelemetry/instrumentation/auto/spymemcached/MemcacheClientTracer.java b/instrumentation/spymemcached-2.12/src/main/java/io/opentelemetry/instrumentation/auto/spymemcached/MemcacheClientTracer.java index 2a90cd601960..97b903f09898 100644 --- a/instrumentation/spymemcached-2.12/src/main/java/io/opentelemetry/instrumentation/auto/spymemcached/MemcacheClientTracer.java +++ b/instrumentation/spymemcached-2.12/src/main/java/io/opentelemetry/instrumentation/auto/spymemcached/MemcacheClientTracer.java @@ -21,13 +21,12 @@ import io.opentelemetry.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; import net.spy.memcached.MemcachedConnection; -import org.checkerframework.checker.nullness.qual.NonNull; public class MemcacheClientTracer extends DatabaseClientTracer { public static final MemcacheClientTracer TRACER = new MemcacheClientTracer(); @Override - protected @NonNull String dbSystem(MemcachedConnection memcachedConnection) { + protected String dbSystem(MemcachedConnection memcachedConnection) { return "memcached"; } @@ -42,7 +41,7 @@ protected void onStatement(Span span, String statement) { } @Override - protected @NonNull String normalizeQuery(String query) { + protected String normalizeQuery(String query) { char[] chars = query .replaceFirst("^async", "") From 3c76b46f477e41fdb39fa2322fe6547dba7f319e Mon Sep 17 00:00:00 2001 From: Nikita Salnikov-Tarnovski Date: Thu, 1 Oct 2020 15:31:30 +0300 Subject: [PATCH 3/3] Test fix --- .../auto/cassandra/v3_0/CassandraDatabaseClientTracer.java | 2 +- .../cassandra-3.0/src/test/groovy/CassandraClientTest.groovy | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/instrumentation/cassandra/cassandra-3.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v3_0/CassandraDatabaseClientTracer.java b/instrumentation/cassandra/cassandra-3.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v3_0/CassandraDatabaseClientTracer.java index 22cffedb2a0e..c0627b21f6c9 100644 --- a/instrumentation/cassandra/cassandra-3.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v3_0/CassandraDatabaseClientTracer.java +++ b/instrumentation/cassandra/cassandra-3.0/src/main/java/io/opentelemetry/instrumentation/auto/cassandra/v3_0/CassandraDatabaseClientTracer.java @@ -46,7 +46,7 @@ protected String dbSystem(Session session) { @Override protected String dbName(Session session) { - return null; + return session.getLoggedKeyspace(); } @Override diff --git a/instrumentation/cassandra/cassandra-3.0/src/test/groovy/CassandraClientTest.groovy b/instrumentation/cassandra/cassandra-3.0/src/test/groovy/CassandraClientTest.groovy index f1863359601e..43657fa5f661 100644 --- a/instrumentation/cassandra/cassandra-3.0/src/test/groovy/CassandraClientTest.groovy +++ b/instrumentation/cassandra/cassandra-3.0/src/test/groovy/CassandraClientTest.groovy @@ -144,6 +144,7 @@ class CassandraClientTest extends AgentTestRunner { "${SemanticAttributes.DB_SYSTEM.key()}" "cassandra" "${SemanticAttributes.DB_NAME.key()}" keyspace "${SemanticAttributes.DB_STATEMENT.key()}" statement + "${SemanticAttributes.CASSANDRA_KEYSPACE.key()}" keyspace } } }