Use SemanticAttributes for DbSystem (#1991)

This commit is contained in:
Anuraag Agrawal 2021-01-08 11:59:56 +09:00 committed by GitHub
parent f14c9b7723
commit 3b88bb75ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 51 additions and 76 deletions

View File

@ -5,8 +5,8 @@
package io.opentelemetry.javaagent.instrumentation.apachecamel.decorators;
import io.opentelemetry.api.trace.attributes.SemanticAttributes.DbSystemValues;
import io.opentelemetry.javaagent.instrumentation.apachecamel.SpanDecorator;
import io.opentelemetry.javaagent.instrumentation.api.db.DbSystem;
import java.util.HashMap;
import java.util.Map;
@ -24,7 +24,7 @@ public class DecoratorRegistry {
result.put("aws-sqs", new MessagingSpanDecorator("aws-sqs"));
result.put("cometd", new MessagingSpanDecorator("cometd"));
result.put("cometds", new MessagingSpanDecorator("cometds"));
result.put("cql", new DbSpanDecorator("cql", DbSystem.CASSANDRA));
result.put("cql", new DbSpanDecorator("cql", DbSystemValues.CASSANDRA));
result.put("direct", new InternalSpanDecorator());
result.put("direct-vm", new InternalSpanDecorator());
result.put("disruptor", new InternalSpanDecorator());
@ -33,12 +33,12 @@ public class DecoratorRegistry {
result.put("http4", new HttpSpanDecorator());
result.put("http", new HttpSpanDecorator());
result.put("ironmq", new MessagingSpanDecorator("ironmq"));
result.put("jdbc", new DbSpanDecorator("jdbc", DbSystem.OTHER_SQL));
result.put("jdbc", new DbSpanDecorator("jdbc", DbSystemValues.OTHER_SQL));
result.put("jetty", new HttpSpanDecorator());
result.put("jms", new MessagingSpanDecorator("jms"));
result.put("kafka", new KafkaSpanDecorator());
result.put("log", new LogSpanDecorator());
result.put("mongodb", new DbSpanDecorator("mongodb", DbSystem.MONGODB));
result.put("mongodb", new DbSpanDecorator("mongodb", DbSystemValues.MONGODB));
result.put("mqtt", new MessagingSpanDecorator("mqtt"));
result.put("netty-http4", new HttpSpanDecorator());
result.put("netty-http", new HttpSpanDecorator());
@ -49,7 +49,7 @@ public class DecoratorRegistry {
result.put("seda", new InternalSpanDecorator());
result.put("servlet", new HttpSpanDecorator());
result.put("sjms", new MessagingSpanDecorator("sjms"));
result.put("sql", new DbSpanDecorator("sql", DbSystem.OTHER_SQL));
result.put("sql", new DbSpanDecorator("sql", DbSystemValues.OTHER_SQL));
result.put("stomp", new MessagingSpanDecorator("stomp"));
result.put("timer", new TimerSpanDecorator());
result.put("undertow", new HttpSpanDecorator());

View File

@ -10,10 +10,10 @@ import com.datastax.driver.core.Host;
import com.datastax.driver.core.Session;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.attributes.SemanticAttributes;
import io.opentelemetry.api.trace.attributes.SemanticAttributes.DbSystemValues;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer;
import io.opentelemetry.instrumentation.api.tracer.utils.NetPeerUtils;
import io.opentelemetry.javaagent.instrumentation.api.db.DbSystem;
import java.net.InetSocketAddress;
public class CassandraDatabaseClientTracer extends DatabaseClientTracer<Session, String> {
@ -35,7 +35,7 @@ public class CassandraDatabaseClientTracer extends DatabaseClientTracer<Session,
@Override
protected String dbSystem(Session session) {
return DbSystem.CASSANDRA;
return DbSystemValues.CASSANDRA;
}
@Override

View File

@ -10,10 +10,10 @@ import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.cql.ExecutionInfo;
import com.datastax.oss.driver.api.core.metadata.Node;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.attributes.SemanticAttributes.DbSystemValues;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer;
import io.opentelemetry.instrumentation.api.tracer.utils.NetPeerUtils;
import io.opentelemetry.javaagent.instrumentation.api.db.DbSystem;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
@ -36,7 +36,7 @@ public class CassandraDatabaseClientTracer extends DatabaseClientTracer<CqlSessi
@Override
protected String dbSystem(CqlSession session) {
return DbSystem.CASSANDRA;
return DbSystemValues.CASSANDRA;
}
@Override

View File

@ -5,8 +5,8 @@
package io.opentelemetry.javaagent.instrumentation.couchbase.v2_0;
import io.opentelemetry.api.trace.attributes.SemanticAttributes.DbSystemValues;
import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer;
import io.opentelemetry.javaagent.instrumentation.api.db.DbSystem;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
@ -27,7 +27,7 @@ public class CouchbaseClientTracer extends DatabaseClientTracer<Void, Method> {
@Override
protected String dbSystem(Void connection) {
return DbSystem.COUCHBASE;
return DbSystemValues.COUCHBASE;
}
@Override

View File

@ -10,8 +10,8 @@ import static io.opentelemetry.javaagent.instrumentation.couchbase.v2_0.Couchbas
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.attributes.SemanticAttributes;
import io.opentelemetry.api.trace.attributes.SemanticAttributes.DbSystemValues;
import io.opentelemetry.instrumentation.rxjava.TracedOnSubscribe;
import io.opentelemetry.javaagent.instrumentation.api.db.DbSystem;
import java.lang.reflect.Method;
import rx.Observable;
@ -43,7 +43,7 @@ public class CouchbaseOnSubscribe<T> extends TracedOnSubscribe<T> {
@Override
protected void decorateSpan(Span span) {
span.setAttribute(SemanticAttributes.DB_SYSTEM, DbSystem.COUCHBASE);
span.setAttribute(SemanticAttributes.DB_SYSTEM, DbSystemValues.COUCHBASE);
span.setAttribute(SemanticAttributes.DB_NAME, bucket);
span.setAttribute(SemanticAttributes.DB_STATEMENT, query);
}

View File

@ -10,7 +10,6 @@ import static io.opentelemetry.api.trace.Span.Kind.CLIENT;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.attributes.SemanticAttributes;
import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer;
import io.opentelemetry.javaagent.instrumentation.api.db.DbSystem;
import java.net.InetSocketAddress;
import org.apache.geode.cache.Region;
@ -46,7 +45,9 @@ public class GeodeTracer extends DatabaseClientTracer<Region<?, ?>, String> {
@Override
protected String dbSystem(Region<?, ?> region) {
return DbSystem.GEODE;
// TODO(anuraaga): Replace with semantic attribute
// https://github.com/open-telemetry/opentelemetry-specification/pull/1321
return "geode";
}
@Override

View File

@ -8,7 +8,7 @@ package io.opentelemetry.javaagent.instrumentation.jdbc;
import static io.opentelemetry.javaagent.instrumentation.jdbc.DbInfo.DEFAULT;
import static java.util.regex.Pattern.CASE_INSENSITIVE;
import io.opentelemetry.javaagent.instrumentation.api.db.DbSystem;
import io.opentelemetry.api.trace.attributes.SemanticAttributes.DbSystemValues;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLDecoder;
@ -624,13 +624,13 @@ public enum JdbcConnectionUrlParser {
if (dbInfo.getPort() == null) {
builder.port(DEFAULT_PORT);
}
return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).system(DbSystem.H2).subtype("tcp");
return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).system(DbSystemValues.H2).subtype("tcp");
} else if (h2Url.startsWith("ssl:")) {
DbInfo dbInfo = builder.build();
if (dbInfo.getPort() == null) {
builder.port(DEFAULT_PORT);
}
return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).system(DbSystem.H2).subtype("ssl");
return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).system(DbSystemValues.H2).subtype("ssl");
} else {
builder.subtype("file").host(null).port(null);
int propLoc = h2Url.indexOf(";");
@ -651,6 +651,8 @@ public enum JdbcConnectionUrlParser {
private static final String DEFAULT_USER = "SA";
private static final int DEFAULT_PORT = 9001;
// TODO(anuraaga): Replace dbsystem with semantic convention
// https://github.com/open-telemetry/opentelemetry-specification/pull/1321
@Override
DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) {
String instance = null;
@ -681,22 +683,22 @@ public enum JdbcConnectionUrlParser {
if (dbInfo.getPort() == null) {
builder.port(DEFAULT_PORT);
}
return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).system(DbSystem.HSQLDB).subtype("hsql");
return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).system("hsqldb").subtype("hsql");
} else if (hsqlUrl.startsWith("hsqls:")) {
if (dbInfo.getPort() == null) {
builder.port(DEFAULT_PORT);
}
return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).system(DbSystem.HSQLDB).subtype("hsqls");
return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).system("hsqldb").subtype("hsqls");
} else if (hsqlUrl.startsWith("http:")) {
if (dbInfo.getPort() == null) {
builder.port(80);
}
return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).system(DbSystem.HSQLDB).subtype("http");
return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).system("hsqldb").subtype("http");
} else if (hsqlUrl.startsWith("https:")) {
if (dbInfo.getPort() == null) {
builder.port(443);
}
return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).system(DbSystem.HSQLDB).subtype("https");
return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).system("hsqldb").subtype("https");
} else {
builder.subtype("mem").host(null).port(null);
instance = hsqlUrl;
@ -939,27 +941,27 @@ public enum JdbcConnectionUrlParser {
switch (type) {
case "as400": // IBM AS400 Database
case "db2": // IBM Db2
return DbSystem.DB2;
return DbSystemValues.DB2;
case "derby": // Apache Derby
return DbSystem.DERBY;
return DbSystemValues.DERBY;
case "h2": // H2 Database
return DbSystem.H2;
return DbSystemValues.H2;
case "hsqldb": // Hyper SQL Database
return DbSystem.HSQLDB;
return "hsqldb";
case "mariadb": // MariaDB
return DbSystem.MARIADB;
return DbSystemValues.MARIADB;
case "mysql": // MySQL
return DbSystem.MYSQL;
return DbSystemValues.MYSQL;
case "oracle": // Oracle Database
return DbSystem.ORACLE;
return DbSystemValues.ORACLE;
case "postgresql": // PostgreSQL
return DbSystem.POSTGRESQL;
return DbSystemValues.POSTGRESQL;
case "jtds": // jTDS - the pure Java JDBC 3.0 driver for Microsoft SQL Server
case "microsoft":
case "sqlserver": // Microsoft SQL Server
return DbSystem.MSSQL;
return DbSystemValues.MSSQL;
default:
return DbSystem.OTHER_SQL; // Unknown DBMS
return DbSystemValues.OTHER_SQL; // Unknown DBMS
}
}
}

