Interface McpTracer

All Known Implementing Classes:
LoggingMcpTracer, NoopMcpTracer

public interface McpTracer
Abstraction for creating tracing spans in MCP operations.

Provides a pluggable tracing interface that decouples the MCP module from any specific tracing implementation. Users can choose:

  • noop() - Zero-overhead no-op tracer for production without tracing
  • logging() - SLF4J-based tracer that logs span lifecycle events
  • Custom implementation backed by OpenTelemetry, Zipkin, etc.

Example usage:


 // No-op tracer (zero overhead)
 McpTracer tracer = McpTracer.noop();

 // Logging tracer (for development/debugging)
 McpTracer tracer = McpTracer.logging();

 // Use with TracingMcpClient
 TracingMcpClient tracingClient = new TracingMcpClient(client, tracer);
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static McpTracer
    Returns a logging tracer that records span events via SLF4J.
    static McpTracer
    Returns a no-op tracer that performs no work and has zero overhead.
    startSpan(String operationName)
    Starts a new root span with the given operation name.
    startSpan(String operationName, McpSpan parent)
    Starts a new child span with the given operation name and parent.
  • Method Details

    • startSpan

      McpSpan startSpan(String operationName)
      Starts a new root span with the given operation name.
      Parameters:
      operationName - the name of the operation being traced
      Returns:
      a new span that must be ended via McpSpan.end()
    • startSpan

      McpSpan startSpan(String operationName, McpSpan parent)
      Starts a new child span with the given operation name and parent.
      Parameters:
      operationName - the name of the operation being traced
      parent - the parent span
      Returns:
      a new child span that must be ended via McpSpan.end()
    • noop

      static McpTracer noop()
      Returns a no-op tracer that performs no work and has zero overhead.
      Returns:
      the singleton no-op tracer instance
    • logging

      static McpTracer logging()
      Returns a logging tracer that records span events via SLF4J.
      Returns:
      a new logging tracer instance