diff --git a/agent-bootstrap/src/main/java/io/opentelemetry/auto/bootstrap/instrumentation/decorator/DatabaseClientDecorator.java b/agent-bootstrap/src/main/java/io/opentelemetry/auto/bootstrap/instrumentation/decorator/DatabaseClientDecorator.java index 408a82a107..9f4cd0d76c 100644 --- a/agent-bootstrap/src/main/java/io/opentelemetry/auto/bootstrap/instrumentation/decorator/DatabaseClientDecorator.java +++ b/agent-bootstrap/src/main/java/io/opentelemetry/auto/bootstrap/instrumentation/decorator/DatabaseClientDecorator.java @@ -28,6 +28,11 @@ public abstract class DatabaseClientDecorator extends ClientDecorato protected abstract String dbInstance(CONNECTION connection); + // TODO make abstract after implementing in all subclasses + protected String dbUrl(final CONNECTION connection) { + return null; + } + @Override public Span afterStart(final Span span) { assert span != null; @@ -47,6 +52,7 @@ public abstract class DatabaseClientDecorator extends ClientDecorato if (connection != null) { span.setAttribute(Tags.DB_USER, dbUser(connection)); span.setAttribute(Tags.DB_INSTANCE, dbInstance(connection)); + span.setAttribute(Tags.DB_URL, dbUrl(connection)); if (Config.get().isDbClientSplitByInstance()) { span.setAttribute(MoreTags.SERVICE_NAME, dbInstance(connection)); diff --git a/agent-bootstrap/src/main/java/io/opentelemetry/auto/bootstrap/instrumentation/jdbc/DBInfo.java b/agent-bootstrap/src/main/java/io/opentelemetry/auto/bootstrap/instrumentation/jdbc/DBInfo.java index 2d6484349f..0eedfb6ee8 100644 --- a/agent-bootstrap/src/main/java/io/opentelemetry/auto/bootstrap/instrumentation/jdbc/DBInfo.java +++ b/agent-bootstrap/src/main/java/io/opentelemetry/auto/bootstrap/instrumentation/jdbc/DBInfo.java @@ -21,10 +21,10 @@ import lombok.Data; @Data @Builder(builderClassName = "Builder", toBuilder = true) public class DBInfo { - public static final DBInfo DEFAULT = new Builder().type("database").build(); + public static final DBInfo DEFAULT = new Builder().build(); private final String type; private final String subtype; - private final String url; + private final String shortUrl; // "type:[subtype:]//host:port" private final String user; private final String instance; private final String db; diff --git a/agent-bootstrap/src/main/java/io/opentelemetry/auto/bootstrap/instrumentation/jdbc/JDBCConnectionUrlParser.java b/agent-bootstrap/src/main/java/io/opentelemetry/auto/bootstrap/instrumentation/jdbc/JDBCConnectionUrlParser.java index 282c912d7c..68cb614858 100644 --- a/agent-bootstrap/src/main/java/io/opentelemetry/auto/bootstrap/instrumentation/jdbc/JDBCConnectionUrlParser.java +++ b/agent-bootstrap/src/main/java/io/opentelemetry/auto/bootstrap/instrumentation/jdbc/JDBCConnectionUrlParser.java @@ -508,7 +508,7 @@ public enum JDBCConnectionUrlParser { final String h2Url = jdbcUrl.substring("h2:".length()); if (h2Url.startsWith("mem:")) { - builder.subtype("mem"); + builder.subtype("mem").host(null).port(null); final int propLoc = h2Url.indexOf(";"); if (propLoc >= 0) { instance = h2Url.substring("mem:".length(), propLoc); @@ -516,7 +516,7 @@ public enum JDBCConnectionUrlParser { instance = h2Url.substring("mem:".length()); } } else if (h2Url.startsWith("file:")) { - builder.subtype("file"); + builder.subtype("file").host(null).port(null); final int propLoc = h2Url.indexOf(";"); if (propLoc >= 0) { instance = h2Url.substring("file:".length(), propLoc); @@ -524,7 +524,7 @@ public enum JDBCConnectionUrlParser { instance = h2Url.substring("file:".length()); } } else if (h2Url.startsWith("zip:")) { - builder.subtype("zip"); + builder.subtype("zip").host(null).port(null); final int propLoc = h2Url.indexOf(";"); if (propLoc >= 0) { instance = h2Url.substring("zip:".length(), propLoc); @@ -544,7 +544,7 @@ public enum JDBCConnectionUrlParser { } return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).type("h2").subtype("ssl"); } else { - builder.subtype("file"); + builder.subtype("file").host(null).port(null); final int propLoc = h2Url.indexOf(";"); if (propLoc >= 0) { instance = h2Url.substring(0, propLoc); @@ -572,13 +572,13 @@ public enum JDBCConnectionUrlParser { } final String hsqlUrl = jdbcUrl.substring("hsqldb:".length()); if (hsqlUrl.startsWith("mem:")) { - builder.subtype("mem"); + builder.subtype("mem").host(null).port(null); instance = hsqlUrl.substring("mem:".length()); } else if (hsqlUrl.startsWith("file:")) { - builder.subtype("file"); + builder.subtype("file").host(null).port(null); instance = hsqlUrl.substring("file:".length()); } else if (hsqlUrl.startsWith("res:")) { - builder.subtype("res"); + builder.subtype("res").host(null).port(null); instance = hsqlUrl.substring("res:".length()); } else if (hsqlUrl.startsWith("hsql:")) { if (dbInfo.getPort() == null) { @@ -601,7 +601,7 @@ public enum JDBCConnectionUrlParser { } return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).type("hsqldb").subtype("https"); } else { - builder.subtype("mem"); + builder.subtype("mem").host(null).port(null); instance = hsqlUrl; } return builder.instance(instance); @@ -631,25 +631,25 @@ public enum JDBCConnectionUrlParser { final String details = split[0]; if (details.startsWith("memory:")) { - builder.subtype("memory"); + builder.subtype("memory").host(null).port(null); final String urlInstance = details.substring("memory:".length()); if (!urlInstance.isEmpty()) { instance = urlInstance; } } else if (details.startsWith("directory:")) { - builder.subtype("directory"); + builder.subtype("directory").host(null).port(null); final String urlInstance = details.substring("directory:".length()); if (!urlInstance.isEmpty()) { instance = urlInstance; } } else if (details.startsWith("classpath:")) { - builder.subtype("classpath"); + builder.subtype("classpath").host(null).port(null); final String urlInstance = details.substring("classpath:".length()); if (!urlInstance.isEmpty()) { instance = urlInstance; } } else if (details.startsWith("jar:")) { - builder.subtype("jar"); + builder.subtype("jar").host(null).port(null); final String urlInstance = details.substring("jar:".length()); if (!urlInstance.isEmpty()) { instance = urlInstance; @@ -677,7 +677,7 @@ public enum JDBCConnectionUrlParser { host = url; } } else { - builder.subtype("directory"); + builder.subtype("directory").host(null).port(null); final String urlInstance = details; if (!urlInstance.isEmpty()) { instance = urlInstance; @@ -736,15 +736,42 @@ public enum JDBCConnectionUrlParser { try { if (typeParsers.containsKey(baseType)) { // Delegate to specific parser - return typeParsers.get(baseType).doParse(jdbcUrl, parsedProps).build(); + return withUrl(typeParsers.get(baseType).doParse(jdbcUrl, parsedProps)); } - return GENERIC_URL_LIKE.doParse(connectionUrl, parsedProps).build(); + return withUrl(GENERIC_URL_LIKE.doParse(jdbcUrl, parsedProps)); } catch (final Exception e) { ExceptionLogger.LOGGER.debug("Error parsing URL", e); return parsedProps.build(); } } + private static DBInfo withUrl(final DBInfo.Builder builder) { + final DBInfo info = builder.build(); + final String type = info.getType(); + if (type == null) { + return builder.build(); + } + final StringBuilder url = new StringBuilder(); + url.append(type); + url.append(':'); + final String subtype = info.getSubtype(); + if (subtype != null) { + url.append(subtype); + url.append(':'); + } + final String host = info.getHost(); + if (host != null) { + url.append("//"); + url.append(host); + final Integer port = info.getPort(); + if (port != null) { + url.append(':'); + url.append(port); + } + } + return builder.shortUrl(url.toString()).build(); + } + // Source: https://stackoverflow.com/a/13592567 private static Map splitQuery(final String query, final String separator) { if (query == null || query.isEmpty()) { diff --git a/agent-bootstrap/src/main/java/io/opentelemetry/auto/instrumentation/api/Tags.java b/agent-bootstrap/src/main/java/io/opentelemetry/auto/instrumentation/api/Tags.java index 8699a176e6..9d1a90d1cb 100644 --- a/agent-bootstrap/src/main/java/io/opentelemetry/auto/instrumentation/api/Tags.java +++ b/agent-bootstrap/src/main/java/io/opentelemetry/auto/instrumentation/api/Tags.java @@ -31,4 +31,5 @@ public class Tags { public static final String DB_INSTANCE = "db.instance"; public static final String DB_USER = "db.user"; public static final String DB_STATEMENT = "db.statement"; + public static final String DB_URL = "db.url"; } diff --git a/agent-bootstrap/src/test/groovy/io/opentelemetry/auto/bootstrap/instrumentation/decorator/DatabaseClientDecoratorTest.groovy b/agent-bootstrap/src/test/groovy/io/opentelemetry/auto/bootstrap/instrumentation/decorator/DatabaseClientDecoratorTest.groovy index 57c7c697fb..2770d08028 100644 --- a/agent-bootstrap/src/test/groovy/io/opentelemetry/auto/bootstrap/instrumentation/decorator/DatabaseClientDecoratorTest.groovy +++ b/agent-bootstrap/src/test/groovy/io/opentelemetry/auto/bootstrap/instrumentation/decorator/DatabaseClientDecoratorTest.groovy @@ -56,6 +56,7 @@ class DatabaseClientDecoratorTest extends ClientDecoratorTest { if (session) { 1 * span.setAttribute(Tags.DB_USER, session.user) 1 * span.setAttribute(Tags.DB_INSTANCE, session.instance) + 1 * span.setAttribute(Tags.DB_URL, session.url) if (renameService) { 1 * span.setAttribute(MoreTags.SERVICE_NAME, session.instance) } @@ -66,7 +67,7 @@ class DatabaseClientDecoratorTest extends ClientDecoratorTest { renameService | session false | null true | [user: "test-user"] - false | [instance: "test-instance"] + false | [instance: "test-instance", url: "test:"] true | [user: "test-user", instance: "test-instance"] } @@ -139,6 +140,11 @@ class DatabaseClientDecoratorTest extends ClientDecoratorTest { protected String dbInstance(Map map) { return map.instance } + + @Override + protected String dbUrl(Map map) { + return map.url + } } } } diff --git a/instrumentation/hibernate/hibernate-3.3/src/test/groovy/CriteriaTest.groovy b/instrumentation/hibernate/hibernate-3.3/src/test/groovy/CriteriaTest.groovy index d40105f64b..bba00795b0 100644 --- a/instrumentation/hibernate/hibernate-3.3/src/test/groovy/CriteriaTest.groovy +++ b/instrumentation/hibernate/hibernate-3.3/src/test/groovy/CriteriaTest.groovy @@ -68,6 +68,7 @@ class CriteriaTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^select / + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } diff --git a/instrumentation/hibernate/hibernate-3.3/src/test/groovy/QueryTest.groovy b/instrumentation/hibernate/hibernate-3.3/src/test/groovy/QueryTest.groovy index 732ba27aca..b1111f029f 100644 --- a/instrumentation/hibernate/hibernate-3.3/src/test/groovy/QueryTest.groovy +++ b/instrumentation/hibernate/hibernate-3.3/src/test/groovy/QueryTest.groovy @@ -72,6 +72,7 @@ class QueryTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" String + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } @@ -117,6 +118,7 @@ class QueryTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^select / + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } @@ -195,6 +197,7 @@ class QueryTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^select / + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } diff --git a/instrumentation/hibernate/hibernate-3.3/src/test/groovy/SessionTest.groovy b/instrumentation/hibernate/hibernate-3.3/src/test/groovy/SessionTest.groovy index 178a377055..cd902a674d 100644 --- a/instrumentation/hibernate/hibernate-3.3/src/test/groovy/SessionTest.groovy +++ b/instrumentation/hibernate/hibernate-3.3/src/test/groovy/SessionTest.groovy @@ -85,6 +85,7 @@ class SessionTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^select / + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } @@ -170,6 +171,7 @@ class SessionTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" String + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } @@ -242,6 +244,7 @@ class SessionTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^select / + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } @@ -264,6 +267,7 @@ class SessionTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" String + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } @@ -394,6 +398,7 @@ class SessionTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" String + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } @@ -472,6 +477,7 @@ class SessionTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" String + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } @@ -571,6 +577,7 @@ class SessionTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^insert / + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } @@ -585,6 +592,7 @@ class SessionTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^delete / + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } diff --git a/instrumentation/hibernate/hibernate-4.0/src/test/groovy/CriteriaTest.groovy b/instrumentation/hibernate/hibernate-4.0/src/test/groovy/CriteriaTest.groovy index d40105f64b..bba00795b0 100644 --- a/instrumentation/hibernate/hibernate-4.0/src/test/groovy/CriteriaTest.groovy +++ b/instrumentation/hibernate/hibernate-4.0/src/test/groovy/CriteriaTest.groovy @@ -68,6 +68,7 @@ class CriteriaTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^select / + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } diff --git a/instrumentation/hibernate/hibernate-4.0/src/test/groovy/QueryTest.groovy b/instrumentation/hibernate/hibernate-4.0/src/test/groovy/QueryTest.groovy index a3122096cb..8f4361bf41 100644 --- a/instrumentation/hibernate/hibernate-4.0/src/test/groovy/QueryTest.groovy +++ b/instrumentation/hibernate/hibernate-4.0/src/test/groovy/QueryTest.groovy @@ -72,6 +72,7 @@ class QueryTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" String + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } @@ -117,6 +118,7 @@ class QueryTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^select / + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } @@ -195,6 +197,7 @@ class QueryTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^select / + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } diff --git a/instrumentation/hibernate/hibernate-4.0/src/test/groovy/SessionTest.groovy b/instrumentation/hibernate/hibernate-4.0/src/test/groovy/SessionTest.groovy index fc39552166..518ac19f96 100644 --- a/instrumentation/hibernate/hibernate-4.0/src/test/groovy/SessionTest.groovy +++ b/instrumentation/hibernate/hibernate-4.0/src/test/groovy/SessionTest.groovy @@ -84,6 +84,7 @@ class SessionTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" String + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } @@ -175,6 +176,7 @@ class SessionTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^select / + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } @@ -197,6 +199,7 @@ class SessionTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" String + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } @@ -327,6 +330,7 @@ class SessionTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" String + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } @@ -405,6 +409,7 @@ class SessionTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" String + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } @@ -504,6 +509,7 @@ class SessionTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^insert / + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } @@ -518,6 +524,7 @@ class SessionTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^delete / + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } @@ -550,6 +557,7 @@ class SessionTest extends AbstractHibernateTest { "$Tags.DB_INSTANCE" "db1" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^insert / + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } diff --git a/instrumentation/hibernate/hibernate-4.3/src/test/groovy/ProcedureCallTest.groovy b/instrumentation/hibernate/hibernate-4.3/src/test/groovy/ProcedureCallTest.groovy index b9fdc7786c..6fad7c86e9 100644 --- a/instrumentation/hibernate/hibernate-4.3/src/test/groovy/ProcedureCallTest.groovy +++ b/instrumentation/hibernate/hibernate-4.3/src/test/groovy/ProcedureCallTest.groovy @@ -111,6 +111,7 @@ class ProcedureCallTest extends AgentTestRunner { "$Tags.DB_INSTANCE" "test" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" "{call TEST_PROC()}" + "$Tags.DB_URL" "hsqldb:mem:" "span.origin.type" "org.hsqldb.jdbc.JDBCCallableStatement" } } diff --git a/instrumentation/hibernate/hibernate-4.3/src/test/groovy/SpringJpaTest.groovy b/instrumentation/hibernate/hibernate-4.3/src/test/groovy/SpringJpaTest.groovy index e0e43f7ec3..06896a149e 100644 --- a/instrumentation/hibernate/hibernate-4.3/src/test/groovy/SpringJpaTest.groovy +++ b/instrumentation/hibernate/hibernate-4.3/src/test/groovy/SpringJpaTest.groovy @@ -55,6 +55,7 @@ class SpringJpaTest extends AgentTestRunner { "$Tags.DB_INSTANCE" "test" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" "select customer0_.id as id1_0_, customer0_.firstName as firstNam2_0_, customer0_.lastName as lastName3_0_ from Customer customer0_" + "$Tags.DB_URL" "hsqldb:mem:" "span.origin.type" "org.hsqldb.jdbc.JDBCPreparedStatement" } } @@ -83,6 +84,7 @@ class SpringJpaTest extends AgentTestRunner { "$Tags.DB_INSTANCE" "test" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" "call next value for hibernate_sequence" + "$Tags.DB_URL" "hsqldb:mem:" "span.origin.type" "org.hsqldb.jdbc.JDBCPreparedStatement" } } @@ -99,6 +101,7 @@ class SpringJpaTest extends AgentTestRunner { "$Tags.DB_INSTANCE" "test" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/insert into Customer \(.*\) values \(.*, \?, \?\)/ + "$Tags.DB_URL" "hsqldb:mem:" "span.origin.type" "org.hsqldb.jdbc.JDBCPreparedStatement" } } @@ -124,6 +127,7 @@ class SpringJpaTest extends AgentTestRunner { "$Tags.DB_INSTANCE" "test" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" "select customer0_.id as id1_0_0_, customer0_.firstName as firstNam2_0_0_, customer0_.lastName as lastName3_0_0_ from Customer customer0_ where customer0_.id=?" + "$Tags.DB_URL" "hsqldb:mem:" "span.origin.type" "org.hsqldb.jdbc.JDBCPreparedStatement" } } @@ -139,6 +143,7 @@ class SpringJpaTest extends AgentTestRunner { "$Tags.DB_INSTANCE" "test" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" "update Customer set firstName=?, lastName=? where id=?" + "$Tags.DB_URL" "hsqldb:mem:" "span.origin.type" "org.hsqldb.jdbc.JDBCPreparedStatement" } } @@ -164,6 +169,7 @@ class SpringJpaTest extends AgentTestRunner { "$Tags.DB_INSTANCE" "test" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" "select customer0_.id as id1_0_, customer0_.firstName as firstNam2_0_, customer0_.lastName as lastName3_0_ from Customer customer0_ where customer0_.lastName=?" + "$Tags.DB_URL" "hsqldb:mem:" "span.origin.type" "org.hsqldb.jdbc.JDBCPreparedStatement" } } @@ -187,6 +193,7 @@ class SpringJpaTest extends AgentTestRunner { "$Tags.DB_INSTANCE" "test" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" "select customer0_.id as id1_0_0_, customer0_.firstName as firstNam2_0_0_, customer0_.lastName as lastName3_0_0_ from Customer customer0_ where customer0_.id=?" + "$Tags.DB_URL" "hsqldb:mem:" "span.origin.type" "org.hsqldb.jdbc.JDBCPreparedStatement" } } @@ -202,6 +209,7 @@ class SpringJpaTest extends AgentTestRunner { "$Tags.DB_INSTANCE" "test" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" "delete from Customer where id=?" + "$Tags.DB_URL" "hsqldb:mem:" "span.origin.type" "org.hsqldb.jdbc.JDBCPreparedStatement" } } diff --git a/instrumentation/java-concurrent/src/slickTest/groovy/SlickTest.groovy b/instrumentation/java-concurrent/src/slickTest/groovy/SlickTest.groovy index d714bd6962..41677a82cd 100644 --- a/instrumentation/java-concurrent/src/slickTest/groovy/SlickTest.groovy +++ b/instrumentation/java-concurrent/src/slickTest/groovy/SlickTest.groovy @@ -53,6 +53,7 @@ class SlickTest extends AgentTestRunner { "$Tags.DB_INSTANCE" SlickUtils.Db() "$Tags.DB_USER" SlickUtils.Username() "$Tags.DB_STATEMENT" SlickUtils.TestQuery() + "$Tags.DB_URL" "h2:mem:" "span.origin.type" "org.h2.jdbc.JdbcPreparedStatement" } } diff --git a/instrumentation/jdbc/src/main/java/io/opentelemetry/auto/instrumentation/jdbc/JDBCDecorator.java b/instrumentation/jdbc/src/main/java/io/opentelemetry/auto/instrumentation/jdbc/JDBCDecorator.java index 6b31a3b908..6737956805 100644 --- a/instrumentation/jdbc/src/main/java/io/opentelemetry/auto/instrumentation/jdbc/JDBCDecorator.java +++ b/instrumentation/jdbc/src/main/java/io/opentelemetry/auto/instrumentation/jdbc/JDBCDecorator.java @@ -65,6 +65,11 @@ public class JDBCDecorator extends DatabaseClientDecorator { } } + @Override + protected String dbUrl(final DBInfo info) { + return info.getShortUrl(); + } + public Span onConnection(final Span span, final Connection connection) { DBInfo dbInfo = JDBCMaps.connectionInfo.get(connection); /* diff --git a/instrumentation/jdbc/src/test/groovy/JDBCConnectionUrlParserTest.groovy b/instrumentation/jdbc/src/test/groovy/JDBCConnectionUrlParserTest.groovy index 9d83a78429..a2fd4c78ae 100644 --- a/instrumentation/jdbc/src/test/groovy/JDBCConnectionUrlParserTest.groovy +++ b/instrumentation/jdbc/src/test/groovy/JDBCConnectionUrlParserTest.groovy @@ -55,7 +55,7 @@ class JDBCConnectionUrlParserTest extends AgentSpecification { def info = parse(url, props) expect: - info.url == expected.url + info.shortUrl == expected.shortUrl info.type == expected.type info.host == expected.host info.port == expected.port @@ -65,132 +65,133 @@ class JDBCConnectionUrlParserTest extends AgentSpecification { info == expected where: - url | props | type | subtype | user | host | port | instance | db - // https://jdbc.postgresql.org/documentation/94/connect.html - "jdbc:postgresql:///" | null | "postgresql" | null | null | "localhost" | 5432 | null | null - "jdbc:postgresql:///" | stdProps | "postgresql" | null | "stdUserName" | "stdServerName" | 9999 | null | "stdDatabaseName" - "jdbc:postgresql://pg.host" | null | "postgresql" | null | null | "pg.host" | 5432 | null | null - "jdbc:postgresql://pg.host:11/pgdb?user=pguser&password=PW" | null | "postgresql" | null | "pguser" | "pg.host" | 11 | null | "pgdb" - "jdbc:postgresql://pg.host:11/pgdb?user=pguser&password=PW" | stdProps | "postgresql" | null | "pguser" | "pg.host" | 11 | null | "pgdb" + url | props | shortUrl | type | subtype | user | host | port | instance | db + // https://jdbc.postgresql.org/documentation/94/connect.html + "jdbc:postgresql:///" | null | "postgresql://localhost:5432" | "postgresql" | null | null | "localhost" | 5432 | null | null + "jdbc:postgresql:///" | stdProps | "postgresql://stdServerName:9999" | "postgresql" | null | "stdUserName" | "stdServerName" | 9999 | null | "stdDatabaseName" + "jdbc:postgresql://pg.host" | null | "postgresql://pg.host:5432" | "postgresql" | null | null | "pg.host" | 5432 | null | null + "jdbc:postgresql://pg.host:11/pgdb?user=pguser&password=PW" | null | "postgresql://pg.host:11" | "postgresql" | null | "pguser" | "pg.host" | 11 | null | "pgdb" + + "jdbc:postgresql://pg.host:11/pgdb?user=pguser&password=PW" | stdProps | "postgresql://pg.host:11" | "postgresql" | null | "pguser" | "pg.host" | 11 | null | "pgdb" // https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-jdbc-url-format.html // https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-configuration-properties.html - "jdbc:mysql:///" | null | "mysql" | null | null | "localhost" | 3306 | null | null - "jdbc:mysql:///" | stdProps | "mysql" | null | "stdUserName" | "stdServerName" | 9999 | null | "stdDatabaseName" - "jdbc:mysql://my.host" | null | "mysql" | null | null | "my.host" | 3306 | null | null - "jdbc:mysql://my.host?user=myuser&password=PW" | null | "mysql" | null | "myuser" | "my.host" | 3306 | null | null - "jdbc:mysql://my.host:22/mydb?user=myuser&password=PW" | null | "mysql" | null | "myuser" | "my.host" | 22 | null | "mydb" - "jdbc:mysql://127.0.0.1:22/mydb?user=myuser&password=PW" | stdProps | "mysql" | null | "myuser" | "127.0.0.1" | 22 | null | "mydb" + "jdbc:mysql:///" | null | "mysql://localhost:3306" | "mysql" | null | null | "localhost" | 3306 | null | null + "jdbc:mysql:///" | stdProps | "mysql://stdServerName:9999" | "mysql" | null | "stdUserName" | "stdServerName" | 9999 | null | "stdDatabaseName" + "jdbc:mysql://my.host" | null | "mysql://my.host:3306" | "mysql" | null | null | "my.host" | 3306 | null | null + "jdbc:mysql://my.host?user=myuser&password=PW" | null | "mysql://my.host:3306" | "mysql" | null | "myuser" | "my.host" | 3306 | null | null + "jdbc:mysql://my.host:22/mydb?user=myuser&password=PW" | null | "mysql://my.host:22" | "mysql" | null | "myuser" | "my.host" | 22 | null | "mydb" + "jdbc:mysql://127.0.0.1:22/mydb?user=myuser&password=PW" | stdProps | "mysql://127.0.0.1:22" | "mysql" | null | "myuser" | "127.0.0.1" | 22 | null | "mydb" - // https://mariadb.com/kb/en/library/about-mariadb-connector-j/#connection-strings - "jdbc:mariadb:127.0.0.1:33/mdbdb" | null | "mariadb" | null | null | "127.0.0.1" | 33 | null | "mdbdb" - "jdbc:mariadb:localhost/mdbdb" | null | "mariadb" | null | null | "localhost" | 3306 | null | "mdbdb" - "jdbc:mariadb:localhost/mdbdb?user=mdbuser&password=PW" | stdProps | "mariadb" | null | "mdbuser" | "localhost" | 9999 | null | "mdbdb" - "jdbc:mariadb:localhost:33/mdbdb" | stdProps | "mariadb" | null | "stdUserName" | "localhost" | 33 | null | "mdbdb" - "jdbc:mariadb://mdb.host:33/mdbdb?user=mdbuser&password=PW" | null | "mariadb" | null | "mdbuser" | "mdb.host" | 33 | null | "mdbdb" - "jdbc:mariadb:aurora://mdb.host/mdbdb" | null | "mariadb" | "aurora" | null | "mdb.host" | 3306 | null | "mdbdb" - "jdbc:mysql:aurora://mdb.host/mdbdb" | null | "mysql" | "aurora" | null | "mdb.host" | 3306 | null | "mdbdb" - "jdbc:mysql:failover://localhost/mdbdb?autoReconnect=true" | null | "mysql" | "failover" | null | "localhost" | 3306 | null | "mdbdb" - "jdbc:mariadb:failover://mdb.host1:33,mdb.host/mdbdb?characterEncoding=utf8" | null | "mariadb" | "failover" | null | "mdb.host1" | 33 | null | "mdbdb" - "jdbc:mariadb:sequential://mdb.host1,mdb.host2:33/mdbdb" | null | "mariadb" | "sequential" | null | "mdb.host1" | 3306 | null | "mdbdb" - "jdbc:mariadb:loadbalance://127.0.0.1:33,mdb.host/mdbdb" | null | "mariadb" | "loadbalance" | null | "127.0.0.1" | 33 | null | "mdbdb" - "jdbc:mariadb:loadbalance://[2001:0660:7401:0200:0000:0000:0edf:bdd7]:33,mdb.host/mdbdb" | null | "mariadb" | "loadbalance" | null | "2001:0660:7401:0200:0000:0000:0edf:bdd7" | 33 | null | "mdbdb" - "jdbc:mysql:loadbalance://127.0.0.1,127.0.0.1:3306/mdbdb?user=mdbuser&password=PW" | null | "mysql" | "loadbalance" | "mdbuser" | "127.0.0.1" | 3306 | null | "mdbdb" - "jdbc:mariadb:replication://localhost:33,anotherhost:3306/mdbdb" | null | "mariadb" | "replication" | null | "localhost" | 33 | null | "mdbdb" + // https://mariadb.com/kb/en/library/about-mariadb-connector-j/#connection-strings + "jdbc:mariadb:127.0.0.1:33/mdbdb" | null | "mariadb://127.0.0.1:33" | "mariadb" | null | null | "127.0.0.1" | 33 | null | "mdbdb" + "jdbc:mariadb:localhost/mdbdb" | null | "mariadb://localhost:3306" | "mariadb" | null | null | "localhost" | 3306 | null | "mdbdb" + "jdbc:mariadb:localhost/mdbdb?user=mdbuser&password=PW" | stdProps | "mariadb://localhost:9999" | "mariadb" | null | "mdbuser" | "localhost" | 9999 | null | "mdbdb" + "jdbc:mariadb:localhost:33/mdbdb" | stdProps | "mariadb://localhost:33" | "mariadb" | null | "stdUserName" | "localhost" | 33 | null | "mdbdb" + "jdbc:mariadb://mdb.host:33/mdbdb?user=mdbuser&password=PW" | null | "mariadb://mdb.host:33" | "mariadb" | null | "mdbuser" | "mdb.host" | 33 | null | "mdbdb" + "jdbc:mariadb:aurora://mdb.host/mdbdb" | null | "mariadb:aurora://mdb.host:3306" | "mariadb" | "aurora" | null | "mdb.host" | 3306 | null | "mdbdb" + "jdbc:mysql:aurora://mdb.host/mdbdb" | null | "mysql:aurora://mdb.host:3306" | "mysql" | "aurora" | null | "mdb.host" | 3306 | null | "mdbdb" + "jdbc:mysql:failover://localhost/mdbdb?autoReconnect=true" | null | "mysql:failover://localhost:3306" | "mysql" | "failover" | null | "localhost" | 3306 | null | "mdbdb" + "jdbc:mariadb:failover://mdb.host1:33,mdb.host/mdbdb?characterEncoding=utf8" | null | "mariadb:failover://mdb.host1:33" | "mariadb" | "failover" | null | "mdb.host1" | 33 | null | "mdbdb" + "jdbc:mariadb:sequential://mdb.host1,mdb.host2:33/mdbdb" | null | "mariadb:sequential://mdb.host1:3306" | "mariadb" | "sequential" | null | "mdb.host1" | 3306 | null | "mdbdb" + "jdbc:mariadb:loadbalance://127.0.0.1:33,mdb.host/mdbdb" | null | "mariadb:loadbalance://127.0.0.1:33" | "mariadb" | "loadbalance" | null | "127.0.0.1" | 33 | null | "mdbdb" + "jdbc:mariadb:loadbalance://[2001:0660:7401:0200:0000:0000:0edf:bdd7]:33,mdb.host/mdbdb" | null | "mariadb:loadbalance://2001:0660:7401:0200:0000:0000:0edf:bdd7:33" | "mariadb" | "loadbalance" | null | "2001:0660:7401:0200:0000:0000:0edf:bdd7" | 33 | null | "mdbdb" + "jdbc:mysql:loadbalance://127.0.0.1,127.0.0.1:3306/mdbdb?user=mdbuser&password=PW" | null | "mysql:loadbalance://127.0.0.1:3306" | "mysql" | "loadbalance" | "mdbuser" | "127.0.0.1" | 3306 | null | "mdbdb" + "jdbc:mariadb:replication://localhost:33,anotherhost:3306/mdbdb" | null | "mariadb:replication://localhost:33" | "mariadb" | "replication" | null | "localhost" | 33 | null | "mdbdb" "jdbc:mysql:replication://address=(HOST=127.0.0.1)(port=33)(user=mdbuser)(password=PW)," + - "address=(host=mdb.host)(port=3306)(user=otheruser)(password=PW)/mdbdb?user=wrong&password=PW" | null | "mysql" | "replication" | "mdbuser" | "127.0.0.1" | 33 | null | "mdbdb" + "address=(host=mdb.host)(port=3306)(user=otheruser)(password=PW)/mdbdb?user=wrong&password=PW" | null | "mysql:replication://127.0.0.1:33" | "mysql" | "replication" | "mdbuser" | "127.0.0.1" | 33 | null | "mdbdb" "jdbc:mysql:replication://address=(HOST=mdb.host)," + - "address=(host=anotherhost)(port=3306)(user=wrong)(password=PW)/mdbdb?user=mdbuser&password=PW" | null | "mysql" | "replication" | "mdbuser" | "mdb.host" | 3306 | null | "mdbdb" + "address=(host=anotherhost)(port=3306)(user=wrong)(password=PW)/mdbdb?user=mdbuser&password=PW" | null | "mysql:replication://mdb.host:3306" | "mysql" | "replication" | "mdbuser" | "mdb.host" | 3306 | null | "mdbdb" //https://docs.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url - "jdbc:microsoft:sqlserver://;" | null | "sqlserver" | null | null | "localhost" | 1433 | null | null - "jdbc:microsoft:sqlserver://;" | stdProps | "sqlserver" | null | "stdUserName" | "stdServerName" | 9999 | null | "stdDatabaseName" - "jdbc:sqlserver://ss.host\\ssinstance:44;databaseName=ssdb;user=ssuser;password=pw" | null | "sqlserver" | null | "ssuser" | "ss.host" | 44 | "ssinstance" | "ssdb" - "jdbc:sqlserver://;serverName=ss.host\\ssinstance:44;DatabaseName=;" | null | "sqlserver" | null | null | "ss.host" | 44 | "ssinstance" | null - "jdbc:sqlserver://ss.host;serverName=althost;DatabaseName=ssdb;" | null | "sqlserver" | null | null | "ss.host" | 1433 | null | "ssdb" - "jdbc:microsoft:sqlserver://ss.host:44;DatabaseName=ssdb;user=ssuser;password=pw;user=ssuser2;" | null | "sqlserver" | null | "ssuser" | "ss.host" | 44 | null | "ssdb" + "jdbc:microsoft:sqlserver://;" | null | "sqlserver://localhost:1433" | "sqlserver" | null | null | "localhost" | 1433 | null | null + "jdbc:microsoft:sqlserver://;" | stdProps | "sqlserver://stdServerName:9999" | "sqlserver" | null | "stdUserName" | "stdServerName" | 9999 | null | "stdDatabaseName" + "jdbc:sqlserver://ss.host\\ssinstance:44;databaseName=ssdb;user=ssuser;password=pw" | null | "sqlserver://ss.host:44" | "sqlserver" | null | "ssuser" | "ss.host" | 44 | "ssinstance" | "ssdb" + "jdbc:sqlserver://;serverName=ss.host\\ssinstance:44;DatabaseName=;" | null | "sqlserver://ss.host:44" | "sqlserver" | null | null | "ss.host" | 44 | "ssinstance" | null + "jdbc:sqlserver://ss.host;serverName=althost;DatabaseName=ssdb;" | null | "sqlserver://ss.host:1433" | "sqlserver" | null | null | "ss.host" | 1433 | null | "ssdb" + "jdbc:microsoft:sqlserver://ss.host:44;DatabaseName=ssdb;user=ssuser;password=pw;user=ssuser2;" | null | "sqlserver://ss.host:44" | "sqlserver" | null | "ssuser" | "ss.host" | 44 | null | "ssdb" // https://docs.oracle.com/cd/B28359_01/java.111/b31224/urls.htm // https://docs.oracle.com/cd/B28359_01/java.111/b31224/jdbcthin.htm - "jdbc:oracle:thin:orcluser/PW@localhost:55:orclsn" | null | "oracle" | "thin" | "orcluser" | "localhost" | 55 | "orclsn" | null - "jdbc:oracle:thin:orcluser/PW@//orcl.host:55/orclsn" | null | "oracle" | "thin" | "orcluser" | "orcl.host" | 55 | "orclsn" | null - "jdbc:oracle:thin:orcluser/PW@127.0.0.1:orclsn" | null | "oracle" | "thin" | "orcluser" | "127.0.0.1" | 1521 | "orclsn" | null - "jdbc:oracle:thin:orcluser/PW@//orcl.host/orclsn" | null | "oracle" | "thin" | "orcluser" | "orcl.host" | 1521 | "orclsn" | null - "jdbc:oracle:thin:@//orcl.host:55/orclsn" | null | "oracle" | "thin" | null | "orcl.host" | 55 | "orclsn" | null - "jdbc:oracle:thin:@ldap://orcl.host:55/some,cn=OracleContext,dc=com" | null | "oracle" | "thin" | null | "orcl.host" | 55 | "some,cn=oraclecontext,dc=com" | null - "jdbc:oracle:thin:127.0.0.1:orclsn" | null | "oracle" | "thin" | null | "127.0.0.1" | 1521 | "orclsn" | null - "jdbc:oracle:thin:orcl.host:orclsn" | stdProps | "oracle" | "thin" | "stdUserName" | "orcl.host" | 9999 | "orclsn" | "stdDatabaseName" + "jdbc:oracle:thin:orcluser/PW@localhost:55:orclsn" | null | "oracle:thin://localhost:55" | "oracle" | "thin" | "orcluser" | "localhost" | 55 | "orclsn" | null + "jdbc:oracle:thin:orcluser/PW@//orcl.host:55/orclsn" | null | "oracle:thin://orcl.host:55" | "oracle" | "thin" | "orcluser" | "orcl.host" | 55 | "orclsn" | null + "jdbc:oracle:thin:orcluser/PW@127.0.0.1:orclsn" | null | "oracle:thin://127.0.0.1:1521" | "oracle" | "thin" | "orcluser" | "127.0.0.1" | 1521 | "orclsn" | null + "jdbc:oracle:thin:orcluser/PW@//orcl.host/orclsn" | null | "oracle:thin://orcl.host:1521" | "oracle" | "thin" | "orcluser" | "orcl.host" | 1521 | "orclsn" | null + "jdbc:oracle:thin:@//orcl.host:55/orclsn" | null | "oracle:thin://orcl.host:55" | "oracle" | "thin" | null | "orcl.host" | 55 | "orclsn" | null + "jdbc:oracle:thin:@ldap://orcl.host:55/some,cn=OracleContext,dc=com" | null | "oracle:thin://orcl.host:55" | "oracle" | "thin" | null | "orcl.host" | 55 | "some,cn=oraclecontext,dc=com" | null + "jdbc:oracle:thin:127.0.0.1:orclsn" | null | "oracle:thin://127.0.0.1:1521" | "oracle" | "thin" | null | "127.0.0.1" | 1521 | "orclsn" | null + "jdbc:oracle:thin:orcl.host:orclsn" | stdProps | "oracle:thin://orcl.host:9999" | "oracle" | "thin" | "stdUserName" | "orcl.host" | 9999 | "orclsn" | "stdDatabaseName" "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST= 127.0.0.1 )(POR T= 666))" + - "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orclsn)))" | null | "oracle" | "thin" | null | "127.0.0.1" | 1521 | "orclsn" | null - // https://docs.oracle.com/cd/B28359_01/java.111/b31224/instclnt.htm - "jdbc:oracle:drivertype:orcluser/PW@orcl.host:55/orclsn" | null | "oracle" | "drivertype" | "orcluser" | "orcl.host" | 55 | "orclsn" | null - "jdbc:oracle:oci8:@" | null | "oracle" | "oci8" | null | null | 1521 | null | null - "jdbc:oracle:oci8:@" | stdProps | "oracle" | "oci8" | "stdUserName" | "stdServerName" | 9999 | null | "stdDatabaseName" - "jdbc:oracle:oci8:@orclsn" | null | "oracle" | "oci8" | null | null | 1521 | "orclsn" | null + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orclsn)))" | null | "oracle:thin://127.0.0.1:1521" | "oracle" | "thin" | null | "127.0.0.1" | 1521 | "orclsn" | null + // https://docs.oracle.com/cd/B28359_01/java.111/b31224/instclnt.htm + "jdbc:oracle:drivertype:orcluser/PW@orcl.host:55/orclsn" | null | "oracle:drivertype://orcl.host:55" | "oracle" | "drivertype" | "orcluser" | "orcl.host" | 55 | "orclsn" | null + "jdbc:oracle:oci8:@" | null | "oracle:oci8:" | "oracle" | "oci8" | null | null | 1521 | null | null + "jdbc:oracle:oci8:@" | stdProps | "oracle:oci8://stdServerName:9999" | "oracle" | "oci8" | "stdUserName" | "stdServerName" | 9999 | null | "stdDatabaseName" + "jdbc:oracle:oci8:@orclsn" | null | "oracle:oci8:" | "oracle" | "oci8" | null | null | 1521 | "orclsn" | null "jdbc:oracle:oci:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)( HOST = orcl.host )" + - "( PORT = 55 ))(CONNECT_DATA=(SERVICE_NAME =orclsn )))" | null | "oracle" | "oci" | null | "orcl.host" | 55 | "orclsn" | null + "( PORT = 55 ))(CONNECT_DATA=(SERVICE_NAME =orclsn )))" | null | "oracle:oci://orcl.host:55" | "oracle" | "oci" | null | "orcl.host" | 55 | "orclsn" | null - // https://www.ibm.com/support/knowledgecenter/en/SSEPEK_10.0.0/java/src/tpc/imjcc_tjvjcccn.html - // https://www.ibm.com/support/knowledgecenter/en/SSEPGG_10.5.0/com.ibm.db2.luw.apdv.java.doc/src/tpc/imjcc_r0052342.html - "jdbc:db2://db2.host" | null | "db2" | null | null | "db2.host" | 50000 | null | null - "jdbc:db2://db2.host" | stdProps | "db2" | null | "stdUserName" | "db2.host" | 9999 | null | "stdDatabaseName" - "jdbc:db2://db2.host:77/db2db:user=db2user;password=PW;" | null | "db2" | null | "db2user" | "db2.host" | 77 | "db2db" | null - "jdbc:db2://db2.host:77/db2db:user=db2user;password=PW;" | stdProps | "db2" | null | "db2user" | "db2.host" | 77 | "db2db" | "stdDatabaseName" - "jdbc:as400://ashost:66/asdb:user=asuser;password=PW;" | null | "as400" | null | "asuser" | "ashost" | 66 | "asdb" | null + // https://www.ibm.com/support/knowledgecenter/en/SSEPEK_10.0.0/java/src/tpc/imjcc_tjvjcccn.html + // https://www.ibm.com/support/knowledgecenter/en/SSEPGG_10.5.0/com.ibm.db2.luw.apdv.java.doc/src /tpc/imjcc_r0052342.html + "jdbc:db2://db2.host" | null | "db2://db2.host:50000" | "db2" | null | null | "db2.host" | 50000 | null | null + "jdbc:db2://db2.host" | stdProps | "db2://db2.host:9999" | "db2" | null | "stdUserName" | "db2.host" | 9999 | null | "stdDatabaseName" + "jdbc:db2://db2.host:77/db2db:user=db2user;password=PW;" | null | "db2://db2.host:77" | "db2" | null | "db2user" | "db2.host" | 77 | "db2db" | null + "jdbc:db2://db2.host:77/db2db:user=db2user;password=PW;" | stdProps | "db2://db2.host:77" | "db2" | null | "db2user" | "db2.host" | 77 | "db2db" | "stdDatabaseName" + "jdbc:as400://ashost:66/asdb:user=asuser;password=PW;" | null | "as400://ashost:66" | "as400" | null | "asuser" | "ashost" | 66 | "asdb" | null // https://help.sap.com/viewer/0eec0d68141541d1b07893a39944924e/2.0.03/en-US/ff15928cf5594d78b841fbbe649f04b4.html - "jdbc:sap://sap.host" | null | "sap" | null | null | "sap.host" | null | null | null - "jdbc:sap://sap.host" | stdProps | "sap" | null | "stdUserName" | "sap.host" | 9999 | null | "stdDatabaseName" - "jdbc:sap://sap.host:88/?databaseName=sapdb&user=sapuser&password=PW" | null | "sap" | null | "sapuser" | "sap.host" | 88 | null | "sapdb" + "jdbc:sap://sap.host" | null | "sap://sap.host" | "sap" | null | null | "sap.host" | null | null | null + "jdbc:sap://sap.host" | stdProps | "sap://sap.host:9999" | "sap" | null | "stdUserName" | "sap.host" | 9999 | null | "stdDatabaseName" + "jdbc:sap://sap.host:88/?databaseName=sapdb&user=sapuser&password=PW" | null | "sap://sap.host:88" | "sap" | null | "sapuser" | "sap.host" | 88 | null | "sapdb" // TODO: -// "jdbc:informix-sqli://infxhost:99/infxdb:INFORMIXSERVER=infxsn;user=infxuser;password=PW" | null | "informix-sqli" | null | "infxuser" | "infxhost" | 99 | "infxdb"| null -// "jdbc:informix-direct://infxdb:999;user=infxuser;password=PW" | null | "informix-direct" | null | "infxuser" | "infxhost" | 999 | "infxdb"| null +// "jdbc:informix-sqli://infxhost:99/infxdb:INFORMIXSERVER=infxsn;user=infxuser;password=PW" | null | "informix-sqli" | null | "infxuser" | "infxhost" | 99 | "infxdb"| null +// "jdbc:informix-direct://infxdb:999;user=infxuser;password=PW" | null | "informix-direct" | null | "infxuser" | "infxhost" | 999 | "infxdb"| null // http://www.h2database.com/html/features.html#database_url - "jdbc:h2:mem:" | null | "h2" | "mem" | null | null | null | null | null - "jdbc:h2:mem:" | stdProps | "h2" | "mem" | "stdUserName" | "stdServerName" | 9999 | null | "stdDatabaseName" - "jdbc:h2:mem:h2db" | null | "h2" | "mem" | null | null | null | "h2db" | null - "jdbc:h2:tcp://h2.host:111/path/h2db;user=h2user;password=PW" | null | "h2" | "tcp" | "h2user" | "h2.host" | 111 | "path/h2db" | null - "jdbc:h2:ssl://h2.host:111/path/h2db;user=h2user;password=PW" | null | "h2" | "ssl" | "h2user" | "h2.host" | 111 | "path/h2db" | null - "jdbc:h2:/data/h2file" | null | "h2" | "file" | null | null | null | "/data/h2file" | null - "jdbc:h2:file:~/h2file;USER=h2user;PASSWORD=PW" | null | "h2" | "file" | null | null | null | "~/h2file" | null - "jdbc:h2:file:/data/h2file" | null | "h2" | "file" | null | null | null | "/data/h2file" | null - "jdbc:h2:file:C:/data/h2file" | null | "h2" | "file" | null | null | null | "c:/data/h2file" | null - "jdbc:h2:zip:~/db.zip!/h2zip" | null | "h2" | "zip" | null | null | null | "~/db.zip!/h2zip" | null + "jdbc:h2:mem:" | null | "h2:mem:" | "h2" | "mem" | null | null | null | null | null + "jdbc:h2:mem:" | stdProps | "h2:mem:" | "h2" | "mem" | "stdUserName" | null | null | null | "stdDatabaseName" + "jdbc:h2:mem:h2db" | null | "h2:mem:" | "h2" | "mem" | null | null | null | "h2db" | null + "jdbc:h2:tcp://h2.host:111/path/h2db;user=h2user;password=PW" | null | "h2:tcp://h2.host:111" | "h2" | "tcp" | "h2user" | "h2.host" | 111 | "path/h2db" | null + "jdbc:h2:ssl://h2.host:111/path/h2db;user=h2user;password=PW" | null | "h2:ssl://h2.host:111" | "h2" | "ssl" | "h2user" | "h2.host" | 111 | "path/h2db" | null + "jdbc:h2:/data/h2file" | null | "h2:file:" | "h2" | "file" | null | null | null | "/data/h2file" | null + "jdbc:h2:file:~/h2file;USER=h2user;PASSWORD=PW" | null | "h2:file:" | "h2" | "file" | null | null | null | "~/h2file" | null + "jdbc:h2:file:/data/h2file" | null | "h2:file:" | "h2" | "file" | null | null | null | "/data/h2file" | null + "jdbc:h2:file:C:/data/h2file" | null | "h2:file:" | "h2" | "file" | null | null | null | "c:/data/h2file" | null + "jdbc:h2:zip:~/db.zip!/h2zip" | null | "h2:zip:" | "h2" | "zip" | null | null | null | "~/db.zip!/h2zip" | null // http://hsqldb.org/doc/2.0/guide/dbproperties-chapt.html - "jdbc:hsqldb:hsdb" | null | "hsqldb" | "mem" | "SA" | null | null | "hsdb" | null - "jdbc:hsqldb:hsdb" | stdProps | "hsqldb" | "mem" | "stdUserName" | "stdServerName" | 9999 | "hsdb" | "stdDatabaseName" - "jdbc:hsqldb:mem:hsdb" | null | "hsqldb" | "mem" | "SA" | null | null | "hsdb" | null - "jdbc:hsqldb:file:hsdb" | null | "hsqldb" | "file" | "SA" | null | null | "hsdb" | null - "jdbc:hsqldb:file:/loc/hsdb" | null | "hsqldb" | "file" | "SA" | null | null | "/loc/hsdb" | null - "jdbc:hsqldb:file:C:/hsdb" | null | "hsqldb" | "file" | "SA" | null | null | "c:/hsdb" | null - "jdbc:hsqldb:res:hsdb" | null | "hsqldb" | "res" | "SA" | null | null | "hsdb" | null - "jdbc:hsqldb:res:/cp/hsdb" | null | "hsqldb" | "res" | "SA" | null | null | "/cp/hsdb" | null - "jdbc:hsqldb:hsql://hs.host:333/hsdb" | null | "hsqldb" | "hsql" | "SA" | "hs.host" | 333 | "hsdb" | null - "jdbc:hsqldb:hsqls://hs.host/hsdb" | null | "hsqldb" | "hsqls" | "SA" | "hs.host" | 9001 | "hsdb" | null - "jdbc:hsqldb:http://hs.host" | null | "hsqldb" | "http" | "SA" | "hs.host" | 80 | null | null - "jdbc:hsqldb:http://hs.host:333/hsdb" | null | "hsqldb" | "http" | "SA" | "hs.host" | 333 | "hsdb" | null - "jdbc:hsqldb:https://127.0.0.1/hsdb" | null | "hsqldb" | "https" | "SA" | "127.0.0.1" | 443 | "hsdb" | null + "jdbc:hsqldb:hsdb" | null | "hsqldb:mem:" | "hsqldb" | "mem" | "SA" | null | null | "hsdb" | null + "jdbc:hsqldb:hsdb" | stdProps | "hsqldb:mem:" | "hsqldb" | "mem" | "stdUserName" | null | null | "hsdb" | "stdDatabaseName" + "jdbc:hsqldb:mem:hsdb" | null | "hsqldb:mem:" | "hsqldb" | "mem" | "SA" | null | null | "hsdb" | null + "jdbc:hsqldb:file:hsdb" | null | "hsqldb:file:" | "hsqldb" | "file" | "SA" | null | null | "hsdb" | null + "jdbc:hsqldb:file:/loc/hsdb" | null | "hsqldb:file:" | "hsqldb" | "file" | "SA" | null | null | "/loc/hsdb" | null + "jdbc:hsqldb:file:C:/hsdb" | null | "hsqldb:file:" | "hsqldb" | "file" | "SA" | null | null | "c:/hsdb" | null + "jdbc:hsqldb:res:hsdb" | null | "hsqldb:res:" | "hsqldb" | "res" | "SA" | null | null | "hsdb" | null + "jdbc:hsqldb:res:/cp/hsdb" | null | "hsqldb:res:" | "hsqldb" | "res" | "SA" | null | null | "/cp/hsdb" | null + "jdbc:hsqldb:hsql://hs.host:333/hsdb" | null | "hsqldb:hsql://hs.host:333" | "hsqldb" | "hsql" | "SA" | "hs.host" | 333 | "hsdb" | null + "jdbc:hsqldb:hsqls://hs.host/hsdb" | null | "hsqldb:hsqls://hs.host:9001" | "hsqldb" | "hsqls" | "SA" | "hs.host" | 9001 | "hsdb" | null + "jdbc:hsqldb:http://hs.host" | null | "hsqldb:http://hs.host:80" | "hsqldb" | "http" | "SA" | "hs.host" | 80 | null | null + "jdbc:hsqldb:http://hs.host:333/hsdb" | null | "hsqldb:http://hs.host:333" | "hsqldb" | "http" | "SA" | "hs.host" | 333 | "hsdb" | null + "jdbc:hsqldb:https://127.0.0.1/hsdb" | null | "hsqldb:https://127.0.0.1:443" | "hsqldb" | "https" | "SA" | "127.0.0.1" | 443 | "hsdb" | null // https://db.apache.org/derby/papers/DerbyClientSpec.html#Connection+URL+Format // https://db.apache.org/derby/docs/10.8/devguide/cdevdvlp34964.html - "jdbc:derby:derbydb" | null | "derby" | "directory" | "APP" | null | null | "derbydb" | null - "jdbc:derby:derbydb" | stdProps | "derby" | "directory" | "stdUserName" | "stdServerName" | 9999 | "derbydb" | "stdDatabaseName" - "jdbc:derby:derbydb;user=derbyuser;password=pw" | null | "derby" | "directory" | "derbyuser" | null | null | "derbydb" | null - "jdbc:derby:memory:derbydb" | null | "derby" | "memory" | "APP" | null | null | "derbydb" | null - "jdbc:derby:memory:;databaseName=derbydb" | null | "derby" | "memory" | "APP" | null | null | null | "derbydb" - "jdbc:derby:memory:derbydb;databaseName=altdb" | null | "derby" | "memory" | "APP" | null | null | "derbydb" | "altdb" - "jdbc:derby:memory:derbydb;user=derbyuser;password=pw" | null | "derby" | "memory" | "derbyuser" | null | null | "derbydb" | null - "jdbc:derby://derby.host:222/memory:derbydb;create=true" | null | "derby" | "network" | "APP" | "derby.host" | 222 | "derbydb" | null - "jdbc:derby://derby.host/memory:derbydb;create=true;user=derbyuser;password=pw" | null | "derby" | "network" | "derbyuser" | "derby.host" | 1527 | "derbydb" | null - "jdbc:derby://127.0.0.1:1527/memory:derbydb;create=true;user=derbyuser;password=pw" | null | "derby" | "network" | "derbyuser" | "127.0.0.1" | 1527 | "derbydb" | null - "jdbc:derby:directory:derbydb;user=derbyuser;password=pw" | null | "derby" | "directory" | "derbyuser" | null | null | "derbydb" | null - "jdbc:derby:classpath:/some/derbydb;user=derbyuser;password=pw" | null | "derby" | "classpath" | "derbyuser" | null | null | "/some/derbydb" | null - "jdbc:derby:jar:/derbydb;user=derbyuser;password=pw" | null | "derby" | "jar" | "derbyuser" | null | null | "/derbydb" | null - "jdbc:derby:jar:(~/path/to/db.jar)/other/derbydb;user=derbyuser;password=pw" | null | "derby" | "jar" | "derbyuser" | null | null | "(~/path/to/db.jar)/other/derbydb" | null + "jdbc:derby:derbydb" | null | "derby:directory:" | "derby" | "directory" | "APP" | null | null | "derbydb" | null + "jdbc:derby:derbydb" | stdProps | "derby:directory:" | "derby" | "directory" | "stdUserName" | null | null | "derbydb" | "stdDatabaseName" + "jdbc:derby:derbydb;user=derbyuser;password=pw" | null | "derby:directory:" | "derby" | "directory" | "derbyuser" | null | null | "derbydb" | null + "jdbc:derby:memory:derbydb" | null | "derby:memory:" | "derby" | "memory" | "APP" | null | null | "derbydb" | null + "jdbc:derby:memory:;databaseName=derbydb" | null | "derby:memory:" | "derby" | "memory" | "APP" | null | null | null | "derbydb" + "jdbc:derby:memory:derbydb;databaseName=altdb" | null | "derby:memory:" | "derby" | "memory" | "APP" | null | null | "derbydb" | "altdb" + "jdbc:derby:memory:derbydb;user=derbyuser;password=pw" | null | "derby:memory:" | "derby" | "memory" | "derbyuser" | null | null | "derbydb" | null + "jdbc:derby://derby.host:222/memory:derbydb;create=true" | null | "derby:network://derby.host:222" | "derby" | "network" | "APP" | "derby.host" | 222 | "derbydb" | null + "jdbc:derby://derby.host/memory:derbydb;create=true;user=derbyuser;password=pw" | null | "derby:network://derby.host:1527" | "derby" | "network" | "derbyuser" | "derby.host" | 1527 | "derbydb" | null + "jdbc:derby://127.0.0.1:1527/memory:derbydb;create=true;user=derbyuser;password=pw" | null | "derby:network://127.0.0.1:1527" | "derby" | "network" | "derbyuser" | "127.0.0.1" | 1527 | "derbydb" | null + "jdbc:derby:directory:derbydb;user=derbyuser;password=pw" | null | "derby:directory:" | "derby" | "directory" | "derbyuser" | null | null | "derbydb" | null + "jdbc:derby:classpath:/some/derbydb;user=derbyuser;password=pw" | null | "derby:classpath:" | "derby" | "classpath" | "derbyuser" | null | null | "/some/derbydb" | null + "jdbc:derby:jar:/derbydb;user=derbyuser;password=pw" | null | "derby:jar:" | "derby" | "jar" | "derbyuser" | null | null | "/derbydb" | null + "jdbc:derby:jar:(~/path/to/db.jar)/other/derbydb;user=derbyuser;password=pw" | null | "derby:jar:" | "derby" | "jar" | "derbyuser" | null | null | "(~/path/to/db.jar)/other/derbydb" | null - expected = new DBInfo.Builder().type(type).subtype(subtype).user(user).instance(instance).db(db).host(host).port(port).build() + expected = new DBInfo.Builder().type(type).subtype(subtype).user(user).instance(instance).db(db).host(host).port(port).shortUrl(shortUrl).build() } } diff --git a/instrumentation/jdbc/src/test/groovy/JDBCInstrumentationTest.groovy b/instrumentation/jdbc/src/test/groovy/JDBCInstrumentationTest.groovy index b7c14481d7..5e650f9e5d 100644 --- a/instrumentation/jdbc/src/test/groovy/JDBCInstrumentationTest.groovy +++ b/instrumentation/jdbc/src/test/groovy/JDBCInstrumentationTest.groovy @@ -205,6 +205,7 @@ class JDBCInstrumentationTest extends AgentTestRunner { "$Tags.DB_USER" username } "$Tags.DB_STATEMENT" query + "$Tags.DB_URL" url "span.origin.type" String } } @@ -216,22 +217,22 @@ class JDBCInstrumentationTest extends AgentTestRunner { connection.close() where: - driver | connection | username | renameService | query - "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | false | "SELECT 3" - "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | false | "SELECT 3 FROM SYSIBM.SYSDUMMY1" - "hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), null) | "SA" | false | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" - "h2" | new Driver().connect(jdbcUrls.get("h2"), connectionProps) | null | true | "SELECT 3" - "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), connectionProps) | "APP" | true | "SELECT 3 FROM SYSIBM.SYSDUMMY1" - "hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), connectionProps) | "SA" | true | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" - "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | false | "SELECT 3" - "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | false | "SELECT 3 FROM SYSIBM.SYSDUMMY1" - "hsqldb" | cpDatasources.get("tomcat").get("hsqldb").getConnection() | "SA" | true | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" - "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | false | "SELECT 3" - "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | true | "SELECT 3 FROM SYSIBM.SYSDUMMY1" - "hsqldb" | cpDatasources.get("hikari").get("hsqldb").getConnection() | "SA" | false | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" - "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | true | "SELECT 3" - "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | false | "SELECT 3 FROM SYSIBM.SYSDUMMY1" - "hsqldb" | cpDatasources.get("c3p0").get("hsqldb").getConnection() | "SA" | false | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" + driver | connection | username | renameService | query | url + "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | false | "SELECT 3" | "h2:mem:" + "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | false | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" + "hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), null) | "SA" | false | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:" + "h2" | new Driver().connect(jdbcUrls.get("h2"), connectionProps) | null | true | "SELECT 3" | "h2:mem:" + "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), connectionProps) | "APP" | true | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" + "hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), connectionProps) | "SA" | true | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:" + "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | false | "SELECT 3" | "h2:mem:" + "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | false | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" + "hsqldb" | cpDatasources.get("tomcat").get("hsqldb").getConnection() | "SA" | true | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:" + "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | false | "SELECT 3" | "h2:mem:" + "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | true | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" + "hsqldb" | cpDatasources.get("hikari").get("hsqldb").getConnection() | "SA" | false | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:" + "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | true | "SELECT 3" | "h2:mem:" + "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | false | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" + "hsqldb" | cpDatasources.get("c3p0").get("hsqldb").getConnection() | "SA" | false | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:" } @Unroll @@ -263,6 +264,7 @@ class JDBCInstrumentationTest extends AgentTestRunner { "$Tags.DB_USER" username } "$Tags.DB_STATEMENT" query + "$Tags.DB_URL" url "span.origin.type" String } } @@ -274,15 +276,15 @@ class JDBCInstrumentationTest extends AgentTestRunner { connection.close() where: - driver | connection | username | query - "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3" - "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" - "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" - "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" - "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" - "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" - "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" - "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" + driver | connection | username | query | url + "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3" | "h2:mem:" + "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" + "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" | "h2:mem:" + "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" + "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" | "h2:mem:" + "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" + "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" | "h2:mem:" + "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" } @Unroll @@ -313,6 +315,7 @@ class JDBCInstrumentationTest extends AgentTestRunner { "$Tags.DB_USER" username } "$Tags.DB_STATEMENT" query + "$Tags.DB_URL" url "span.origin.type" String } } @@ -324,15 +327,15 @@ class JDBCInstrumentationTest extends AgentTestRunner { connection.close() where: - driver | connection | username | query - "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3" - "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" - "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" - "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" - "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" - "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" - "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" - "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" + driver | connection | username | query | url + "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3" | "h2:mem:" + "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" + "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" | "h2:mem:" + "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" + "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" | "h2:mem:" + "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" + "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" | "h2:mem:" + "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" } @Unroll @@ -363,6 +366,7 @@ class JDBCInstrumentationTest extends AgentTestRunner { "$Tags.DB_USER" username } "$Tags.DB_STATEMENT" query + "$Tags.DB_URL" url "span.origin.type" String } } @@ -374,15 +378,15 @@ class JDBCInstrumentationTest extends AgentTestRunner { connection.close() where: - driver | connection | username | query - "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3" - "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" - "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" - "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" - "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" - "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" - "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" - "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" + driver | connection | username | query | url + "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3" | "h2:mem:" + "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" + "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" | "h2:mem:" + "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" + "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" | "h2:mem:" + "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" + "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" | "h2:mem:" + "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" } @Unroll @@ -413,6 +417,7 @@ class JDBCInstrumentationTest extends AgentTestRunner { "$Tags.DB_USER" username } "$Tags.DB_STATEMENT" query + "$Tags.DB_URL" url "span.origin.type" String } } @@ -424,19 +429,19 @@ class JDBCInstrumentationTest extends AgentTestRunner { connection.close() where: - driver | connection | username | query - "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "CREATE TABLE S_H2 (id INTEGER not NULL, PRIMARY KEY ( id ))" - "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "CREATE TABLE S_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))" - "hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), null) | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB (id INTEGER not NULL, PRIMARY KEY ( id ))" - "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "CREATE TABLE S_H2_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" - "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "CREATE TABLE S_DERBY_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" - "hsqldb" | cpDatasources.get("tomcat").get("hsqldb").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" - "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "CREATE TABLE S_H2_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" - "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "CREATE TABLE S_DERBY_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" - "hsqldb" | cpDatasources.get("hikari").get("hsqldb").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" - "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "CREATE TABLE S_H2_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" - "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "CREATE TABLE S_DERBY_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" - "hsqldb" | cpDatasources.get("c3p0").get("hsqldb").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" + driver | 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:" } @Unroll @@ -466,6 +471,7 @@ class JDBCInstrumentationTest extends AgentTestRunner { "$Tags.DB_USER" username } "$Tags.DB_STATEMENT" query + "$Tags.DB_URL" url "span.origin.type" String } } @@ -477,15 +483,15 @@ class JDBCInstrumentationTest extends AgentTestRunner { connection.close() where: - driver | connection | username | query - "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "CREATE TABLE PS_H2 (id INTEGER not NULL, PRIMARY KEY ( id ))" - "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "CREATE TABLE PS_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))" - "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "CREATE TABLE PS_H2_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" - "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "CREATE TABLE PS_DERBY_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" - "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "CREATE TABLE PS_H2_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" - "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "CREATE TABLE PS_DERBY_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" - "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "CREATE TABLE PS_H2_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" - "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "CREATE TABLE PS_DERBY_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" + driver | 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:" } @Unroll @@ -497,7 +503,7 @@ class JDBCInstrumentationTest extends AgentTestRunner { try { connection = new TestConnection(true) } catch (Exception e) { - connection = driverClass.connect(url, null) + connection = driverClass.connect(jdbcUrl, null) } Statement statement = null @@ -535,6 +541,7 @@ class JDBCInstrumentationTest extends AgentTestRunner { "$Tags.DB_USER" username } "$Tags.DB_STATEMENT" query + "$Tags.DB_URL" url "span.origin.type" String } } @@ -550,11 +557,11 @@ class JDBCInstrumentationTest extends AgentTestRunner { } where: - prepareStatement | driver | driverClass | url | username | query - true | "h2" | new Driver() | "jdbc:h2:mem:" + dbName | null | "SELECT 3;" - true | "derby" | new EmbeddedDriver() | "jdbc:derby:memory:" + dbName + ";create=true" | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" - false | "h2" | new Driver() | "jdbc:h2:mem:" + dbName | null | "SELECT 3;" - false | "derby" | new EmbeddedDriver() | "jdbc:derby:memory:" + dbName + ";create=true" | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" + prepareStatement | driver | driverClass | jdbcUrl | username | query | url + true | "h2" | new Driver() | "jdbc:h2:mem:" + dbName | null | "SELECT 3;" | "h2:mem:" + true | "derby" | new EmbeddedDriver() | "jdbc:derby:memory:" + dbName + ";create=true" | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" + false | "h2" | new Driver() | "jdbc:h2:mem:" + dbName | null | "SELECT 3;" | "h2:mem:" + false | "derby" | new EmbeddedDriver() | "jdbc:derby:memory:" + dbName + ";create=true" | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "derby:memory:" } def "calling #datasource.class.simpleName getConnection generates a span when under existing trace"() { @@ -638,6 +645,7 @@ class JDBCInstrumentationTest extends AgentTestRunner { "$Tags.COMPONENT" "java-jdbc-statement" "$Tags.DB_TYPE" "sql" "$Tags.DB_STATEMENT" query + "$Tags.DB_URL" "testdb://localhost" "span.origin.type" TestStatement.name } } @@ -702,6 +710,7 @@ class JDBCInstrumentationTest extends AgentTestRunner { "$Tags.DB_INSTANCE" dbName.toLowerCase() "$Tags.DB_USER" "SA" "$Tags.DB_STATEMENT" query + "$Tags.DB_URL" "hsqldb:mem:" "span.origin.type" String } } @@ -719,6 +728,7 @@ class JDBCInstrumentationTest extends AgentTestRunner { "$Tags.DB_INSTANCE" dbName.toLowerCase() "$Tags.DB_USER" "SA" "$Tags.DB_STATEMENT" query + "$Tags.DB_URL" "hsqldb:mem:" "span.origin.type" String } } diff --git a/instrumentation/spring-data-1.8/src/test/groovy/SpringJpaTest.groovy b/instrumentation/spring-data-1.8/src/test/groovy/SpringJpaTest.groovy index 29c4662b36..c28c82500b 100644 --- a/instrumentation/spring-data-1.8/src/test/groovy/SpringJpaTest.groovy +++ b/instrumentation/spring-data-1.8/src/test/groovy/SpringJpaTest.groovy @@ -88,6 +88,7 @@ class SpringJpaTest extends AgentTestRunner { "$Tags.DB_INSTANCE" "test" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^select / + "$Tags.DB_URL" "hsqldb:mem:" "span.origin.type" "org.hsqldb.jdbc.JDBCPreparedStatement" } } @@ -122,6 +123,7 @@ class SpringJpaTest extends AgentTestRunner { "$Tags.DB_INSTANCE" "test" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^insert / + "$Tags.DB_URL" "hsqldb:mem:" "span.origin.type" "org.hsqldb.jdbc.JDBCPreparedStatement" } } @@ -156,6 +158,7 @@ class SpringJpaTest extends AgentTestRunner { "$Tags.DB_INSTANCE" "test" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^select / + "$Tags.DB_URL" "hsqldb:mem:" "span.origin.type" "org.hsqldb.jdbc.JDBCPreparedStatement" } } @@ -170,6 +173,7 @@ class SpringJpaTest extends AgentTestRunner { "$Tags.DB_INSTANCE" "test" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^update / + "$Tags.DB_URL" "hsqldb:mem:" "span.origin.type" "org.hsqldb.jdbc.JDBCPreparedStatement" } } @@ -202,6 +206,7 @@ class SpringJpaTest extends AgentTestRunner { "$Tags.DB_INSTANCE" "test" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^select / + "$Tags.DB_URL" "hsqldb:mem:" "span.origin.type" "org.hsqldb.jdbc.JDBCPreparedStatement" } } @@ -234,6 +239,7 @@ class SpringJpaTest extends AgentTestRunner { "$Tags.DB_INSTANCE" "test" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^select / + "$Tags.DB_URL" "hsqldb:mem:" "span.origin.type" "org.hsqldb.jdbc.JDBCPreparedStatement" } } @@ -248,6 +254,7 @@ class SpringJpaTest extends AgentTestRunner { "$Tags.DB_INSTANCE" "test" "$Tags.DB_USER" "sa" "$Tags.DB_STATEMENT" ~/^delete / + "$Tags.DB_URL" "hsqldb:mem:" "span.origin.type" "org.hsqldb.jdbc.JDBCPreparedStatement" } }