From 467ac138e3319ec041c63fbf5d560180c0b2259d Mon Sep 17 00:00:00 2001 From: rays Date: Fri, 27 Nov 2026 23:24:26 -0500 Subject: [PATCH] A database step's trace says how long it waited and how long Postgres took (#501) All Subscriptions' Unread page spends 170-210 ms in its 'page' step one time in ten, where the query itself takes 24-31 ms on production and the pool's wait metric stays under 5 ms. The step now carries wait_ms and query_ms, the same split #367's metrics make, so a slow trace names which. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01RqkrVCCH8YcP2Y3i8VNYWA --- crates/ipx/src/db.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/ipx/src/db.rs b/crates/ipx/src/db.rs index 5e9532e..08a6a10 100644 --- a/crates/ipx/src/db.rs +++ b/crates/ipx/src/db.rs @@ -327,7 +327,13 @@ thread_local! { /// shortcut: half the queries, measured by difference; a wrapper on sqlx's pool would see all. fn waited(started: std::time::Instant) { if let Some(q) = LAST_QUERY.take() { - crate::metrics::DB_WAIT.observe("", started.elapsed().saturating_sub(q).as_secs_f64()); + let wait = started.elapsed().saturating_sub(q); + crate::metrics::DB_WAIT.observe("", wait.as_secs_f64()); + // On the step too, so a slow one in Tempo says whether it waited for a connection or for + // Postgres: the metric's spread could not say which of a page's queries it was. + let span = tracing::Span::current(); + span.record("wait_ms", wait.as_millis() as u64); + span.record("query_ms", q.as_millis() as u64); } } @@ -3074,7 +3080,11 @@ pub enum EntryFlag { /// A span for one step of a request or a scan, and none outside one: the healthcheck and the page's /// live updates run the same code, and every call there would be a trace of its own. pub fn step(of: &'static str) -> tracing::Span { - if tracing::Span::current().is_none() { tracing::Span::none() } else { tracing::info_span!("step", of) } + if tracing::Span::current().is_none() { + tracing::Span::none() + } else { + tracing::info_span!("step", of, wait_ms = tracing::field::Empty, query_ms = tracing::field::Empty) + } } /// A file on disk with no DeadAir copy made since it was downloaded (issue #171).