move FoundIn to observability.rs

This commit is contained in:
Charles Hall 2024-06-04 12:24:01 -07:00
parent 0bd2c43dab
commit 22dd7f1a54
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
9 changed files with 43 additions and 53 deletions

View file

@ -245,35 +245,6 @@ pub(crate) fn truncate_str_for_debug(
}
}
/// Type to record cache performance in a tracing span field.
pub(crate) enum FoundIn {
/// Found in cache
Cache,
/// Cache miss, but it was in the database. The cache has been updated.
Database,
/// Cache and database miss, but another server had it. The cache has been
/// updated.
Remote,
/// The entry could not be found anywhere.
Nothing,
}
impl FoundIn {
fn value(&self) -> &'static str {
match self {
FoundIn::Cache => "hit",
FoundIn::Database => "miss-database",
FoundIn::Remote => "miss-remote",
FoundIn::Nothing => "not-found",
}
}
// TODO: use tracing::Value instead if it ever becomes accessible
pub(crate) fn record(&self, field: &str) {
tracing::Span::current().record(field, self.value());
}
}
#[cfg(test)]
mod tests {
use crate::utils::truncate_str_for_debug;