Package com.tnsai.mcp.observability
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:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidend()Ends this span, recording its duration.Returns the span ID for this span.Returns the trace ID for this span.voidRecords an exception on this span.voidsetAttribute(String key, double value) Sets a double attribute on this span.voidsetAttribute(String key, long value) Sets a long attribute on this span.voidsetAttribute(String key, String value) Sets a string attribute on this span.voidsetStatus(McpSpan.SpanStatus status) Sets the status of this span.
-
Method Details
-
setAttribute
Sets a string attribute on this span.- Parameters:
key- the attribute keyvalue- the attribute value
-
setAttribute
Sets a long attribute on this span.- Parameters:
key- the attribute keyvalue- the attribute value
-
setAttribute
Sets a double attribute on this span.- Parameters:
key- the attribute keyvalue- the attribute value
-
setStatus
Sets the status of this span.- Parameters:
status- the span status
-
recordException
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
-