Skip to content

Commit c379244

Browse files
committed
feedback
1 parent cf1db4c commit c379244

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/PreparedStatementInstrumentation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public static void onExit(
156156
String str = null;
157157

158158
if (value instanceof Boolean
159-
// Short, Int, Long, Float, Double, BigDecimal
159+
// Byte, Short, Int, Long, Float, Double, BigDecimal
160160
|| value instanceof Number
161161
|| value instanceof String
162162
|| value instanceof Date
@@ -191,7 +191,7 @@ public static void onExit(
191191
String str = null;
192192

193193
if (value instanceof Boolean
194-
// Short, Int, Long, Float, Double, BigDecimal
194+
// Byte, Short, Int, Long, Float, Double, BigDecimal
195195
|| value instanceof Number
196196
|| value instanceof String
197197
|| value instanceof Date

instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/OpenTelemetryPreparedStatement.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,28 @@ private void putParameter(int index, Object value) {
7171
}
7272
}
7373

74+
private void putParameterIfRecognizedType(int index, Object value) {
75+
if (this.captureQueryParameters && value != null) {
76+
String str = null;
77+
78+
if (value instanceof Boolean
79+
// Byte, Short, Int, Long, Float, Double, BigDecimal
80+
|| value instanceof Number
81+
|| value instanceof String
82+
|| value instanceof Date
83+
|| value instanceof Time
84+
|| value instanceof Timestamp
85+
|| value instanceof URL
86+
|| value instanceof RowId) {
87+
str = value.toString();
88+
}
89+
90+
if (str != null) {
91+
parameters.put(Integer.toString(index - 1), str);
92+
}
93+
}
94+
}
95+
7496
@Override
7597
public ResultSet executeQuery() throws SQLException {
7698
return OpenTelemetryResultSet.wrap(wrapCall(query, delegate::executeQuery), this);
@@ -244,14 +266,14 @@ public void setBinaryStream(int parameterIndex, InputStream x) throws SQLExcepti
244266
@Override
245267
public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
246268
delegate.setObject(parameterIndex, x, targetSqlType);
247-
putParameter(parameterIndex, x);
269+
putParameterIfRecognizedType(parameterIndex, x);
248270
}
249271

250272
@SuppressWarnings("UngroupedOverloads")
251273
@Override
252274
public void setObject(int parameterIndex, Object x) throws SQLException {
253275
delegate.setObject(parameterIndex, x);
254-
putParameter(parameterIndex, x);
276+
putParameterIfRecognizedType(parameterIndex, x);
255277
}
256278

257279
@Override

0 commit comments

Comments
 (0)