Resolve a TODO in SmokeTest
MODIFY
smoke-tests/src/test/groovy/io/opentelemetry/smoketest/GrpcSmokeTest.groovy
smoke-tests/src/test/groovy/io/opentelemetry/smoketest/GrpcSmokeTest.groovy
@@ -8,6 +8,7 @@ package io.opentelemetry.smoketest
import static java.util.stream.Collectors.toSet
import io.grpc.ManagedChannelBuilder
+import io.opentelemetry.api.trace.TraceId
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest
import io.opentelemetry.proto.collector.trace.v1.TraceServiceGrpc
import java.util.jar.Attributes
@@ -47,7 +48,7 @@ class GrpcSmokeTest extends SmokeTest {
then: "correct traceIds are logged via MDC instrumentation"
def loggedTraceIds = getLoggedTraceIds(output)
def spanTraceIds = getSpanStream(traces)
- .map({ bytesToHex(it.getTraceId().toByteArray()) })
+ .map({ TraceId.fromBytes(it.getTraceId().toByteArray()) })
.collect(toSet())
loggedTraceIds == spanTraceIds

MODIFY
smoke-tests/src/test/groovy/io/opentelemetry/smoketest/PropagationTest.groovy
smoke-tests/src/test/groovy/io/opentelemetry/smoketest/PropagationTest.groovy
@@ -7,6 +7,7 @@ package io.opentelemetry.smoketest
import static java.util.stream.Collectors.toSet
+import io.opentelemetry.api.trace.TraceId
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest
import okhttp3.Request
@@ -27,7 +28,7 @@ abstract class PropagationTest extends SmokeTest {
def response = CLIENT.newCall(request).execute()
Collection<ExportTraceServiceRequest> traces = waitForTraces()
def traceIds = getSpanStream(traces)
- .map({ bytesToHex(it.getTraceId().toByteArray()) })
+ .map({ TraceId.fromBytes(it.getTraceId().toByteArray()) })
.collect(toSet())
then:
@@ -93,7 +94,7 @@ class OtTracePropagationTest extends SmokeTest {
def response = CLIENT.newCall(request).execute()
Collection<ExportTraceServiceRequest> traces = waitForTraces()
def traceIds = getSpanStream(traces)
- .map({ bytesToHex(it.getTraceId().toByteArray()).substring(16) })
+ .map({ TraceId.fromBytes(it.getTraceId().toByteArray()).substring(16) })
.collect(toSet())
then:

MODIFY
smoke-tests/src/test/groovy/io/opentelemetry/smoketest/SmokeTest.groovy
smoke-tests/src/test/groovy/io/opentelemetry/smoketest/SmokeTest.groovy
@@ -156,37 +156,6 @@ abstract class SmokeTest extends Specification {
.isPresent()
}
- // TODO(anuraaga): Delete after https://github.com/open-telemetry/opentelemetry-java/pull/2750
- static String bytesToHex(byte[] bytes) {
- char[] dest = new char[bytes.length * 2]
- bytesToBase16(bytes, dest)
- return new String(dest)
- }
-
- private static void bytesToBase16(byte[] bytes, char[] dest) {
- for (int i = 0; i < bytes.length; i++) {
- byteToBase16(bytes[i], dest, i * 2)
- }
- }
-
- private static void byteToBase16(byte value, char[] dest, int destOffset) {
- int b = value & 0xFF
- dest[destOffset] = ENCODING[b]
- dest[destOffset + 1] = ENCODING[b | 0x100]
- }
-
- private static final String ALPHABET = "0123456789abcdef"
- private static final char[] ENCODING = buildEncodingArray()
-
- private static char[] buildEncodingArray() {
- char[] encoding = new char[512]
- for (int i = 0; i < 256; ++i) {
- encoding[i] = ALPHABET.charAt(i >>> 4)
- encoding[i | 0x100] = ALPHABET.charAt(i & 0xF)
- }
- return encoding
- }
-
static class Backend {
private static final INSTANCE = new Backend()

MODIFY
smoke-tests/src/test/groovy/io/opentelemetry/smoketest/SpringBootSmokeTest.groovy
smoke-tests/src/test/groovy/io/opentelemetry/smoketest/SpringBootSmokeTest.groovy
@@ -7,6 +7,7 @@ package io.opentelemetry.smoketest
import static java.util.stream.Collectors.toSet
+import io.opentelemetry.api.trace.TraceId
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest
import java.util.jar.Attributes
import java.util.jar.JarFile
@@ -55,7 +56,7 @@ class SpringBootSmokeTest extends SmokeTest {
then: "correct traceIds are logged via MDC instrumentation"
def loggedTraceIds = getLoggedTraceIds(output)
def spanTraceIds = getSpanStream(traces)
- .map({ bytesToHex(it.getTraceId().toByteArray()) })
+ .map({ TraceId.fromBytes(it.getTraceId().toByteArray()) })
.collect(toSet())
loggedTraceIds == spanTraceIds

MODIFY
smoke-tests/src/test/groovy/io/opentelemetry/smoketest/TraceInspector.java
smoke-tests/src/test/groovy/io/opentelemetry/smoketest/TraceInspector.java
package io.opentelemetry.smoketest;
import com.google.protobuf.ByteString;
+import io.opentelemetry.api.trace.TraceId;
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest;
import io.opentelemetry.proto.common.v1.AnyValue;
import io.opentelemetry.proto.common.v1.KeyValue;
@@ -88,7 +89,7 @@ public class TraceInspector {
return getSpanStream()
.map(Span::getTraceId)
.map(ByteString::toByteArray)
- .map(SmokeTest::bytesToHex)
+ .map(TraceId::fromBytes)
.collect(Collectors.toSet());
}
}

Resolve a TODO in SmokeTest (#2604)