Enrich JDBC spans with db.operation and db.sql.table
MODIFY
instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/JdbcTracer.java
instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/JdbcTracer.java
@@ -7,10 +7,12 @@ package io.opentelemetry.javaagent.instrumentation.jdbc;
import static io.opentelemetry.javaagent.instrumentation.jdbc.JdbcUtils.connectionFromStatement;
+import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer;
import io.opentelemetry.javaagent.instrumentation.api.db.SqlStatementInfo;
import io.opentelemetry.javaagent.instrumentation.api.db.SqlStatementSanitizer;
+import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.InetSocketAddress;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
@@ -87,12 +89,28 @@ public class JdbcTracer extends DatabaseClientTracer<DbInfo, String, SqlStatemen
return null;
}
+ @Override
+ protected void onStatement(
+ SpanBuilder span, DbInfo connection, String statement, SqlStatementInfo sanitizedStatement) {
+ super.onStatement(span, connection, statement, sanitizedStatement);
+ String table = sanitizedStatement.getTable();
+ if (table != null) {
+ span.setAttribute(SemanticAttributes.DB_SQL_TABLE, table);
+ }
+ }
+
@Override
protected String dbStatement(
DbInfo connection, String statement, SqlStatementInfo sanitizedStatement) {
return sanitizedStatement.getFullStatement();
}
+ @Override
+ protected String dbOperation(
+ DbInfo connection, String statement, SqlStatementInfo sanitizedStatement) {
+ return sanitizedStatement.getOperation();
+ }
+
private DbInfo extractDbInfo(Connection connection) {
DbInfo dbInfo = JdbcMaps.connectionInfo.get(connection);
/*

MODIFY
instrumentation/jdbc/javaagent/src/test/groovy/JdbcInstrumentationTest.groovy
instrumentation/jdbc/javaagent/src/test/groovy/JdbcInstrumentationTest.groovy
@@ -185,8 +185,10 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification {
if (username != null) {
"$SemanticAttributes.DB_USER.key" username
}
- "$SemanticAttributes.DB_STATEMENT.key" sanitizedQuery
"$SemanticAttributes.DB_CONNECTION_STRING.key" url
+ "$SemanticAttributes.DB_STATEMENT.key" sanitizedQuery
+ "$SemanticAttributes.DB_OPERATION.key" "SELECT"
+ "$SemanticAttributes.DB_SQL_TABLE.key" table
}
}
}
@@ -197,22 +199,22 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification {
connection.close()
where:
- system | connection | username | query | sanitizedQuery | spanName | url
- "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:"
- "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
- "hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), null) | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ${dbNameLower}.INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:"
- "h2" | new Driver().connect(jdbcUrls.get("h2"), connectionProps) | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:"
- "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), connectionProps) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
- "hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), connectionProps) | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ${dbNameLower}.INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:"
- "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:"
- "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
- "hsqldb" | cpDatasources.get("tomcat").get("hsqldb").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ${dbNameLower}.INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:"
- "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:"
- "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
- "hsqldb" | cpDatasources.get("hikari").get("hsqldb").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ${dbNameLower}.INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:"
- "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:"
- "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
- "hsqldb" | cpDatasources.get("c3p0").get("hsqldb").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ${dbNameLower}.INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:"
+ system | connection | username | query | sanitizedQuery | spanName | url | table
+ "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null
+ "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
+ "hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), null) | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ${dbNameLower}.INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:" | "INFORMATION_SCHEMA.SYSTEM_USERS"
+ "h2" | new Driver().connect(jdbcUrls.get("h2"), connectionProps) | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null
+ "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), connectionProps) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
+ "hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), connectionProps) | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ${dbNameLower}.INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:" | "INFORMATION_SCHEMA.SYSTEM_USERS"
+ "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null
+ "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
+ "hsqldb" | cpDatasources.get("tomcat").get("hsqldb").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ${dbNameLower}.INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:" | "INFORMATION_SCHEMA.SYSTEM_USERS"
+ "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null
+ "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
+ "hsqldb" | cpDatasources.get("hikari").get("hsqldb").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ${dbNameLower}.INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:" | "INFORMATION_SCHEMA.SYSTEM_USERS"
+ "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null
+ "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
+ "hsqldb" | cpDatasources.get("c3p0").get("hsqldb").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ${dbNameLower}.INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:" | "INFORMATION_SCHEMA.SYSTEM_USERS"
}
@Unroll
@@ -241,8 +243,10 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification {
if (username != null) {
"$SemanticAttributes.DB_USER.key" username
}
- "$SemanticAttributes.DB_STATEMENT.key" sanitizedQuery
"$SemanticAttributes.DB_CONNECTION_STRING.key" url
+ "$SemanticAttributes.DB_STATEMENT.key" sanitizedQuery
+ "$SemanticAttributes.DB_OPERATION.key" "SELECT"
+ "$SemanticAttributes.DB_SQL_TABLE.key" table
}
}
}
@@ -253,15 +257,15 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification {
connection.close()
where:
- system | connection | username | query | sanitizedQuery | spanName | url
- "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:"
- "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
- "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:"
- "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
- "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:"
- "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
- "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:"
- "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
+ system | connection | username | query | sanitizedQuery | spanName | url | table
+ "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null
+ "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
+ "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null
+ "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
+ "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null
+ "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
+ "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null
+ "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
}
@Unroll
@@ -289,8 +293,10 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification {
if (username != null) {
"$SemanticAttributes.DB_USER.key" username
}
- "$SemanticAttributes.DB_STATEMENT.key" sanitizedQuery
"$SemanticAttributes.DB_CONNECTION_STRING.key" url
+ "$SemanticAttributes.DB_STATEMENT.key" sanitizedQuery
+ "$SemanticAttributes.DB_OPERATION.key" "SELECT"
+ "$SemanticAttributes.DB_SQL_TABLE.key" table
}
}
}
@@ -301,15 +307,15 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification {
connection.close()
where:
- system | connection | username | query | sanitizedQuery | spanName | url
- "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:"
- "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
- "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:"
- "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
- "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:"
- "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
- "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:"
- "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
+ system | connection | username | query | sanitizedQuery | spanName | url | table
+ "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null
+ "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
+ "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null
+ "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
+ "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null
+ "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
+ "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null
+ "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
}
@Unroll
@@ -337,8 +343,10 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification {
if (username != null) {
"$SemanticAttributes.DB_USER.key" username
}
- "$SemanticAttributes.DB_STATEMENT.key" sanitizedQuery
"$SemanticAttributes.DB_CONNECTION_STRING.key" url
+ "$SemanticAttributes.DB_STATEMENT.key" sanitizedQuery
+ "$SemanticAttributes.DB_OPERATION.key" "SELECT"
+ "$SemanticAttributes.DB_SQL_TABLE.key" table
}
}
}
@@ -349,15 +357,15 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification {
connection.close()
where:
- system | connection | username | query | sanitizedQuery | spanName | url
- "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:"
- "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
- "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:"
- "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
- "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:"
- "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
- "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:"
- "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
+ system | connection | username | query | sanitizedQuery | spanName | url | table
+ "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null
+ "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
+ "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null
+ "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
+ "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null
+ "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
+ "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null
+ "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
}
@Unroll
@@ -498,8 +506,10 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification {
if (username != null) {
"$SemanticAttributes.DB_USER.key" username
}
- "$SemanticAttributes.DB_STATEMENT.key" sanitizedQuery
"$SemanticAttributes.DB_CONNECTION_STRING.key" url
+ "$SemanticAttributes.DB_STATEMENT.key" sanitizedQuery
+ "$SemanticAttributes.DB_OPERATION.key" "SELECT"
+ "$SemanticAttributes.DB_SQL_TABLE.key" table
}
}
}
@@ -510,11 +520,11 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification {
connection?.close()
where:
- prepareStatement | system | driver | jdbcUrl | username | query | sanitizedQuery | spanName | url
- true | "h2" | new Driver() | "jdbc:h2:mem:" + dbName | null | "SELECT 3;" | "SELECT ?;" | "SELECT $dbNameLower" | "h2:mem:"
- true | "derby" | new EmbeddedDriver() | "jdbc:derby:memory:" + dbName + ";create=true" | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
- false | "h2" | new Driver() | "jdbc:h2:mem:" + dbName | null | "SELECT 3;" | "SELECT ?;" | "SELECT $dbNameLower" | "h2:mem:"
- false | "derby" | new EmbeddedDriver() | "jdbc:derby:memory:" + dbName + ";create=true" | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:"
+ prepareStatement | system | driver | jdbcUrl | username | query | sanitizedQuery | spanName | url | table
+ true | "h2" | new Driver() | "jdbc:h2:mem:" + dbName | null | "SELECT 3;" | "SELECT ?;" | "SELECT $dbNameLower" | "h2:mem:" | null
+ true | "derby" | new EmbeddedDriver() | "jdbc:derby:memory:" + dbName + ";create=true" | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
+ false | "h2" | new Driver() | "jdbc:h2:mem:" + dbName | null | "SELECT 3;" | "SELECT ?;" | "SELECT $dbNameLower" | "h2:mem:" | null
+ false | "derby" | new EmbeddedDriver() | "jdbc:derby:memory:" + dbName + ";create=true" | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT ${dbNameLower}.SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1"
}
def "calling #datasource.class.simpleName getConnection generates a span when under existing trace"() {
@@ -632,20 +642,22 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification {
attributes {
"$SemanticAttributes.DB_SYSTEM.key" "testdb"
"$SemanticAttributes.DB_NAME.key" databaseName
- "$SemanticAttributes.DB_STATEMENT.key" sanitizedQuery
"$SemanticAttributes.DB_CONNECTION_STRING.key" "testdb://localhost"
+ "$SemanticAttributes.DB_STATEMENT.key" sanitizedQuery
+ "$SemanticAttributes.DB_OPERATION.key" operation
+ "$SemanticAttributes.DB_SQL_TABLE.key" table
}
}
}
}
where:
- url | query | sanitizedQuery | spanName | databaseName
- "jdbc:testdb://localhost?databaseName=test" | "SELECT * FROM table" | "SELECT * FROM table" | "SELECT test.table" | "test"
- "jdbc:testdb://localhost?databaseName=test" | "SELECT 42" | "SELECT ?" | "SELECT test" | "test"
- "jdbc:testdb://localhost" | "SELECT * FROM table" | "SELECT * FROM table" | "SELECT table" | null
- "jdbc:testdb://localhost?databaseName=test" | "CREATE TABLE table" | "CREATE TABLE table" | "test" | "test"
- "jdbc:testdb://localhost" | "CREATE TABLE table" | "CREATE TABLE table" | "DB Query" | null
+ url | query | sanitizedQuery | spanName | databaseName | operation | table
+ "jdbc:testdb://localhost?databaseName=test" | "SELECT * FROM table" | "SELECT * FROM table" | "SELECT test.table" | "test" | "SELECT" | "table"
+ "jdbc:testdb://localhost?databaseName=test" | "SELECT 42" | "SELECT ?" | "SELECT test" | "test" | "SELECT" | null
+ "jdbc:testdb://localhost" | "SELECT * FROM table" | "SELECT * FROM table" | "SELECT table" | null | "SELECT" | "table"
+ "jdbc:testdb://localhost?databaseName=test" | "CREATE TABLE table" | "CREATE TABLE table" | "test" | "test" | null | null
+ "jdbc:testdb://localhost" | "CREATE TABLE table" | "CREATE TABLE table" | "DB Query" | null | null | null
}
@Unroll
@@ -689,8 +701,10 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.DB_SYSTEM.key" "hsqldb"
"$SemanticAttributes.DB_NAME.key" dbNameLower
"$SemanticAttributes.DB_USER.key" "SA"
- "$SemanticAttributes.DB_STATEMENT.key" "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS"
"$SemanticAttributes.DB_CONNECTION_STRING.key" "hsqldb:mem:"
+ "$SemanticAttributes.DB_STATEMENT.key" "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS"
+ "$SemanticAttributes.DB_OPERATION.key" "SELECT"
+ "$SemanticAttributes.DB_SQL_TABLE.key" "INFORMATION_SCHEMA.SYSTEM_USERS"
}
}
}

Enrich JDBC spans with db.operation and db.sql.table (#2425)