Skip to content

Commit 70e4525

Browse files
authored
Merge pull request #502 from DataDog/tyler/jdbc-errors
Better error handling for older JDBC drivers
2 parents 60738ab + e11ab12 commit 70e4525

3 files changed

Lines changed: 21 additions & 9 deletions

File tree

dd-java-agent/instrumentation/jdbc/jdbc.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ dependencies {
1818

1919
testCompile project(':dd-java-agent:testing')
2020
// jdbc unit testing
21-
testCompile group: 'com.h2database', name: 'h2', version: '1.4.197'
22-
testCompile group: 'org.apache.derby', name: 'derby', version: '10.12.1.1'
23-
testCompile group: 'org.hsqldb', name: 'hsqldb', version: '2.3.+'
21+
testCompile group: 'com.h2database', name: 'h2', version: '1.3.169' // first version jdk 1.6 compatible
22+
testCompile group: 'org.apache.derby', name: 'derby', version: '10.6.1.0'
23+
testCompile group: 'org.hsqldb', name: 'hsqldb', version: '2.0.0'
2424

2525
testCompile group: 'org.apache.tomcat', name: 'tomcat-jdbc', version: '7.0.19'
2626
// tomcat needs this to run

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,16 @@ public static Scope startSpan(@Advice.This final PreparedStatement statement) {
6262
Connection connection;
6363
try {
6464
connection = statement.getConnection();
65-
// unwrap the connection to cache the underlying actual connection and to not cache proxy
66-
// objects
67-
if (connection.isWrapperFor(Connection.class)) {
68-
connection = connection.unwrap(Connection.class);
65+
try {
66+
// unwrap the connection to cache the underlying actual connection and to not cache proxy
67+
// objects
68+
if (connection.isWrapperFor(Connection.class)) {
69+
connection = connection.unwrap(Connection.class);
70+
}
71+
} catch (final Exception e) {
72+
// perhaps wrapping isn't supported?
73+
// ex: org.h2.jdbc.JdbcConnection v1.3.175
74+
// Stick with original connection.
6975
}
7076
} catch (final Throwable e) {
7177
// Had some problem getting the connection.

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,16 @@ public static Scope startSpan(
6363
Connection connection;
6464
try {
6565
connection = statement.getConnection();
66-
if (connection.isWrapperFor(Connection.class)) {
66+
try {
6767
// unwrap the connection to cache the underlying actual connection and to not cache proxy
6868
// objects
69-
connection = connection.unwrap(Connection.class);
69+
if (connection.isWrapperFor(Connection.class)) {
70+
connection = connection.unwrap(Connection.class);
71+
}
72+
} catch (final Exception e) {
73+
// perhaps wrapping isn't supported?
74+
// ex: org.h2.jdbc.JdbcConnection v1.3.175
75+
// Stick with original connection.
7076
}
7177
} catch (final Throwable e) {
7278
// Had some problem getting the connection.

0 commit comments

Comments
 (0)