Interface McpSpan


public interface McpSpan
Abstraction for a tracing span in MCP operations.

Provides a lightweight tracing API that can be backed by OpenTelemetry, SLF4J logging, or a no-op implementation. This avoids forcing an OTel dependency on framework users while still enabling observability.

Typical usage:


 McpSpan span = tracer.startSpan("mcp.callTool");
 try {
     span.setAttribute("mcp.tool.name", "readFile");
     // ... do work ...
     span.setStatus(SpanStatus.OK);
 } catch (Exception e) {
     span.setStatus(SpanStatus.ERROR);
     span.recordException(e);
     throw e;
 } finally {
     span.end();
 }
 
See Also:
  • Method Details

    • setAttribute

      void setAttribute(String key, String value)
      Sets a string attribute on this span.
      Parameters:
      key - the attribute key
      value - the attribute value
    • setAttribute

      void setAttribute(String key, long value)
      Sets a long attribute on this span.
      Parameters:
      key - the attribute key
      value - the attribute value
    • setAttribute

      void setAttribute(String key, double value)
      Sets a double attribute on this span.
      Parameters:
      key - the attribute key
      value - the attribute value
    • setStatus

      void setStatus(McpSpan.SpanStatus status)
      Sets the status of this span.
      Parameters:
      status - the span status
    • recordException

      void recordException(Throwable t)
      Records an exception on this span.
      Parameters:
      t - the exception to record
    • end

      void end()
      Ends this span, recording its duration. After calling end(), no further mutations should be made.
    • getTraceId

      String getTraceId()
      Returns the trace ID for this span.
      Returns:
      the trace ID string
    • getSpanId

      String getSpanId()
      Returns the span ID for this span.
      Returns:
      the span ID string