Skip to content

Commit b92f0c0

Browse files
amarzialivandonr
andauthored
Add support for sybase tds jdbc driver (#8764)
* Add support for sybase tds jdbc driver * Update dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/jdbc/JDBCConnectionUrlParser.java Co-authored-by: Raphaël Vandon <[email protected]> * add sybase callable stmt * Remove null check since creates sides effects * Add sybase jdbc2 alias --------- Co-authored-by: Raphaël Vandon <[email protected]>
1 parent c329d08 commit b92f0c0

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/jdbc/JDBCConnectionUrlParser.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
4242
}
4343

4444
String path = uri.getPath();
45+
4546
if (path.startsWith("/")) {
4647
path = path.substring(1);
4748
}
@@ -795,7 +796,23 @@ DBInfo.Builder doParse(String jdbcUrl, DBInfo.Builder builder) {
795796
}
796797
return GENERIC_URL_LIKE.doParse(url, builder);
797798
}
798-
};
799+
},
800+
// https://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc01776.1601/doc/html/san1357754914053.html
801+
// Sybase TDS
802+
SYBASE_TDS("sybase") {
803+
@Override
804+
DBInfo.Builder doParse(String jdbcUrl, DBInfo.Builder builder) {
805+
if (jdbcUrl.startsWith("sybase:tds:")) {
806+
// that uri is opaque so we need to adjust it in order to be parsed with the classical
807+
// hierarchical way
808+
return GENERIC_URL_LIKE
809+
.doParse("sybase://" + jdbcUrl.substring("sybase:tds:".length()), builder)
810+
.subtype("tds");
811+
}
812+
return GENERIC_URL_LIKE.doParse(jdbcUrl, builder);
813+
}
814+
},
815+
;
799816

800817
private static final Map<String, JDBCConnectionUrlParser> typeParsers = new HashMap<>();
801818

@@ -925,6 +942,10 @@ private static void populateStandardProperties(
925942
ExceptionLogger.LOGGER.debug("Error parsing portnumber property: {}", portNumber, e);
926943
}
927944
}
945+
if (props.containsKey("servicename")) {
946+
// this property is used to specify the db to use for Sybase connection strings
947+
builder.instance((String) props.get("servicename"));
948+
}
928949

929950
if (props.containsKey("portNumber")) {
930951
final String portNumber = (String) props.get("portNumber");

dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/DefaultConnectionInstrumentation.java

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public class DefaultConnectionInstrumentation extends AbstractConnectionInstrume
4545
"com.informix.jdbc.IfmxConnection",
4646
// Intersystems IRIS
4747
"com.intersystems.jdbc.IRISConnection",
48+
// Sybase
49+
"com.sybase.jdbc2.jdbc.SybConnection",
50+
"com.sybase.jdbc4.jdbc.SybConnection",
4851
// for testing purposes
4952
"test.TestConnection"
5053
};

dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/PreparedStatementInstrumentation.java

+5
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ public final class PreparedStatementInstrumentation extends AbstractPreparedStat
122122
// Intersystems IRIS
123123
"com.intersystems.jdbc.IRISPreparedStatement",
124124
"com.intersystems.jdbc.IRISCallableStatement",
125+
// sybase
126+
"com.sybase.jdbc2.jdbc.SybPreparedStatement",
127+
"com.sybase.jdbc2.jdbc.SybCallableStatement",
128+
"com.sybase.jdbc4.jdbc.SybPreparedStatement",
129+
"com.sybase.jdbc4.jdbc.SybCallableStatement",
125130
// for testing purposes
126131
"test.TestPreparedStatement"
127132
};

dd-java-agent/instrumentation/jdbc/src/test/groovy/JDBCConnectionUrlParserTest.groovy

+3-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ class JDBCConnectionUrlParserTest extends AgentTestRunner {
204204
"jdbc:IRIS://dbhostname:1972/namespace" | null | "iris" | null | null | "dbhostname" | 1972 | null | "namespace"
205205
"jdbc:IRIS://dbhostname:1972/namespace/+myjdbc.log" | null | "iris" | null | null | "dbhostname" | 1972 | null | "namespace"
206206
"jdbc:IRIS://dbhostname:1972/namespace/::false" | null | "iris" | null | null | "dbhostname" | 1972 | null | "namespace"
207-
207+
// sybase
208+
"jdbc:sybase:Tds:dbhostname:2638?ServiceName=demo" | null | "sybase" | "tds" | null | "dbhostname" | 2638 | "demo" | null
209+
"jdbc:sybase:Tds:dbhostname:2638/dbname" | null | "sybase" | "tds" | null | "dbhostname" | 2638 | null | "dbname"
208210
expected = new DBInfo.Builder().type(type).subtype(subtype).user(user).instance(instance).db(db).host(host).port(port).build()
209211
}
210212
}

0 commit comments

Comments
 (0)