log: Add tracing events through core for future debugability.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user