Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions instrumentation/jdbc/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ tasks {

tasks {
withType<Test>().configureEach {
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
jvmArgs("-Dotel.instrumentation.jdbc.experimental.transaction.enabled=true")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public void transform(TypeTransformer transformer) {
"setTimestamp",
"setURL",
"setRowId",
"setNString")
"setNString",
"setObject")
.and(takesArgument(0, int.class))
.and(takesArguments(2))
.and(isPublic()),
Expand All @@ -89,6 +90,13 @@ public void transform(TypeTransformer transformer) {
.and(takesArguments(3))
.and(isPublic()),
PreparedStatementInstrumentation.class.getName() + "$SetTimeParameter3Advice");
transformer.applyAdviceToMethod(
namedOneOf("setObject")
.and(takesArgument(0, int.class))
.and(takesArgument(2, int.class))
.and(takesArguments(3))
.and(isPublic()),
PreparedStatementInstrumentation.class.getName() + "$SetParameter3Advice");
transformer.applyAdviceToMethod(
named("clearParameters").and(takesNoArguments()).and(isPublic()),
PreparedStatementInstrumentation.class.getName() + "$ClearParametersAdvice");
Expand Down Expand Up @@ -192,6 +200,38 @@ public static void onExit(
}
}

@SuppressWarnings("unused")
public static class SetParameter3Advice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void onExit(
@Advice.This PreparedStatement statement,
@Advice.Argument(0) int index,
@Advice.Argument(1) Object value,
@Advice.Argument(2) int targetSqlType) {
if (!CAPTURE_QUERY_PARAMETERS) {
return;
}

String str = null;

if (value instanceof Boolean
// Short, Int, Long, Float, Double, BigDecimal
|| value instanceof Number
|| value instanceof String
|| value instanceof Date
|| value instanceof Time
|| value instanceof Timestamp
|| value instanceof URL
|| value instanceof RowId) {
str = value.toString();
}

if (str != null) {
JdbcData.addParameter(statement, Integer.toString(index - 1), str);
}
}
}

@SuppressWarnings("unused")
public static class SetTimeParameter3Advice {
@Advice.OnMethodExit(suppress = Throwable.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Calendar;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -306,6 +307,59 @@ void testStringPreparedStatementParameter(
"S");
}

@ParameterizedTest
@MethodSource("preparedStatementStream")
void testObjectPreparedStatementParameter(
String system,
Connection connection,
String username,
String query,
String sanitizedQuery,
String spanName,
String url,
String table)
throws SQLException {
test(
system,
connection,
username,
query,
sanitizedQuery,
spanName,
url,
table,
statement -> statement.setObject(1, "S"),
"S");
}

@ParameterizedTest
@MethodSource("preparedStatementStream")
void testObjectWithTypePreparedStatementParameter(
String system,
Connection connection,
String username,
String query,
String sanitizedQuery,
String spanName,
String url,
String table)
throws SQLException {
// we are using old database drivers that don't support the tested setObject method
Assumptions.assumeTrue(Boolean.getBoolean("testLatestDeps"));

test(
system,
connection,
username,
query,
sanitizedQuery,
spanName,
url,
table,
statement -> statement.setObject(1, "S", Types.CHAR),
"S");
}

@ParameterizedTest
@MethodSource("preparedStatementStream")
void testDate2PreparedStatementParameter(
Expand Down
Loading