Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Remove problematic nanoTime() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
bhs committed Sep 23, 2016
1 parent 505eb4a commit 027764f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,17 @@ public final Map<String,String> getBaggage() {

@Override
public final Span log(String event) {
return log(System.nanoTime() / 1000, event);
return log(nowMicros(), event);
}

@Override
public final Span log(long timestampMicros, String event) {
return log(System.nanoTime() / 1000, Collections.singletonMap("event", event));
return log(timestampMicros, Collections.singletonMap("event", event));
}

@Override
public final Span log(Map<String, ?> fields) {
return log(System.nanoTime() / 1000, fields);
return log(nowMicros(), fields);
}

@Override
Expand Down Expand Up @@ -179,4 +179,9 @@ final class LogData {
this.fields = fields;
}
}

static long nowMicros() {
Instant now = Instant.now();
return (now.getEpochSecond() * 1000000) + (now.getNano() / 1000);
}
}
13 changes: 8 additions & 5 deletions opentracing-mock/src/main/java/io/opentracing/mock/MockSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public synchronized MockContext context() {

@Override
public void finish() {
this.finish(System.nanoTime() / 1000);
this.finish(nowMicros());
}

@Override
Expand Down Expand Up @@ -123,8 +123,7 @@ public synchronized Span setTag(String key, Number value) {

@Override
public final Span log(Map<String, ?> fields) {
long nowMicros = System.nanoTime() / 1000;
return log(nowMicros, fields);
return log(nowMicros(), fields);
}
@Override
public final Span log(long timestampMicros, Map<String, ?> fields) {
Expand All @@ -134,7 +133,7 @@ public final Span log(long timestampMicros, Map<String, ?> fields) {

@Override
public Span log(String event) {
return this.log(System.nanoTime() / 1000, event);
return this.log(nowMicros(), event);
}

@Override
Expand All @@ -144,7 +143,7 @@ public Span log(long timestampMicroseconds, String event) {

@Override
public Span log(String eventName, Object payload) {
return this.log(System.nanoTime() / 1000, eventName, payload);
return this.log(nowMicros(), eventName, payload);
}

@Override
Expand Down Expand Up @@ -253,4 +252,8 @@ public long timestampMicros() {
static long nextId() {
return nextId.addAndGet(1);
}

static long nowMicros() {
return System.currentTimeMillis() * 1000;
}
}

0 comments on commit 027764f

Please sign in to comment.