feat: Add telemetry, timing, and detailed logging across server, stub, and nvim-core

This commit is contained in:
Riz Ashraf committed 2026-09-19 04:13:07 +01:00
1 parent 26cf6cee80
commit 2fdb03c302
4 files changed
+62 -4

No files matched your search

+25 -1
View File
@@ -33,10 +33,23 @@ pub struct MemoryHandler {
impl MemoryHandler {
pub async fn handle_request(&self, req: serde_json::Value) -> Option<serde_json::Value> {
let start_time = std::time::Instant::now();
let id = req.get("id").cloned().unwrap_or(serde_json::Value::Null);
let id_clone = id.clone();
let method = req.get("method").and_then(|m| m.as_str()).unwrap_or("");
tracing::debug!(">>> [Server] Handling MCP request method: {}", method);
let tool_name = if method == "tools/call" {
req.get("params").and_then(|p| p.get("name")).and_then(|n| n.as_str()).unwrap_or("unknown")
} else {
""
};
if method == "tools/call" {
tracing::info!(">>> [Server] Handling MCP tool call: {} (id: {})", tool_name, id);
} else {
tracing::debug!(">>> [Server] Handling MCP request method: {}", method);
}
tracing::trace!(">>> [Server] Full MCP Request payload: {}", req.to_string());
let response = match method {
"server/discover" => {
@@ -1648,6 +1661,17 @@ impl MemoryHandler {
}
};
let elapsed = start_time.elapsed();
if method == "tools/call" {
let is_error = response.as_ref().map_or(false, |r| r.get("error").is_some() || r.get("result").and_then(|res| res.get("isError")).and_then(|e| e.as_bool()).unwrap_or(false));
tracing::info!("<<< [Server] MCP tool call {} (id: {}) completed in {:?} [Error: {}]", tool_name, id_clone, elapsed, is_error);
// Broadcast completion latency to the UI Activity Feed
let status_msg = if is_error { "with error" } else { "successfully" };
self.state.broadcast_activity(&format!("Tool {} completed {} in {:?}", tool_name, status_msg, elapsed));
} else {
tracing::debug!("<<< [Server] MCP request method {} completed in {:?}", method, elapsed);
}
tracing::trace!("Returning response from handle_request: {:?}", response);
response
}
+1
View File
@@ -263,6 +263,7 @@ fn run_server(state: Arc<MemoryState>) -> Result<(), Box<dyn std::error::Error>>
"/shutdown",
post(|| async move {
std::thread::spawn(|| {
tracing::info!("Received shutdown request via /shutdown endpoint. Exiting process cleanly.");
std::thread::sleep(std::time::Duration::from_millis(100));
std::process::exit(0);
});