-
Notifications
You must be signed in to change notification settings - Fork 0
Observability
Jeffrie Budde edited this page Nov 25, 2025
·
1 revision
Logging, tracing, and metrics guidance. See Middleware Cookbook for logging middleware patterns.
use tracing_subscriber::{fmt, EnvFilter};
fn init_tracing() {
fmt()
.with_env_filter(EnvFilter::from_default_env().add_directive(tracing::Level::INFO.into()))
.with_target(false)
.init();
}- Recommended env vars:
RUST_LOG=infofor normal use,RUST_LOG=fastrmcp=debug,tower_http=debugfor transport debugging. - Add
LoggingMiddlewarefor structured request/response logs around handlers.
- Request:
method,id,tool/resource/prompt name,client.name,client.version,connection_id(SSE/WS),latency_ms. - Response:
id,status(ok/error),error.code,error.message,subscription_id(for notifications). - Transport:
connection_id,remote_addr(if available),protocol(stdio/sse/ws),close_reason. - Context logs: use
ctx.log_info/debug/warning/errorto emit MCP notifications back to clients.
- Not built-in yet; recommended patterns:
- Add a metrics middleware (see Metrics example in
docs/MIDDLEWARE.md): counters for total requests/errors and histograms for latency. - Expose Prometheus via
axumroute in web transports. - Track subscription counts via
subscription_manager().subscription_count()and per-URI counts. - Emit progress via
ctx.report_progress(...)for long-running tools.
- Add a metrics middleware (see Metrics example in
- Enable request/response logging with
LoggingMiddleware::requests_only()during input validation debugging to avoid noisy responses. - For schema issues, log the deserialized params in the tool and return
InvalidParamswith a concise message. - Web transports: set
tower_http=debugand inspect SSE frames/WS frames in browser devtools. - Reproduce with the examples to isolate framework vs. app issues; see Examples.
Related: Troubleshooting • Security for auth/rate limit logging.