-
@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 theSpans that might be closed automatically or manually. As such aSpancan be marked as auto ended which will leave theSpanopen, but remember theendTime. If theSpanis then marked as leaked then its "auto end" time is used to close it.
-
-
Constructor Summary
Constructors Constructor Description SpanTracker()
-
Method Summary
Modifier and Type Method Description final SpanImplget(Object token, Enum<?> subToken)final SpanImplassociate(Object token, Enum<?> subToken, SpanImpl span)Track a SpanImplagainst a specified token object, and an optional subToken Enum, returning the actualSpanbeing tracked.final SpanImplassociate(Object token, Enum<?> subToken, Function0<SpanImpl> createSpan)Ensure that the specified tokenis tracked by thisSpanTrackercreating a newSpanif required (by calling createSpan).final SpanImplremoveAssociation(Object token, Enum<?> subToken)final UnitmarkSpanAutomaticEnd(Object token, Enum<?> subToken)Mark when a Spanwould have been ended automatically.final BooleanmarkSpanLeaked(Object token, Enum<?> subToken)Attempt to mark a tracked Spanas "leaked", closing it with its (automatic end)markSpanAutomaticEnd.final UnitendSpan(Object token, Enum<?> subToken, Long endTime)End the tracking of a Spanmarking itsendTimeif it has not already been closed.final UnitendAllSpans(Object token, Long endTime)End all spans associated with the given token or any subTokens.final UnitdiscardAllSpans(Object token)Discard & remove all spans associated with the given token. -
-
Method Detail
-
associate
final SpanImpl associate(Object token, Enum<?> subToken, Function0<SpanImpl> createSpan)
Ensure that the specified
tokenis tracked by thisSpanTrackercreating a newSpanif required (by calling createSpan). If thetokenalready has an associatedSpanthen that is returned, otherwise createSpan is used.Note: in race scenarios the createSpan may be invoked and the resulting
Spandiscarded, the currently trackedSpanwill however always be returned.
-
removeAssociation
final SpanImpl removeAssociation(Object token, Enum<?> subToken)
-
markSpanAutomaticEnd
final Unit markSpanAutomaticEnd(Object token, Enum<?> subToken)
Mark when a
Spanwould have been ended automatically. If the associatedSpanis later marked as leaked then itsendTimewill 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
Spanas "leaked", closing it with its (automatic end)markSpanAutomaticEnd. Returnstrueif theSpanwas marked as leaked, orfalseif theSpanwas already considered to be closed (or was not tracked).
-
endSpan
final Unit endSpan(Object token, Enum<?> subToken, Long endTime)
End the tracking of a
Spanmarking itsendTimeif 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)
-
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.
-
-
-
-