open-telemetry / open-telemetry/opentelemetry-java
JavaVersionSpecific returns millisecond precision for currentTimeNanos()
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2.5k
- Forks
- 1k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 58
Description
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
- Create and start Span 1 - startEpochNanos is set to millisecond precision
- End Span 1 - endEpochNanos is set to nanosecond precision
- Create and start Span 2 - startEpochNanos is set to millisecond precision
- End Span 2 - endEpochNanos is set to nanosecond precision
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at JavaVersionSpecific.currentTimeNanos() in the opentelemetry-sdk-common artifact and trace how AnchoredClock is created for spans without a parent. Reproduce the two-span sequence on Java 8, then verify that Span.startEpochNanos uses the closest available precision and cannot regress relative to the preceding span's end time.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- observability-sre
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100