Class ActiveSpan


  • public class ActiveSpan
    extends java.lang.Object
    Access the currently active OpenTracing Span and SpanContext.
    • Constructor Summary

      Constructors 
      Constructor Description
      ActiveSpan()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Iterable<java.util.Map.Entry<java.lang.String,​java.lang.String>> baggageItems()
      Get all baggage items propagating with the currently active OpenTracing SpanContext (if there is one).
      static io.opentracing.Span get()
      Get the currently active OpenTracing Span (if there is one).
      static java.lang.String getBaggageItem​(java.lang.String key)
      Get a baggage item from the currently active OpenTracing Span (if there is one).
      static io.opentracing.SpanContext getContext()
      Get the currently active OpenTracing SpanContext (if there is one).
      static void log​(java.lang.String event)
      Log an event to the currently active OpenTracing Span (if there is one).
      static void log​(java.util.Map<java.lang.String,​?> fields)
      Log key:value pairs to the currently active OpenTracing Span (if there is one).
      static void setBaggageItem​(java.lang.String key, java.lang.String value)
      Attach a baggage item to the currently active OpenTracing Span (if there is one).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ActiveSpan

        public ActiveSpan()
    • Method Detail

      • get

        public static io.opentracing.Span get()
        Get the currently active OpenTracing Span (if there is one).

        Returns null if there is no active Span. See also the log and baggage methods, which only log or attach if there is a non-null active Span.

        Returns:
        the currently active Span, otherwise null
        See Also:
        log(Map), log(String), setBaggageItem(String, String), getBaggageItem(String)
      • getContext

        public static io.opentracing.SpanContext getContext()
        Get the currently active OpenTracing SpanContext (if there is one).

        Returns null if there is no active SpanContext.

        Returns:
        the currently active SpanContext, otherwise null
      • log

        public static void log​(java.util.Map<java.lang.String,​?> fields)
        Log key:value pairs to the currently active OpenTracing Span (if there is one).
        Parameters:
        fields - key:value log fields
      • log

        public static void log​(java.lang.String event)
        Log an event to the currently active OpenTracing Span (if there is one).
        Parameters:
        event - the event value
      • setBaggageItem

        public static void setBaggageItem​(java.lang.String key,
                                          java.lang.String value)
        Attach a baggage item to the currently active OpenTracing Span (if there is one).

        Note: The baggage key is case-insensitive.

        Note: Baggage is propagated with subsequent local and remote calls, so this feature must be used with care. Baggage is only propagated to the future children of this Span.

        Parameters:
        key - the (case-insenstive) key for this baggage item
        value - the value for this baggage item
      • getBaggageItem

        public static java.lang.String getBaggageItem​(java.lang.String key)
        Get a baggage item from the currently active OpenTracing Span (if there is one).

        Note: The baggage key is case-insensitive.

        Returns null if there is no such item for the key, or if there is no active Span.

        Parameters:
        key - the (case-insenstive) key associated with the baggage item
        Returns:
        the baggage item identified by the given key, or null if not found
      • baggageItems

        public static java.lang.Iterable<java.util.Map.Entry<java.lang.String,​java.lang.String>> baggageItems()
        Get all baggage items propagating with the currently active OpenTracing SpanContext (if there is one).
        Returns:
        all active baggage items
        See Also:
        setBaggageItem(String, String), getBaggageItem(String)