View File

@ -5,8 +5,8 @@
package io.opentelemetry.javaagent.instrumentation.jedis.v1_4;
import io.opentelemetry.api.trace.attributes.SemanticAttributes.DbSystemValues;
import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer;
import io.opentelemetry.javaagent.instrumentation.api.db.DbSystem;
import io.opentelemetry.javaagent.instrumentation.api.db.RedisCommandNormalizer;
import io.opentelemetry.javaagent.instrumentation.jedis.v1_4.JedisClientTracer.CommandWithArgs;
import java.net.InetSocketAddress;
@ -37,7 +37,7 @@ public class JedisClientTracer extends DatabaseClientTracer<Connection, CommandW
@Override
protected String dbSystem(Connection connection) {
return DbSystem.REDIS;
return DbSystemValues.REDIS;
}
@Override

View File

@ -5,8 +5,8 @@
package io.opentelemetry.javaagent.instrumentation.jedis.v3_0;
import io.opentelemetry.api.trace.attributes.SemanticAttributes.DbSystemValues;
import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer;
import io.opentelemetry.javaagent.instrumentation.api.db.DbSystem;
import io.opentelemetry.javaagent.instrumentation.api.db.RedisCommandNormalizer;
import io.opentelemetry.javaagent.instrumentation.jedis.v3_0.JedisClientTracer.CommandWithArgs;
import java.net.InetSocketAddress;
@ -39,7 +39,7 @@ public class JedisClientTracer extends DatabaseClientTracer<Connection, CommandW
@Override
protected String dbSystem(Connection connection) {
return DbSystem.REDIS;
return DbSystemValues.REDIS;
}
@Override

