Class SpanManager
java.lang.Object
com.loomcache.server.tracing.SpanManager
Comprehensive span management for distributed tracing.
Features
- Create, start, and end spans with automatic duration tracking - Parent-child span relationships - Span attributes (key-value tags) - Span kinds: CLIENT, SERVER, INTERNAL, PRODUCER, CONSUMER - Span events/annotations with attributes - Active span tracking per virtual thread - Thread-safe concurrent operationsUsage
SpanManager.initialize();
Span span = SpanManager.createSpan("cache.get", SpanKind.INTERNAL);
try {
span.setAttribute("key", "myKey");
span.setAttribute("partitionId", 5);
span.addEvent("cache_lookup", Map.of("found", "true"));
span.setStatus(SpanStatus.OK);
} catch (Exception e) {
span.setStatus(SpanStatus.ERROR);
} finally {
SpanManager.endSpan(span);
}
- Since:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classSpan record containing all span information.static final recordSpan event record.static enumSpan kind enumeration.static enumSpan status enumeration. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidClear all active spans (typically for testing).static SpanManager.SpancreateSpan(String operationName, SpanManager.SpanKind kind) Create a new span.static voidendSpan(SpanManager.Span span) End a span and remove it from active tracking.static @Nullable SpanManager.SpanGet the currently active span for the current thread.static intGet total number of active spans.static Map<String, SpanManager.Span> Get all active spans (for testing).static voidInitialize the SpanManager.static voidsetActiveSpan(@Nullable SpanManager.Span span) Set the active span for the current scope.
-
Constructor Details
-
SpanManager
public SpanManager()
-
-
Method Details
-
initialize
public static void initialize()Initialize the SpanManager. -
createSpan
Create a new span.- Parameters:
operationName- the name of the operationkind- the span kind- Returns:
- a new Span
-
endSpan
End a span and remove it from active tracking.- Parameters:
span- the span to end
-
getActiveSpan
Get the currently active span for the current thread.- Returns:
- the active span, or null if none is active
-
setActiveSpan
Set the active span for the current scope. This is typically called internally by scope management.- Parameters:
span- the span to set as active
-
getActiveSpans
Get all active spans (for testing).- Returns:
- a copy of the active spans map
-
clearActiveSpans
public static void clearActiveSpans()Clear all active spans (typically for testing). -
getActiveSpanCount
public static int getActiveSpanCount()Get total number of active spans.
-