JavaVersionSpecific returns millisecond precision for currentTimeNanos()

Open
#6,233 7 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java

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.

Description

Bug

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

  1. Create and start Span 1 - startEpochNanos is set to millisecond precision
  2. End Span 1 - endEpochNanos is set to nanosecond precision
  3. Create and start Span 2 - startEpochNanos is set to millisecond precision
  4. 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

Dominant language
Java
Stars
2.5k
Forks
1.1k
Avg merge
5d 11h
Merged PRs (30d)
41

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from open-telemetry/opentelemetry-java

All issues in open-telemetry/opentelemetry-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.