turbomcp-telemetry
OpenTelemetry integration and observability for TurboMCP SDK.
Features
- Distributed Tracing: OpenTelemetry traces with MCP-specific span attributes
- Metrics Collection: Request counts, latencies, error rates with Prometheus export
- Structured Logging: JSON-formatted logs correlated with traces
- Tower Middleware: Automatic instrumentation for MCP request handling
Quick Start
use ;
async
Feature Flags
| Feature | Description |
|---|---|
opentelemetry |
Full OpenTelemetry integration with OTLP export |
prometheus |
Standalone Prometheus metrics (using metrics.rs) |
tower |
Tower middleware for automatic request instrumentation |
full |
All features enabled |
OpenTelemetry Integration
Enable the opentelemetry feature for full distributed tracing:
use TelemetryConfig;
let config = builder
.service_name
.otlp_endpoint
.sampling_ratio
.build;
let _guard = config.init?;
Prometheus Metrics
Enable the prometheus feature for standalone Prometheus metrics:
use TelemetryConfig;
let config = builder
.service_name
.prometheus_port
.build;
let _guard = config.init?;
// Metrics available at http://localhost:9090/metrics
Tower Middleware
Enable the tower feature for automatic request instrumentation:
use ServiceBuilder;
use ;
let config = new
.service_name
.exclude_method;
let service = new
.layer
.service;
MCP Span Attributes
The telemetry system records MCP-specific attributes on spans:
| Attribute | Description |
|---|---|
mcp.method |
MCP method name (e.g., "tools/call") |
mcp.tool.name |
Tool name for tools/call requests |
mcp.resource.uri |
Resource URI for resources/read |
mcp.prompt.name |
Prompt name for prompts/get |
mcp.request.id |
JSON-RPC request ID |
mcp.session.id |
MCP session ID |
mcp.transport |
Transport type (stdio, http, websocket) |
mcp.duration_ms |
Request duration in milliseconds |
mcp.status |
Request status (success/error) |
Pre-defined Metrics
When using the prometheus feature:
| Metric | Type | Description |
|---|---|---|
mcp_requests_total |
Counter | Total requests by method and status |
mcp_request_duration_seconds |
Histogram | Request latency distribution |
mcp_tool_calls_total |
Counter | Tool calls by name and status |
mcp_tool_duration_seconds |
Histogram | Tool execution latency |
mcp_resource_reads_total |
Counter | Resource reads by URI pattern |
mcp_active_connections |
Gauge | Current active connections |
mcp_errors_total |
Counter | Errors by kind and method |
License
MIT