From 777f33e212d4b5a35ff7c6f011d2a3943bf6e778 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Thu, 26 Dec 2024 11:12:47 -0800 Subject: [PATCH] notmuch: add instrumentation to most public methods --- Cargo.lock | 1 + notmuch/Cargo.toml | 1 + notmuch/src/lib.rs | 13 +++++++++++++ 3 files changed, 15 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index eadfb82..c86e76c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3393,6 +3393,7 @@ dependencies = [ "serde", "serde_json", "thiserror 1.0.69", + "tracing", ] [[package]] diff --git a/notmuch/Cargo.toml b/notmuch/Cargo.toml index 922d281..ffd6d81 100644 --- a/notmuch/Cargo.toml +++ b/notmuch/Cargo.toml @@ -10,6 +10,7 @@ log = "0.4.14" serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0", features = ["unbounded_depth"] } thiserror = "1.0.30" +tracing = "0.1.41" [dev-dependencies] itertools = "0.10.1" diff --git a/notmuch/src/lib.rs b/notmuch/src/lib.rs index fe5704a..5763a18 100644 --- a/notmuch/src/lib.rs +++ b/notmuch/src/lib.rs @@ -215,6 +215,7 @@ use std::{ use log::{error, info}; use serde::{Deserialize, Serialize}; +use tracing::instrument; /// # Number of seconds since the Epoch pub type UnixTime = isize; @@ -474,6 +475,7 @@ impl Notmuch { } } + #[instrument(skip_all)] pub fn new(&self) -> Result, NotmuchError> { self.run_notmuch(["new"]) } @@ -482,6 +484,7 @@ impl Notmuch { self.run_notmuch(std::iter::empty::<&str>()) } + #[instrument(skip_all, fields(query=query))] pub fn tags_for_query(&self, query: &str) -> Result, NotmuchError> { let res = self.run_notmuch(["search", "--format=json", "--output=tags", query])?; Ok(serde_json::from_slice(&res)?) @@ -491,16 +494,19 @@ impl Notmuch { self.tags_for_query("*") } + #[instrument(skip_all, fields(tag=tag,search_term=search_term))] pub fn tag_add(&self, tag: &str, search_term: &str) -> Result<(), NotmuchError> { self.run_notmuch(["tag", &format!("+{tag}"), search_term])?; Ok(()) } + #[instrument(skip_all, fields(tag=tag,search_term=search_term))] pub fn tag_remove(&self, tag: &str, search_term: &str) -> Result<(), NotmuchError> { self.run_notmuch(["tag", &format!("-{tag}"), search_term])?; Ok(()) } + #[instrument(skip_all, fields(query=query,offset=offset,limit=limit))] pub fn search( &self, query: &str, @@ -524,6 +530,7 @@ impl Notmuch { })) } + #[instrument(skip_all, fields(query=query))] pub fn count(&self, query: &str) -> Result { // NOTE: --output=threads is technically more correct, but really slow // TODO: find a fast thread count path @@ -536,6 +543,7 @@ impl Notmuch { .unwrap_or(0)) } + #[instrument(skip_all, fields(query=query))] pub fn show(&self, query: &str) -> Result { let slice = self.run_notmuch([ "show", @@ -554,6 +562,7 @@ impl Notmuch { Ok(val) } + #[instrument(skip_all, fields(query=query,part=part))] pub fn show_part(&self, query: &str, part: usize) -> Result { let slice = self.run_notmuch([ "show", @@ -573,20 +582,24 @@ impl Notmuch { Ok(val) } + #[instrument(skip_all, fields(id=id))] pub fn show_original(&self, id: &MessageId) -> Result, NotmuchError> { self.show_original_part(id, 0) } + #[instrument(skip_all, fields(id=id,part=part))] pub fn show_original_part(&self, id: &MessageId, part: usize) -> Result, NotmuchError> { let res = self.run_notmuch(["show", "--part", &part.to_string(), id])?; Ok(res) } + #[instrument(skip_all, fields(query=query))] pub fn message_ids(&self, query: &str) -> Result, NotmuchError> { let res = self.run_notmuch(["search", "--output=messages", "--format=json", query])?; Ok(serde_json::from_slice(&res)?) } + #[instrument(skip_all, fields(query=query))] pub fn files(&self, query: &str) -> Result, NotmuchError> { let res = self.run_notmuch(["search", "--output=files", "--format=json", query])?; Ok(serde_json::from_slice(&res)?)