Class SpanManager

java.lang.Object
com.loomcache.server.tracing.SpanManager

public final class SpanManager extends Object
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 operations

Usage

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
  • Constructor Details

    • SpanManager

      public SpanManager()
  • Method Details

    • initialize

      public static void initialize()
      Initialize the SpanManager.
    • createSpan

      public static SpanManager.Span createSpan(String operationName, SpanManager.SpanKind kind)
      Create a new span.
      Parameters:
      operationName - the name of the operation
      kind - the span kind
      Returns:
      a new Span
    • endSpan

      public static void endSpan(SpanManager.Span span)
      End a span and remove it from active tracking.
      Parameters:
      span - the span to end
    • getActiveSpan

      public static @Nullable SpanManager.Span getActiveSpan()
      Get the currently active span for the current thread.
      Returns:
      the active span, or null if none is active
    • setActiveSpan

      public static void setActiveSpan(@Nullable SpanManager.Span span)
      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

      public static Map<String, SpanManager.Span> 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.