log: Add tracing events through core for future debugability.

This commit is contained in:
2026-03-14 11:56:01 -04:00
parent bb3f200141
commit c6d80a9650
7 changed files with 83 additions and 12 deletions

View File

@@ -8,6 +8,7 @@ use std::time::Duration;
use tokio::sync::mpsc;
use tokio::task::JoinHandle;
use tracing::Instrument;
use crate::event::Action;
use crate::hook::{HookEvent, HookEventKind, HookHandler, HookResponse};
@@ -76,6 +77,8 @@ impl DebouncedDispatcher {
.cloned()
.unwrap_or(DebounceMode::None);
tracing::debug!(event_kind = ?kind, mode = ?mode, "dispatching hook event");
match mode {
DebounceMode::None => {
self.fire_now(event);
@@ -95,11 +98,15 @@ impl DebouncedDispatcher {
fn fire_now(&self, event: HookEvent) {
let handler = Arc::clone(&self.handler);
tokio::spawn(async move {
if let Err(e) = handler.handle(event) {
tracing::warn!(error = %e, "hook handler error");
let span = tracing::debug_span!("hook_fire", event_kind = ?event.kind());
tokio::spawn(
async move {
if let Err(e) = handler.handle(event) {
tracing::warn!(error = %e, "hook handler error");
}
}
});
.instrument(span),
);
}
fn fire_debounced(&mut self, event: HookEvent, delay: Duration, cancel: bool) {
@@ -108,19 +115,27 @@ impl DebouncedDispatcher {
self.cancel_in_flight(kind);
}
let delay_ms = delay.as_millis() as u64;
tracing::debug!(delay_ms, cancel_stale = cancel, "debounced hook scheduled");
let handler = Arc::clone(&self.handler);
let handle = tokio::spawn(async move {
tokio::time::sleep(delay).await;
if let Err(e) = handler.handle(event) {
tracing::warn!(error = %e, "hook handler error");
let span = tracing::debug_span!("hook_fire", event_kind = ?kind);
let handle = tokio::spawn(
async move {
tokio::time::sleep(delay).await;
if let Err(e) = handler.handle(event) {
tracing::warn!(error = %e, "hook handler error");
}
}
});
.instrument(span),
);
self.in_flight.insert(kind, handle);
}
fn cancel_in_flight(&mut self, kind: HookEventKind) {
if let Some(handle) = self.in_flight.remove(&kind) {
tracing::debug!(event_kind = ?kind, "cancelled in-flight hook");
handle.abort();
}
}