View File

@ -8,8 +8,8 @@ package io.opentelemetry.javaagent.instrumentation.lettuce.v4_0;
import com.lambdaworks.redis.RedisURI;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.attributes.SemanticAttributes;
import io.opentelemetry.api.trace.attributes.SemanticAttributes.DbSystemValues;
import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer;
import io.opentelemetry.javaagent.instrumentation.api.db.DbSystem;
import java.net.InetSocketAddress;
public abstract class LettuceAbstractDatabaseClientTracer<QUERY>
@ -17,7 +17,7 @@ public abstract class LettuceAbstractDatabaseClientTracer<QUERY>
@Override
protected String dbSystem(RedisURI connection) {
return DbSystem.REDIS;
return DbSystemValues.REDIS;
}
@Override

View File

@ -8,8 +8,8 @@ package io.opentelemetry.javaagent.instrumentation.lettuce.v5_0;
import io.lettuce.core.RedisURI;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.attributes.SemanticAttributes;
import io.opentelemetry.api.trace.attributes.SemanticAttributes.DbSystemValues;
import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer;
import io.opentelemetry.javaagent.instrumentation.api.db.DbSystem;
import java.net.InetSocketAddress;
public abstract class LettuceAbstractDatabaseClientTracer<QUERY>
@ -21,7 +21,7 @@ public abstract class LettuceAbstractDatabaseClientTracer<QUERY>
@Override
protected String dbSystem(RedisURI connection) {
return DbSystem.REDIS;
return DbSystemValues.REDIS;
}
@Override

