New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JavaVersionSpecific returns millisecond precision for currentTimeNanos() #6233
Comments
@scottsue I'm not aware of any reliable way of getting nanosecond precision wall time on Java 8. Do you know of something? |
@breedx-splk correct, unfortunately not a reliable way. However |
Would the idea then be to anchor to some arbitrary previous time then? |
I was just playing around to see how this could work and I created my own version of JavaVersionSpecific. The implementation requiring the following private static final NanosecondClock SYSTEM_EPOCH_NANO_CLOCK = new NanosecondClock(null);
public long currentTimeNanos() {
return SYSTEM_EPOCH_NANO_CLOCK.getNowSinceEpochInNano();
} This utilises a static NanoClock which gives the ability to return the nanos since epoch. In essence, this is what AnchoredClock does as well, only that it seems AnchoredClock looks to be recreated if it is not inheriting from a parentSpan? I would say it is possibly feasible to have a static instance of AnchoredClock in my above implementation to give the same functionality? |
Yeah, but you haven't shared the implementation of that class. Where is that from? |
The implementation of the NanosecondClock is something that I had to hand quickly internally. However after using this, I suspect that creating a static AnchoredClock could work. |
From a Java 8 JVM perspective there are limitations to the precision of time, however looking at the implementation of JavaVersionSpecific.currentTimeNanos() for Java 8, this should return as close as possible, the nanosecond precision since epoch, however it is currently only to millisecond precision.
Steps to reproduce
Create two Spans in the following order
It looks like a new AnchoredClock is created for each Span if it is not inheriting from a parentSpan, therefore if the spans are created in less than 1 millisecond of each other, there is a potential the Span1.endEpochNanos is greater than Span2.startEpochNanos
What did you expect to see?
I would expect Span.startEpochNanos to be at nanosecond precision
What did you see instead?
Span.startEpochNanos is at millisecond precision
What version and what artifacts are you using?
Artifacts: opentelemetry-sdk-common
Version: 1.35
Environment
OS: Centos
Runtime: Java 8 OpenJdk
The text was updated successfully, but these errors were encountered: