Class Trace


  • public class Trace
    extends Object
    A Trace represents a time interval an application has spent within a certain piece of code. A trace can be part of a hierarchy, i.e. i can have a parent trace and it can have sub-traces.
    • Method Detail

      • getLabel

        public String getLabel()
        Returns the label of this trace.
        Returns:
        the label of this trace
      • getStartTime

        public Instant getStartTime()
        Returns the start time of this trace.
        Returns:
        the start time of this trace
      • getEndTime

        public Instant getEndTime()
        Returns the end time of this trace.
        Returns:
        the end time of this trace
        Throws:
        IllegalStateException - if the trace has not yet finished
      • hasEnded

        public boolean hasEnded()
        Returns whether the trace has already ended.
        Returns:
        whether the trace has already ended
      • end

        public void end​(Instant endTime)
        Sets the trace as ended and records the end time.
        Parameters:
        endTime - the end time for the trace
      • end

        public void end​(Instant endTime,
                        Throwable exitThrowable)
        Sets this trace and all still active sub-traces as ended and records the end time.
        Parameters:
        endTime - the end time for the trace
        exitThrowable - the throwable that exited the trace
      • getDuration

        public Duration getDuration()
        Returns the duration of this trace.
        Returns:
        the duration of this trace
        Throws:
        IllegalStateException - if the trace has not yet finished
      • getParentTrace

        public Trace getParentTrace()
        Returns the parent trace or null.
        Returns:
        the parent trace or null
      • isContextRoot

        public boolean isContextRoot()
        Returns whether this trace is the root of a TraceContextImpl.
        Returns:
        whether this trace is the root of a TraceContextImpl
      • isGap

        public boolean isGap()
        Returns whether this trace represents a gap. Gaps are periods of time between explicit traces. This can help locate costly segments of code that aren't explicitly traced (yet).
        Returns:
        whether this trace represents a gap
      • getSubTraces

        public List<Trace> getSubTraces()
        Returns the list of sub-traces.
        Returns:
        the list of sub-traces
      • getLastSubTrace

        public Trace getLastSubTrace()
      • getActiveTrace

        public Trace getActiveTrace​(boolean includeRoot)
      • getExitThrowable

        public Optional<Throwable> getExitThrowable()
        Returns the throwable that exited the trace.
        Returns:
        the throwable that exited the trace
      • isWarn

        public boolean isWarn()
      • setWarn

        public void setWarn​(boolean warn)
      • getData

        public <T> T getData​(Class<T> key)
      • setData

        public <T> void setData​(Class<T> key,
                                T data)
      • getData

        public <T> T getData​(String key,
                             Class<T> type)
      • setData

        public void setData​(String key,
                            Object data)