Skip to content

Commit 606a9be

Browse files
committed
without DatatypeConverter
1 parent 52a14b2 commit 606a9be

File tree

1 file changed

+11
-2
lines changed
  • dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.sql.Statement;
2727
import java.util.HashSet;
2828
import java.util.Set;
29-
import javax.xml.bind.DatatypeConverter;
3029
import org.slf4j.Logger;
3130
import org.slf4j.LoggerFactory;
3231

@@ -244,6 +243,16 @@ public boolean isSqlServer(final DBInfo dbInfo) {
244243
return "sqlserver".equals(dbInfo.getType());
245244
}
246245

246+
public static byte[] hexStringToByteArray(String s) {
247+
int len = s.length();
248+
byte[] data = new byte[len / 2];
249+
for (int i = 0; i < len; i += 2) {
250+
data[i / 2] =
251+
(byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
252+
}
253+
return data;
254+
}
255+
247256
/**
248257
* Executes a `SET CONTEXT_INFO` statement on the DB with the active trace ID and the given span
249258
* ID. This context will be "attached" to future queries on the same connection. See <a
@@ -275,7 +284,7 @@ public long setContextInfo(Connection connection, DBInfo dbInfo) {
275284

276285
String instrumentationSql = "set context_info ?";
277286
instrumentationStatement = connection.prepareStatement(instrumentationSql);
278-
instrumentationStatement.setBytes(1, DatatypeConverter.parseHexBinary(contextInfo));
287+
instrumentationStatement.setBytes(1, hexStringToByteArray(contextInfo));
279288
DECORATE.onStatement(instrumentationSpan, instrumentationSql);
280289
instrumentationStatement.execute();
281290
} catch (Exception e) {

0 commit comments

Comments
 (0)