Better null handling for JDBC instrumentation
This also reduces the log noise for transformation issues around synthesized classes.
MODIFY
dd-java-agent/src/main/java/com/datadoghq/agent/TracingAgent.java
dd-java-agent/src/main/java/com/datadoghq/agent/TracingAgent.java
@@ -109,7 +109,7 @@ public class TracingAgent {
final JavaModule module,
final boolean loaded,
final Throwable throwable) {
- log.warn("Failed to handle " + typeName + " for transformation", throwable);
+ log.debug("Failed to handle " + typeName + " for transformation: " + throwable.getMessage());
}
@Override

MODIFY
dd-java-agent/src/main/java/com/datadoghq/agent/instrumentation/jdbc/DriverInstrumentation.java
dd-java-agent/src/main/java/com/datadoghq/agent/instrumentation/jdbc/DriverInstrumentation.java
@@ -38,6 +38,7 @@ public final class DriverInstrumentation implements Instrumenter {
@Advice.Argument(0) final String url,
@Advice.Argument(1) final Properties info,
@Advice.Return final Connection connection) {
+ if (url != null) {
// Remove end of url to prevent passwords from leaking:
final String sanitizedURL = url.replaceAll("[?;].*", "");
final String type = url.split(":")[1];
@@ -45,9 +46,11 @@ public final class DriverInstrumentation implements Instrumenter {
connectionInfo.put(connection, new DBInfo(sanitizedURL, type, dbUser));
}
}
+ }
@Data
public static class DBInfo {
+ public static DBInfo UNKNOWN = new DBInfo("null", "unknown", null);
private final String url;
private final String type;
private final String user;

MODIFY
dd-java-agent/src/main/java/com/datadoghq/agent/instrumentation/jdbc/PreparedStatementInstrumentation.java
dd-java-agent/src/main/java/com/datadoghq/agent/instrumentation/jdbc/PreparedStatementInstrumentation.java
@@ -49,8 +49,10 @@ public final class PreparedStatementInstrumentation implements Instrumenter {
return NoopActiveSpanSource.NoopActiveSpan.INSTANCE;
}
- final DriverInstrumentation.DBInfo dbInfo =
- DriverInstrumentation.connectionInfo.get(connection);
+ DriverInstrumentation.DBInfo dbInfo = DriverInstrumentation.connectionInfo.get(connection);
+ if (dbInfo == null) {
+ dbInfo = DriverInstrumentation.DBInfo.UNKNOWN;
+ }
final ActiveSpan span =
GlobalTracer.get().buildSpan(dbInfo.getType() + ".query").startActive();

MODIFY
dd-java-agent/src/main/java/com/datadoghq/agent/instrumentation/jdbc/StatementInstrumentation.java
dd-java-agent/src/main/java/com/datadoghq/agent/instrumentation/jdbc/StatementInstrumentation.java
@@ -49,8 +49,10 @@ public final class StatementInstrumentation implements Instrumenter {
return NoopActiveSpanSource.NoopActiveSpan.INSTANCE;
}
- final DriverInstrumentation.DBInfo dbInfo =
- DriverInstrumentation.connectionInfo.get(connection);
+ DriverInstrumentation.DBInfo dbInfo = DriverInstrumentation.connectionInfo.get(connection);
+ if (dbInfo == null) {
+ dbInfo = DriverInstrumentation.DBInfo.UNKNOWN;
+ }
final ActiveSpan span =
GlobalTracer.get().buildSpan(dbInfo.getType() + ".query").startActive();

Better null handling for JDBC instrumentation

This also reduces the log noise for transformation issues around synthesized classes.