centralize all clock methods
This commit is contained in:
parent
e8c980de20
commit
ebb3cde32c
|
@ -35,18 +35,18 @@ public abstract class DDBaseSpan<S extends BaseSpan> implements BaseSpan<S> {
|
||||||
|
|
||||||
// record the start time in nano (current milli + nano delta)
|
// record the start time in nano (current milli + nano delta)
|
||||||
if (timestampMicro == 0L) {
|
if (timestampMicro == 0L) {
|
||||||
this.startTimeMicro = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis());
|
this.startTimeMicro = Clock.currentMicroTime();
|
||||||
} else {
|
} else {
|
||||||
this.startTimeMicro = timestampMicro;
|
this.startTimeMicro = timestampMicro;
|
||||||
}
|
}
|
||||||
this.startTimeNano = Clock.nowNanos();
|
this.startTimeNano = Clock.currentNanoTicks();
|
||||||
|
|
||||||
// track each span of the trace
|
// track each span of the trace
|
||||||
this.context.getTrace().add(this);
|
this.context.getTrace().add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void finish() {
|
public final void finish() {
|
||||||
this.durationNano = Clock.nowNanos() - startTimeNano;
|
this.durationNano = Clock.currentNanoTicks() - startTimeNano;
|
||||||
afterFinish();
|
afterFinish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,7 @@ 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.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Queue;
|
|
||||||
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. */
|
||||||
|
@ -290,7 +285,7 @@ public class DDTracer extends ThreadLocalActiveSpanSource implements io.opentrac
|
||||||
}
|
}
|
||||||
|
|
||||||
private long generateNewId() {
|
private long generateNewId() {
|
||||||
return Clock.nowNanos();
|
return Clock.currentNanoTicks();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
package com.datadoghq.trace.util;
|
package com.datadoghq.trace.util;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class Clock {
|
public class Clock {
|
||||||
|
|
||||||
public static synchronized long nowNanos() {
|
public static synchronized long currentNanoTicks() {
|
||||||
return System.nanoTime();
|
return System.nanoTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static synchronized long currentMicroTime() {
|
||||||
|
return TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue