Class AnchoredClock

java.lang.Object
io.opentelemetry.sdk.trace.AnchoredClock

@Immutable final class AnchoredClock extends Object
A utility for returning wall times anchored to a given point in time. Wall time measurements will not be taken from the system, but instead are computed by adding monotonic time to the anchor point.

This is needed because Java has lower granularity for epoch times and tracing events are recorded more often. There is also a performance improvement in avoiding referencing the system's wall time where possible. Instead of computing a true wall time for every timestamp within a trace, we compute it once at the local root and then anchor all descendant span timestamps to this root's timestamp.

  • Field Details

    • clock

      private final Clock clock
    • epochNanos

      private final long epochNanos
    • nanoTime

      private final long nanoTime
  • Constructor Details

    • AnchoredClock

      private AnchoredClock(Clock clock, long epochNanos, long nanoTime)
  • Method Details

    • create

      public static AnchoredClock create(Clock clock)
      Returns a AnchoredClock.
      Parameters:
      clock - the Clock to be used to read the current epoch time and nanoTime.
      Returns:
      a MonotonicClock.
    • now

      long now()
      Returns the current epoch timestamp in nanos calculated using System.nanoTime() since the reference time read in the constructor. This time can be used for computing durations.
      Returns:
      the current epoch timestamp in nanos.
    • startTime

      long startTime()
      Returns the start time in nanos of this AnchoredClock.