Merge pull request #74 from DataDog/tyler/random
Use a ThreadLocalRandom generator for span IDs instead of nanoTime
This commit is contained in:
commit
f56418e82a
|
@ -1,6 +1,9 @@
|
||||||
# Maven #
|
# Maven #
|
||||||
#########
|
#########
|
||||||
target
|
target
|
||||||
|
/target
|
||||||
|
**/target/
|
||||||
|
**/dependency-reduced-pom.xml
|
||||||
|
|
||||||
# Gradle #
|
# Gradle #
|
||||||
#########
|
#########
|
||||||
|
@ -31,6 +34,8 @@ Thumbs.db
|
||||||
#################
|
#################
|
||||||
/.idea
|
/.idea
|
||||||
*.iml
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
# Visual Studio Code #
|
# Visual Studio Code #
|
||||||
######################
|
######################
|
||||||
|
@ -39,10 +44,5 @@ Thumbs.db
|
||||||
# Others #
|
# Others #
|
||||||
##########
|
##########
|
||||||
/logs/*
|
/logs/*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/target
|
|
||||||
**/target/
|
|
||||||
**/dependency-reduced-pom.xml
|
|
||||||
/bin
|
/bin
|
||||||
|
/out
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class TraceAnnotationsManagerTest {
|
||||||
//Test new trace with 2 children spans
|
//Test new trace with 2 children spans
|
||||||
SayTracedHello.sayHELLOsayHA();
|
SayTracedHello.sayHELLOsayHA();
|
||||||
assertThat(writer.firstTrace().size()).isEqualTo(3);
|
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).getOperationName()).isEqualTo("NEW_TRACE");
|
||||||
assertThat(writer.firstTrace().get(0).getParentId()).isEqualTo(0); //ROOT / no parent
|
assertThat(writer.firstTrace().get(0).getParentId()).isEqualTo(0); //ROOT / no parent
|
||||||
|
|
|
@ -5,7 +5,6 @@ import com.datadoghq.trace.propagation.Codec;
|
||||||
import com.datadoghq.trace.propagation.HTTPCodec;
|
import com.datadoghq.trace.propagation.HTTPCodec;
|
||||||
import com.datadoghq.trace.sampling.AllSampler;
|
import com.datadoghq.trace.sampling.AllSampler;
|
||||||
import com.datadoghq.trace.sampling.Sampler;
|
import com.datadoghq.trace.sampling.Sampler;
|
||||||
import com.datadoghq.trace.util.Clock;
|
|
||||||
import com.datadoghq.trace.writer.LoggingWriter;
|
import com.datadoghq.trace.writer.LoggingWriter;
|
||||||
import com.datadoghq.trace.writer.Writer;
|
import com.datadoghq.trace.writer.Writer;
|
||||||
import io.opentracing.ActiveSpan;
|
import io.opentracing.ActiveSpan;
|
||||||
|
@ -14,7 +13,13 @@ import io.opentracing.BaseSpan;
|
||||||
import io.opentracing.SpanContext;
|
import io.opentracing.SpanContext;
|
||||||
import io.opentracing.propagation.Format;
|
import io.opentracing.propagation.Format;
|
||||||
import io.opentracing.util.ThreadLocalActiveSpanSource;
|
import io.opentracing.util.ThreadLocalActiveSpanSource;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/** DDTracer makes it easy to send traces and span to DD using the OpenTracing integration. */
|
/** DDTracer makes it easy to send traces and span to DD using the OpenTracing integration. */
|
||||||
|
@ -285,7 +290,8 @@ public class DDTracer extends ThreadLocalActiveSpanSource implements io.opentrac
|
||||||
}
|
}
|
||||||
|
|
||||||
private long generateNewId() {
|
private long generateNewId() {
|
||||||
return Clock.currentNanoTicks();
|
// Ensure the generated ID is in a valid range:
|
||||||
|
return ThreadLocalRandom.current().nextLong(1, Long.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -319,7 +325,7 @@ public class DDTracer extends ThreadLocalActiveSpanSource implements io.opentrac
|
||||||
if (this.serviceName == null) this.serviceName = ddsc.getServiceName();
|
if (this.serviceName == null) this.serviceName = ddsc.getServiceName();
|
||||||
if (this.spanType == null) this.spanType = ddsc.getSpanType();
|
if (this.spanType == null) this.spanType = ddsc.getSpanType();
|
||||||
} else {
|
} else {
|
||||||
traceId = spanId;
|
traceId = generateNewId();
|
||||||
parentSpanId = 0L;
|
parentSpanId = 0L;
|
||||||
baggage = null;
|
baggage = null;
|
||||||
parentTrace = null;
|
parentTrace = null;
|
||||||
|
|
Loading…
Reference in New Issue