Class Trace

java.lang.Object
de.codecamp.tracer.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 Details

    • newGap

      public static Trace newGap(Trace parentTrace, Instant startTime, Instant endTime)
    • newExplicit

      public static Trace newExplicit(Trace parentTrace, Instant startTime, String label, Object[] labelFormatArgs)
    • newContextRoot

      public static Trace newContextRoot(Trace parentTrace, Instant startTime, String label, Object[] labelFormatArgs)
    • 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 Object getData(String key)
    • getData

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

      public void setData(String key, Object data)
    • getData

      public Map<String,Object> getData()
    • setData

      public void setData(Map<String,Object> data)
    • toString

      public String toString()
      Overrides:
      toString in class Object