Package 

Class SpanTracker


  • @RestrictTo(value = {RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) 
    public final class SpanTracker
    
                        

    Container for Spans that are associated with other objects, which have their own lifecycles (Activity, Fragment, etc.). SpanTracker encapsulates tracking of the Spans that might be closed automatically or manually. As such a Span can be marked as auto ended which will leave the Span open, but remember the endTime. If the Span is then marked as leaked then its "auto end" time is used to close it.

    • Constructor Detail

      • SpanTracker

        SpanTracker()
    • Method Detail

      • associate

         final SpanImpl associate(Object token, Enum<?> subToken, SpanImpl span)

        Track a SpanImpl against a specified token object, and an optional subToken Enum, returning the actual Span being tracked. This function may discard span if the given token is already being tracked, if this is the case the tracked span will be returned.

      • associate

         final SpanImpl associate(Object token, Enum<?> subToken, Function0<SpanImpl> createSpan)

        Ensure that the specified token is tracked by this SpanTracker creating a new Span if required (by calling createSpan). If the token already has an associated Span then that is returned, otherwise createSpan is used.

        Note: in race scenarios the createSpan may be invoked and the resulting Span discarded, the currently tracked Span will however always be returned.

      • markSpanAutomaticEnd

         final Unit markSpanAutomaticEnd(Object token, Enum<?> subToken)

        Mark when a Span would have been ended automatically. If the associated Span is later marked as leaked then its endTime will be set to the time that this function was last called. Otherwise this value will be discarded.

      • markSpanLeaked

         final Boolean markSpanLeaked(Object token, Enum<?> subToken)

        Attempt to mark a tracked Span as "leaked", closing it with its (automatic end)markSpanAutomaticEnd. Returns true if the Span was marked as leaked, or false if the Span was already considered to be closed (or was not tracked).

      • endSpan

         final Unit endSpan(Object token, Enum<?> subToken, Long endTime)

        End the tracking of a Span marking its endTime if it has not already been closed. This must be called in order to ensure tokens can be garbage-collected.

      • endAllSpans

         final Unit endAllSpans(Object token, Long endTime)

        End all spans associated with the given token or any subTokens. This will attempt to use autoEndTimes where they are available, but will otherwise fallback to using endTime for each of the spans that get closed.

      • discardAllSpans

         final Unit discardAllSpans(Object token)

        Discard & remove all spans associated with the given token. This will result in any associated spans being discarded, any of their child spans that have already been closed will have no valid parent span and will also be discarded by the server-side.