diff --git a/instrumentation-api-incubator/src/main/jflex/SqlSanitizer.jflex b/instrumentation-api-incubator/src/main/jflex/SqlSanitizer.jflex index 71ba5d0c18ec..af03f1e4598c 100644 --- a/instrumentation-api-incubator/src/main/jflex/SqlSanitizer.jflex +++ b/instrumentation-api-incubator/src/main/jflex/SqlSanitizer.jflex @@ -122,13 +122,56 @@ WHITESPACE = [ \t\r\n]+ /** @return true if all statement info is gathered */ boolean handleNext() { return false; - } + } + + /** @return true if all statement info is gathered */ + boolean handleOperationTarget(String target) { + return false; + } + + boolean expectingOperationTarget() { + return false; + } SqlStatementInfo getResult(String fullStatement) { return SqlStatementInfo.create(fullStatement, getClass().getSimpleName().toUpperCase(java.util.Locale.ROOT), mainIdentifier); } } + private abstract class DdlOperation extends Operation { + private String operationTarget = ""; + private boolean expectingOperationTarget = true; + + boolean expectingOperationTarget() { + return expectingOperationTarget; + } + + boolean handleOperationTarget(String target) { + operationTarget = target; + expectingOperationTarget = false; + return false; + } + + boolean shouldHandleIdentifier() { + // Return true only if the provided value corresponds to a table, as it will be used to set the attribute `db.sql.table`. + return "TABLE".equals(operationTarget); + } + + boolean handleIdentifier() { + if (shouldHandleIdentifier()) { + mainIdentifier = readIdentifierName(); + } + return true; + } + + SqlStatementInfo getResult(String fullStatement) { + if (!"".equals(operationTarget)) { + return SqlStatementInfo.create(fullStatement, getClass().getSimpleName().toUpperCase(java.util.Locale.ROOT) + " " + operationTarget, mainIdentifier); + } + return super.getResult(fullStatement); + } + } + private static class NoOp extends Operation { static final Operation INSTANCE = new NoOp(); @@ -273,6 +316,15 @@ WHITESPACE = [ \t\r\n]+ } } + private class Create extends DdlOperation { + } + + private class Drop extends DdlOperation { + } + + private class Alter extends DdlOperation { + } + private SqlStatementInfo getResult() { if (builder.length() > LIMIT) { builder.delete(LIMIT, builder.length()); @@ -329,6 +381,27 @@ WHITESPACE = [ \t\r\n]+ appendCurrentFragment(); if (isOverLimit()) return YYEOF; } + "CREATE" { + if (!insideComment) { + setOperation(new Create()); + } + appendCurrentFragment(); + if (isOverLimit()) return YYEOF; + } + "DROP" { + if (!insideComment) { + setOperation(new Drop()); + } + appendCurrentFragment(); + if (isOverLimit()) return YYEOF; + } + "ALTER" { + if (!insideComment) { + setOperation(new Alter()); + } + appendCurrentFragment(); + if (isOverLimit()) return YYEOF; + } "FROM" { if (!insideComment && !extractionDone) { if (operation == NoOp.INSTANCE) { @@ -357,11 +430,27 @@ WHITESPACE = [ \t\r\n]+ } "NEXT" { if (!insideComment && !extractionDone) { - extractionDone = operation.handleNext(); + extractionDone = operation.handleNext(); + } + appendCurrentFragment(); + if (isOverLimit()) return YYEOF; + } + "IF" | "NOT" | "EXISTS" { + appendCurrentFragment(); + if (isOverLimit()) return YYEOF; + } + "TABLE" | "INDEX" | "DATABASE" | "PROCEDURE" | "VIEW" { + if (!insideComment && !extractionDone) { + if (operation.expectingOperationTarget()) { + extractionDone = operation.handleOperationTarget(yytext()); + } else { + extractionDone = operation.handleIdentifier(); } + } appendCurrentFragment(); if (isOverLimit()) return YYEOF; } + {COMMA} { if (!insideComment && !extractionDone) { extractionDone = operation.handleComma(); diff --git a/instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlStatementSanitizerTest.java b/instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlStatementSanitizerTest.java index 737c09f17ce6..df7ce1daa8e5 100644 --- a/instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlStatementSanitizerTest.java +++ b/instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlStatementSanitizerTest.java @@ -60,6 +60,17 @@ void veryLongSelectStatementsAreOk() { assertThat(result).isEqualTo(expected); } + @ParameterizedTest + @ArgumentsSource(DdlArgs.class) + void checkDdlOperationStatementsAreOk( + String actual, Function expectFunc) { + SqlStatementInfo result = SqlStatementSanitizer.create(true).sanitize(actual); + SqlStatementInfo expected = expectFunc.apply(actual); + assertThat(result.getFullStatement()).isEqualTo(expected.getFullStatement()); + assertThat(result.getOperation()).isEqualTo(expected.getOperation()); + assertThat(result.getMainIdentifier()).isEqualTo(expected.getMainIdentifier()); + } + @Test void lotsOfTicksDontCauseStackOverflowOrLongRuntimes() { String s = "'"; @@ -331,4 +342,34 @@ public Stream provideArguments(ExtensionContext context) th Arguments.of(null, expect(null, null))); } } + + static class DdlArgs implements ArgumentsProvider { + + static Function expect(String operation, String identifier) { + return sql -> SqlStatementInfo.create(sql, operation, identifier); + } + + static Function expect( + String sql, String operation, String identifier) { + return ignored -> SqlStatementInfo.create(sql, operation, identifier); + } + + @Override + public Stream provideArguments(ExtensionContext context) throws Exception { + return Stream.of( + Arguments.of("CREATE TABLE `table`", expect("CREATE TABLE", "table")), + Arguments.of("CREATE TABLE IF NOT EXISTS table", expect("CREATE TABLE", "table")), + Arguments.of("DROP TABLE `if`", expect("DROP TABLE", "if")), + Arguments.of( + "ALTER TABLE table ADD CONSTRAINT c FOREIGN KEY (foreign_id) REFERENCES ref (id)", + expect("ALTER TABLE", "table")), + Arguments.of("CREATE INDEX types_name ON types (name)", expect("CREATE INDEX", null)), + Arguments.of("DROP INDEX types_name ON types (name)", expect("DROP INDEX", null)), + Arguments.of( + "CREATE VIEW tmp AS SELECT type FROM table WHERE id = ?", + expect("CREATE VIEW", null)), + Arguments.of( + "CREATE PROCEDURE p AS SELECT * FROM table GO", expect("CREATE PROCEDURE", null))); + } + } } diff --git a/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/java/CassandraClientTest.java b/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/java/CassandraClientTest.java index 424eaf6aef69..7ea430aca23f 100644 --- a/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/java/CassandraClientTest.java +++ b/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/java/CassandraClientTest.java @@ -225,8 +225,8 @@ private static Stream provideSyncParameters() { null, "DROP KEYSPACE IF EXISTS sync_test", "DROP KEYSPACE IF EXISTS sync_test", - "DB Query", - null, + "DROP", + "DROP", null))), Arguments.of( named( @@ -235,8 +235,8 @@ private static Stream provideSyncParameters() { null, "CREATE KEYSPACE sync_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}", "CREATE KEYSPACE sync_test WITH REPLICATION = {?:?, ?:?}", - "DB Query", - null, + "CREATE", + "CREATE", null))), Arguments.of( named( @@ -245,9 +245,9 @@ private static Stream provideSyncParameters() { "sync_test", "CREATE TABLE sync_test.users ( id UUID PRIMARY KEY, name text )", "CREATE TABLE sync_test.users ( id UUID PRIMARY KEY, name text )", - "sync_test", - null, - null))), + "CREATE TABLE sync_test.users", + "CREATE TABLE", + "sync_test.users"))), Arguments.of( named( "Insert data", @@ -279,8 +279,8 @@ private static Stream provideAsyncParameters() { null, "DROP KEYSPACE IF EXISTS async_test", "DROP KEYSPACE IF EXISTS async_test", - "DB Query", - null, + "DROP", + "DROP", null))), Arguments.of( named( @@ -289,8 +289,8 @@ private static Stream provideAsyncParameters() { null, "CREATE KEYSPACE async_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}", "CREATE KEYSPACE async_test WITH REPLICATION = {?:?, ?:?}", - "DB Query", - null, + "CREATE", + "CREATE", null))), Arguments.of( named( @@ -299,9 +299,9 @@ private static Stream provideAsyncParameters() { "async_test", "CREATE TABLE async_test.users ( id UUID PRIMARY KEY, name text )", "CREATE TABLE async_test.users ( id UUID PRIMARY KEY, name text )", - "async_test", - null, - null))), + "CREATE TABLE async_test.users", + "CREATE TABLE", + "async_test.users"))), Arguments.of( named( "Insert data", diff --git a/instrumentation/cassandra/cassandra-4-common/testing/src/main/java/io/opentelemetry/cassandra/v4/common/AbstractCassandraTest.java b/instrumentation/cassandra/cassandra-4-common/testing/src/main/java/io/opentelemetry/cassandra/v4/common/AbstractCassandraTest.java index e509823582dc..a8424cd650f5 100644 --- a/instrumentation/cassandra/cassandra-4-common/testing/src/main/java/io/opentelemetry/cassandra/v4/common/AbstractCassandraTest.java +++ b/instrumentation/cassandra/cassandra-4-common/testing/src/main/java/io/opentelemetry/cassandra/v4/common/AbstractCassandraTest.java @@ -200,8 +200,8 @@ private static Stream provideSyncParameters() { null, "DROP KEYSPACE IF EXISTS sync_test", "DROP KEYSPACE IF EXISTS sync_test", - "DB Query", - null, + "DROP", + "DROP", null))), Arguments.of( named( @@ -210,8 +210,8 @@ private static Stream provideSyncParameters() { null, "CREATE KEYSPACE sync_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}", "CREATE KEYSPACE sync_test WITH REPLICATION = {?:?, ?:?}", - "DB Query", - null, + "CREATE", + "CREATE", null))), Arguments.of( named( @@ -220,9 +220,9 @@ private static Stream provideSyncParameters() { "sync_test", "CREATE TABLE sync_test.users ( id UUID PRIMARY KEY, name text )", "CREATE TABLE sync_test.users ( id UUID PRIMARY KEY, name text )", - "sync_test", - null, - null))), + "CREATE TABLE sync_test.users", + "CREATE TABLE", + "sync_test.users"))), Arguments.of( named( "Insert data", @@ -254,8 +254,8 @@ private static Stream provideAsyncParameters() { null, "DROP KEYSPACE IF EXISTS async_test", "DROP KEYSPACE IF EXISTS async_test", - "DB Query", - null, + "DROP", + "DROP", null))), Arguments.of( named( @@ -264,8 +264,8 @@ private static Stream provideAsyncParameters() { null, "CREATE KEYSPACE async_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}", "CREATE KEYSPACE async_test WITH REPLICATION = {?:?, ?:?}", - "DB Query", - null, + "CREATE", + "CREATE", null))), Arguments.of( named( @@ -274,9 +274,9 @@ private static Stream provideAsyncParameters() { "async_test", "CREATE TABLE async_test.users ( id UUID PRIMARY KEY, name text )", "CREATE TABLE async_test.users ( id UUID PRIMARY KEY, name text )", - "async_test", - null, - null))), + "CREATE TABLE async_test.users", + "CREATE TABLE", + "async_test.users"))), Arguments.of( named( "Insert data", diff --git a/instrumentation/cassandra/cassandra-4.4/testing/src/main/java/io/opentelemetry/testing/cassandra/v4_4/AbstractCassandra44Test.java b/instrumentation/cassandra/cassandra-4.4/testing/src/main/java/io/opentelemetry/testing/cassandra/v4_4/AbstractCassandra44Test.java index 53e53c4bd5c8..f9c1128008f2 100644 --- a/instrumentation/cassandra/cassandra-4.4/testing/src/main/java/io/opentelemetry/testing/cassandra/v4_4/AbstractCassandra44Test.java +++ b/instrumentation/cassandra/cassandra-4.4/testing/src/main/java/io/opentelemetry/testing/cassandra/v4_4/AbstractCassandra44Test.java @@ -106,8 +106,8 @@ private static Stream provideReactiveParameters() { null, "DROP KEYSPACE IF EXISTS reactive_test", "DROP KEYSPACE IF EXISTS reactive_test", - "DB Query", - null, + "DROP", + "DROP", null))), Arguments.of( named( @@ -116,8 +116,8 @@ private static Stream provideReactiveParameters() { null, "CREATE KEYSPACE reactive_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}", "CREATE KEYSPACE reactive_test WITH REPLICATION = {?:?, ?:?}", - "DB Query", - null, + "CREATE", + "CREATE", null))), Arguments.of( named( @@ -126,9 +126,9 @@ private static Stream provideReactiveParameters() { "reactive_test", "CREATE TABLE reactive_test.users ( id UUID PRIMARY KEY, name text )", "CREATE TABLE reactive_test.users ( id UUID PRIMARY KEY, name text )", - "reactive_test", - null, - null))), + "CREATE TABLE reactive_test.users", + "CREATE TABLE", + "reactive_test.users"))), Arguments.of( named( "Insert data", diff --git a/instrumentation/jdbc/javaagent/src/test/groovy/JdbcInstrumentationTest.groovy b/instrumentation/jdbc/javaagent/src/test/groovy/JdbcInstrumentationTest.groovy index 0463b6bf4d53..b95a9502b826 100644 --- a/instrumentation/jdbc/javaagent/src/test/groovy/JdbcInstrumentationTest.groovy +++ b/instrumentation/jdbc/javaagent/src/test/groovy/JdbcInstrumentationTest.groovy @@ -399,7 +399,7 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification { hasNoParent() } span(1) { - name dbNameLower + name spanName kind CLIENT childOf span(0) attributes { @@ -410,6 +410,8 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification { } "$SemanticAttributes.DB_STATEMENT" query "$SemanticAttributes.DB_CONNECTION_STRING" url + "$SemanticAttributes.DB_OPERATION" "CREATE TABLE" + "$SemanticAttributes.DB_SQL_TABLE" table } } } @@ -420,19 +422,19 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification { connection.close() where: - system | connection | username | query | url - "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "CREATE TABLE S_H2 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "h2:mem:" - "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "CREATE TABLE S_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))" | "derby:memory:" - "hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), null) | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB (id INTEGER not NULL, PRIMARY KEY ( id ))" | "hsqldb:mem:" - "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "CREATE TABLE S_H2_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | "h2:mem:" - "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "CREATE TABLE S_DERBY_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | "derby:memory:" - "hsqldb" | cpDatasources.get("tomcat").get("hsqldb").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | "hsqldb:mem:" - "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "CREATE TABLE S_H2_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | "h2:mem:" - "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "CREATE TABLE S_DERBY_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | "derby:memory:" - "hsqldb" | cpDatasources.get("hikari").get("hsqldb").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | "hsqldb:mem:" - "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "CREATE TABLE S_H2_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "h2:mem:" - "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "CREATE TABLE S_DERBY_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "derby:memory:" - "hsqldb" | cpDatasources.get("c3p0").get("hsqldb").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "hsqldb:mem:" + system | connection | username | query | spanName | url | table + "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "CREATE TABLE S_H2 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.S_H2" | "h2:mem:" | "S_H2" + "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "CREATE TABLE S_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.S_DERBY" | "derby:memory:" | "S_DERBY" + "hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), null) | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE PUBLIC.S_HSQLDB" | "hsqldb:mem:" | "PUBLIC.S_HSQLDB" + "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "CREATE TABLE S_H2_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.S_H2_TOMCAT" | "h2:mem:" | "S_H2_TOMCAT" + "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "CREATE TABLE S_DERBY_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.S_DERBY_TOMCAT" | "derby:memory:" | "S_DERBY_TOMCAT" + "hsqldb" | cpDatasources.get("tomcat").get("hsqldb").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE PUBLIC.S_HSQLDB_TOMCAT" | "hsqldb:mem:" | "PUBLIC.S_HSQLDB_TOMCAT" + "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "CREATE TABLE S_H2_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.S_H2_HIKARI" | "h2:mem:" | "S_H2_HIKARI" + "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "CREATE TABLE S_DERBY_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.S_DERBY_HIKARI" | "derby:memory:" | "S_DERBY_HIKARI" + "hsqldb" | cpDatasources.get("hikari").get("hsqldb").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE PUBLIC.S_HSQLDB_HIKARI" | "hsqldb:mem:" | "PUBLIC.S_HSQLDB_HIKARI" + "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "CREATE TABLE S_H2_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.S_H2_C3P0" | "h2:mem:" | "S_H2_C3P0" + "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "CREATE TABLE S_DERBY_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.S_DERBY_C3P0" | "derby:memory:" | "S_DERBY_C3P0" + "hsqldb" | cpDatasources.get("c3p0").get("hsqldb").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE PUBLIC.S_HSQLDB_C3P0" | "hsqldb:mem:" | "PUBLIC.S_HSQLDB_C3P0" } def "prepared statement update on #system with #connection.getClass().getCanonicalName() generates a span"() { @@ -452,7 +454,7 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification { hasNoParent() } span(1) { - name dbNameLower + name spanName kind CLIENT childOf span(0) attributes { @@ -463,6 +465,8 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification { } "$SemanticAttributes.DB_STATEMENT" query "$SemanticAttributes.DB_CONNECTION_STRING" url + "$SemanticAttributes.DB_OPERATION" "CREATE TABLE" + "$SemanticAttributes.DB_SQL_TABLE" table } } } @@ -473,15 +477,15 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification { connection.close() where: - system | connection | username | query | url - "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "CREATE TABLE PS_H2 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "h2:mem:" - "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "CREATE TABLE PS_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))" | "derby:memory:" - "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "CREATE TABLE PS_H2_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | "h2:mem:" - "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "CREATE TABLE PS_DERBY_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | "derby:memory:" - "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "CREATE TABLE PS_H2_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | "h2:mem:" - "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "CREATE TABLE PS_DERBY_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | "derby:memory:" - "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "CREATE TABLE PS_H2_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "h2:mem:" - "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "CREATE TABLE PS_DERBY_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "derby:memory:" + system | connection | username | query | spanName | url | table + "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "CREATE TABLE PS_H2 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.PS_H2" | "h2:mem:" | "PS_H2" + "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "CREATE TABLE PS_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.PS_DERBY" | "derby:memory:" | "PS_DERBY" + "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "CREATE TABLE PS_H2_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.PS_H2_TOMCAT" | "h2:mem:" | "PS_H2_TOMCAT" + "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "CREATE TABLE PS_DERBY_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.PS_DERBY_TOMCAT" | "derby:memory:" | "PS_DERBY_TOMCAT" + "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "CREATE TABLE PS_H2_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.PS_H2_HIKARI" | "h2:mem:" | "PS_H2_HIKARI" + "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "CREATE TABLE PS_DERBY_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.PS_DERBY_HIKARI" | "derby:memory:" | "PS_DERBY_HIKARI" + "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "CREATE TABLE PS_H2_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.PS_H2_C3P0" | "h2:mem:" | "PS_H2_C3P0" + "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "CREATE TABLE PS_DERBY_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.PS_DERBY_C3P0" | "derby:memory:" | "PS_DERBY_C3P0" } def "connection constructor throwing then generating correct spans after recovery using #driver connection (prepare statement = #prepareStatement)"() { @@ -698,12 +702,12 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification { } where: - 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 + 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" | "CREATE TABLE test.table" | "test" | "CREATE TABLE" | "table" + "jdbc:testdb://localhost" | "CREATE TABLE table" | "CREATE TABLE table" | "CREATE TABLE table" | null | "CREATE TABLE" | "table" } def "#connectionPoolName connections should be cached in case of wrapped connections"() { diff --git a/instrumentation/r2dbc-1.0/testing/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/AbstractR2dbcStatementTest.java b/instrumentation/r2dbc-1.0/testing/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/AbstractR2dbcStatementTest.java index 50a458a9bb1e..9d33342b74ad 100644 --- a/instrumentation/r2dbc-1.0/testing/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/AbstractR2dbcStatementTest.java +++ b/instrumentation/r2dbc-1.0/testing/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/AbstractR2dbcStatementTest.java @@ -204,9 +204,9 @@ private static Stream provideParameters() { system.system, "CREATE TABLE person (id SERIAL PRIMARY KEY, first_name VARCHAR(255), last_name VARCHAR(255))", "CREATE TABLE person (id SERIAL PRIMARY KEY, first_name VARCHAR(?), last_name VARCHAR(?))", - DB, - null, - null))), + "CREATE TABLE " + DB + ".person", + "person", + "CREATE TABLE"))), Arguments.of( named( system.system + " Insert",