View File

@ -18,10 +18,10 @@ import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.api.trace.attributes.SemanticAttributes;
import io.opentelemetry.api.trace.attributes.SemanticAttributes.DbSystemValues;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.tracer.utils.NetPeerUtils;
import io.opentelemetry.instrumentation.api.tracer.utils.NetPeerUtils.SpanAttributeSetter;
import io.opentelemetry.javaagent.instrumentation.api.db.DbSystem;
import io.opentelemetry.javaagent.instrumentation.api.db.RedisCommandNormalizer;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
@ -165,7 +165,7 @@ public enum OpenTelemetryTracing implements Tracing {
.spanBuilder("redis")
.setSpanKind(Kind.CLIENT)
.setParent(parent)
.setAttribute(SemanticAttributes.DB_SYSTEM, DbSystem.REDIS);
.setAttribute(SemanticAttributes.DB_SYSTEM, DbSystemValues.REDIS);
}
@Override

View File

@ -12,8 +12,8 @@ import com.mongodb.connection.ConnectionDescription;
import com.mongodb.event.CommandStartedEvent;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.attributes.SemanticAttributes;
import io.opentelemetry.api.trace.attributes.SemanticAttributes.DbSystemValues;
import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer;
import io.opentelemetry.javaagent.instrumentation.api.db.DbSystem;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@ -56,7 +56,7 @@ public class MongoClientTracer extends DatabaseClientTracer<CommandStartedEvent,
@Override
protected String dbSystem(CommandStartedEvent event) {
return DbSystem.MONGODB;
return DbSystemValues.MONGODB;
}
@Override

View File

@ -5,8 +5,8 @@
package io.opentelemetry.javaagent.instrumentation.rediscala;
import io.opentelemetry.api.trace.attributes.SemanticAttributes.DbSystemValues;
import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer;
import io.opentelemetry.javaagent.instrumentation.api.db.DbSystem;
import java.net.InetSocketAddress;
import redis.RedisCommand;
@ -26,7 +26,7 @@ public class RediscalaClientTracer
@Override
protected String dbSystem(RedisCommand redisCommand) {
return DbSystem.REDIS;
return DbSystemValues.REDIS;
}
@Override

View File

@ -7,8 +7,8 @@ package io.opentelemetry.javaagent.instrumentation.redisson;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.opentelemetry.api.trace.attributes.SemanticAttributes.DbSystemValues;
import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer;
import io.opentelemetry.javaagent.instrumentation.api.db.DbSystem;
import io.opentelemetry.javaagent.instrumentation.api.db.RedisCommandNormalizer;
import java.net.InetSocketAddress;
import java.util.ArrayList;
@ -98,7 +98,7 @@ public class RedissonClientTracer extends DatabaseClientTracer<RedisConnection,
@Override
protected String dbSystem(RedisConnection connection) {
return DbSystem.REDIS;
return DbSystemValues.REDIS;
}
@Override

View File

@ -1,28 +0,0 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.instrumentation.api.db;
public final class DbSystem {
public static final String CASSANDRA = "cassandra";
public static final String COUCHBASE = "couchbase";
public static final String DB2 = "db2";
public static final String DERBY = "derby";
public static final String DYNAMODB = "dynamodb";
public static final String GEODE = "geode";
public static final String H2 = "h2";
public static final String HSQLDB = "hsqldb";
public static final String MARIADB = "mariadb";
public static final String MONGODB = "mongodb";
public static final String MSSQL = "mssql";
public static final String MYSQL = "mysql";
public static final String ORACLE = "oracle";
public static final String OTHER_SQL = "other_sql";
public static final String POSTGRESQL = "postgresql";
public static final String REDIS = "redis";
private DbSystem() {}
}