File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 2626import java .sql .Statement ;
2727import java .util .HashSet ;
2828import java .util .Set ;
29- import javax .xml .bind .DatatypeConverter ;
3029import org .slf4j .Logger ;
3130import 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 ) {
You can’t perform that action at this time.
0 commit comments