|
20 | 20 | import datadog.trace.bootstrap.instrumentation.jdbc.DBInfo; |
21 | 21 | import datadog.trace.bootstrap.instrumentation.jdbc.DBQueryInfo; |
22 | 22 | import datadog.trace.bootstrap.instrumentation.jdbc.JDBCConnectionUrlParser; |
23 | | -import java.io.ByteArrayOutputStream; |
24 | | -import java.io.DataOutputStream; |
| 23 | +import java.nio.ByteBuffer; |
| 24 | +import java.nio.ByteOrder; |
25 | 25 | import java.sql.Connection; |
26 | 26 | import java.sql.DatabaseMetaData; |
27 | 27 | import java.sql.PreparedStatement; |
@@ -274,15 +274,15 @@ public long setContextInfo(Connection connection, DBInfo dbInfo) { |
274 | 274 | final byte versionAndSamplingDecision = |
275 | 275 | (byte) ((VERSION << 4) & 0b11110000 | samplingDecision & 0b00000001); |
276 | 276 |
|
277 | | - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
278 | | - DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); |
279 | | - dataOutputStream.writeByte(versionAndSamplingDecision); |
280 | | - dataOutputStream.writeLong(spanID); |
| 277 | + ByteBuffer byteBuffer = ByteBuffer.allocate(1 + 3 * Long.BYTES); |
| 278 | + byteBuffer.order(ByteOrder.BIG_ENDIAN); |
| 279 | + |
| 280 | + byteBuffer.put(versionAndSamplingDecision); |
| 281 | + byteBuffer.putLong(spanID); |
281 | 282 | final DDTraceId traceId = instrumentationSpan.getTraceId(); |
282 | | - dataOutputStream.writeLong(traceId.toHighOrderLong()); |
283 | | - dataOutputStream.writeLong(traceId.toLong()); |
284 | | - dataOutputStream.flush(); |
285 | | - final byte[] contextInfo = byteArrayOutputStream.toByteArray(); |
| 283 | + byteBuffer.putLong(traceId.toHighOrderLong()); |
| 284 | + byteBuffer.putLong(traceId.toLong()); |
| 285 | + final byte[] contextInfo = byteBuffer.array(); |
286 | 286 |
|
287 | 287 | String instrumentationSql = "set context_info ?"; |
288 | 288 | instrumentationStatement = connection.prepareStatement(instrumentationSql); |
|
0 commit comments