centralize all clock methods
MODIFY
dd-trace/src/main/java/com/datadoghq/trace/DDBaseSpan.java
dd-trace/src/main/java/com/datadoghq/trace/DDBaseSpan.java
@@ -35,18 +35,18 @@ public abstract class DDBaseSpan<S extends BaseSpan> implements BaseSpan<S> {
// record the start time in nano (current milli + nano delta)
if (timestampMicro == 0L) {
- this.startTimeMicro = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis());
+ this.startTimeMicro = Clock.currentMicroTime();
} else {
this.startTimeMicro = timestampMicro;
}
- this.startTimeNano = Clock.nowNanos();
+ this.startTimeNano = Clock.currentNanoTicks();
// track each span of the trace
this.context.getTrace().add(this);
}
public final void finish() {
- this.durationNano = Clock.nowNanos() - startTimeNano;
+ this.durationNano = Clock.currentNanoTicks() - startTimeNano;
afterFinish();
}

MODIFY
dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java
dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java
@@ -14,12 +14,7 @@ import io.opentracing.BaseSpan;
import io.opentracing.SpanContext;
import io.opentracing.propagation.Format;
import io.opentracing.util.ThreadLocalActiveSpanSource;
-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.*;
import lombok.extern.slf4j.Slf4j;
/** DDTracer makes it easy to send traces and span to DD using the OpenTracing integration. */
@@ -290,7 +285,7 @@ public class DDTracer extends ThreadLocalActiveSpanSource implements io.opentrac
}
private long generateNewId() {
- return Clock.nowNanos();
+ return Clock.currentNanoTicks();
}
/**

MODIFY
dd-trace/src/main/java/com/datadoghq/trace/util/Clock.java
dd-trace/src/main/java/com/datadoghq/trace/util/Clock.java
package com.datadoghq.trace.util;
+import java.util.concurrent.TimeUnit;
+
public class Clock {
- public static synchronized long nowNanos() {
+ public static synchronized long currentNanoTicks() {
return System.nanoTime();
}
+
+ public static synchronized long currentMicroTime() {
+ return TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis());
+ }
}

centralize all clock methods