Class TraceContext


  • public abstract class TraceContext
    extends java.lang.Object
    Allows explicit control on tracing context, which is used to manage the linkage of TraceEvents.

    This determines the current state/context of tracing, when TraceEvents are reported, the context would be updated. The context then provides references such that new events created can link and point to previous events to form extents/trace.

    Under most circumstances, context is set and managed automatically. This explicit control might only be necessary for trace that crosses multiple threads with top extent thread not being the parent thread of all the other events.

    Example:

     
     TraceContext currentContext = TraceContext.getDefault();
     threadPoolExecutor.submit(new MyCallable(currentContext));
     ...
     private class MyCallable {
         private TraceContext traceContext;
         private MyCallable(TraceContext context) {
             this.traceContext = context;
         }
         
         public call() {
             if (traceContext != null) {
                 traceContext.setAsDefault();
                 TraceEvent entryEvent = Trace.createEntryEvent("ThreadedJob");
                 ...
             }
         }
      
     }
     
     
     
    See Also:
    Context
    • Constructor Detail

      • TraceContext

        public TraceContext()
    • Method Detail

      • getDefault

        public static TraceContext getDefault()
        Returns the Context currently associated with this thread. Note that this context is Clone of the context: modifications will NOT affect the current thread unless setAsDefault is called.
        Returns:
        ITraceContextHandler
      • clearDefault

        public static void clearDefault()
        Resets the current thread's context
      • setAsDefault

        public abstract void setAsDefault()
        Sets the current thread's context to this context
      • isSampled

        public static boolean isSampled​(java.lang.String xTraceID)