Generate a random trace ID instead of copying the span ID
MODIFY
dd-java-agent-ittests/src/test/java/com/datadoghq/trace/agent/TraceAnnotationsManagerTest.java
dd-java-agent-ittests/src/test/java/com/datadoghq/trace/agent/TraceAnnotationsManagerTest.java
@@ -45,7 +45,7 @@ public class TraceAnnotationsManagerTest {
//Test new trace with 2 children spans
SayTracedHello.sayHELLOsayHA();
assertThat(writer.firstTrace().size()).isEqualTo(3);
- final long parentId = writer.firstTrace().get(0).context().getTraceId();
+ final long parentId = writer.firstTrace().get(0).context().getSpanId();
assertThat(writer.firstTrace().get(0).getOperationName()).isEqualTo("NEW_TRACE");
assertThat(writer.firstTrace().get(0).getParentId()).isEqualTo(0); //ROOT / no parent

MODIFY
dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java
dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java
@@ -290,7 +290,8 @@ public class DDTracer extends ThreadLocalActiveSpanSource implements io.opentrac
}
private long generateNewId() {
- return ThreadLocalRandom.current().nextLong();
+ // Ensure the generated ID is in a valid range:
+ return ThreadLocalRandom.current().nextLong(1, Long.MAX_VALUE);
}
/**
@@ -324,7 +325,7 @@ public class DDTracer extends ThreadLocalActiveSpanSource implements io.opentrac
if (this.serviceName == null) this.serviceName = ddsc.getServiceName();
if (this.spanType == null) this.spanType = ddsc.getSpanType();
} else {
- traceId = spanId;
+ traceId = generateNewId();
parentSpanId = 0L;
baggage = null;
parentTrace = null;

Generate a random trace ID instead of copying the span ID