Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review DB semantic conventions #1284

Merged
merged 3 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/semantic-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | - |
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,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);

Expand Down Expand Up @@ -111,32 +111,41 @@ 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));
}

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 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);

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;

public class CassandraDatabaseClientTracer extends DatabaseClientTracer<Session, String> {
Expand All @@ -44,13 +45,14 @@ protected String dbSystem(Session session) {
}

@Override
protected String dbUser(Session session) {
return null;
protected String dbName(Session session) {
return session.getLoggedKeyspace();
}

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ protected 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@ protected 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@ protected 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@ protected 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Span startSpan(String operation, Region<?, ?> connection, String query) {
.startSpan();

onConnection(span, connection);
onPeerConnection(span, connection);
setNetSemanticConvention(span, connection);
onStatement(span, normalizedQuery);

return span;
Expand All @@ -56,11 +56,6 @@ protected String dbSystem(Region<?, ?> region) {
return DbSystem.GEODE;
}

@Override
protected String dbUser(Region<?, ?> region) {
return null;
}

@Override
protected String dbName(Region<?, ?> region) {
return region.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ protected 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@ protected 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import com.lambdaworks.redis.RedisURI;
import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer;
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;

public abstract class LettuceAbstractDatabaseClientTracer<QUERY>
Expand All @@ -31,26 +31,16 @@ protected 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;

public abstract class LettuceAbstractDatabaseClientTracer<QUERY>
Expand All @@ -34,25 +35,16 @@ protected 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());
}

@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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ protected 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.
Expand Down
Loading