Skip to content

Commit 8eef2f5

Browse files
authored
Merge pull request #146 from DataDog/tyler/null-handling
Better null handling for JDBC instrumentation
2 parents 31e912a + 4199d12 commit 8eef2f5

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

dd-java-agent/src/main/java/com/datadoghq/agent/TracingAgent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void onError(
109109
final JavaModule module,
110110
final boolean loaded,
111111
final Throwable throwable) {
112-
log.warn("Failed to handle " + typeName + " for transformation", throwable);
112+
log.debug("Failed to handle " + typeName + " for transformation: " + throwable.getMessage());
113113
}
114114

115115
@Override

dd-java-agent/src/main/java/com/datadoghq/agent/instrumentation/jdbc/DriverInstrumentation.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,19 @@ public static void addDBInfo(
3838
@Advice.Argument(0) final String url,
3939
@Advice.Argument(1) final Properties info,
4040
@Advice.Return final Connection connection) {
41-
// Remove end of url to prevent passwords from leaking:
42-
final String sanitizedURL = url.replaceAll("[?;].*", "");
43-
final String type = url.split(":")[1];
44-
final String dbUser = info == null ? null : info.getProperty("user");
45-
connectionInfo.put(connection, new DBInfo(sanitizedURL, type, dbUser));
41+
if (url != null) {
42+
// Remove end of url to prevent passwords from leaking:
43+
final String sanitizedURL = url.replaceAll("[?;].*", "");
44+
final String type = url.split(":")[1];
45+
final String dbUser = info == null ? null : info.getProperty("user");
46+
connectionInfo.put(connection, new DBInfo(sanitizedURL, type, dbUser));
47+
}
4648
}
4749
}
4850

4951
@Data
5052
public static class DBInfo {
53+
public static DBInfo UNKNOWN = new DBInfo("null", "unknown", null);
5154
private final String url;
5255
private final String type;
5356
private final String user;

dd-java-agent/src/main/java/com/datadoghq/agent/instrumentation/jdbc/PreparedStatementInstrumentation.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ public static ActiveSpan startSpan(@Advice.This final PreparedStatement statemen
4949
return NoopActiveSpanSource.NoopActiveSpan.INSTANCE;
5050
}
5151

52-
final DriverInstrumentation.DBInfo dbInfo =
53-
DriverInstrumentation.connectionInfo.get(connection);
52+
DriverInstrumentation.DBInfo dbInfo = DriverInstrumentation.connectionInfo.get(connection);
53+
if (dbInfo == null) {
54+
dbInfo = DriverInstrumentation.DBInfo.UNKNOWN;
55+
}
5456

5557
final ActiveSpan span =
5658
GlobalTracer.get().buildSpan(dbInfo.getType() + ".query").startActive();

dd-java-agent/src/main/java/com/datadoghq/agent/instrumentation/jdbc/StatementInstrumentation.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ public static ActiveSpan startSpan(
4949
return NoopActiveSpanSource.NoopActiveSpan.INSTANCE;
5050
}
5151

52-
final DriverInstrumentation.DBInfo dbInfo =
53-
DriverInstrumentation.connectionInfo.get(connection);
52+
DriverInstrumentation.DBInfo dbInfo = DriverInstrumentation.connectionInfo.get(connection);
53+
if (dbInfo == null) {
54+
dbInfo = DriverInstrumentation.DBInfo.UNKNOWN;
55+
}
5456

5557
final ActiveSpan span =
5658
GlobalTracer.get().buildSpan(dbInfo.getType() + ".query").startActive();

0 commit comments

Comments
 (0)