Improved tracing (part 1)

This commit is contained in:
mdecimus
2024-07-23 12:44:14 +02:00
parent 9c23774aa5
commit ae7cadc27d
224 changed files with 2352 additions and 1832 deletions

View File

@@ -41,7 +41,6 @@ pub async fn exec_untrain(ctx: PluginContext<'_>) -> Variable {
}
async fn train(ctx: PluginContext<'_>, is_train: bool) -> Variable {
let span: &tracing::Span = ctx.span;
let store = match &ctx.arguments[0] {
Variable::String(v) if !v.is_empty() => ctx.core.storage.lookups.get(v.as_ref()),
_ => Some(&ctx.core.storage.lookup),
@@ -51,7 +50,7 @@ async fn train(ctx: PluginContext<'_>, is_train: bool) -> Variable {
store
} else {
tracing::warn!(
parent: span,
context = "sieve:bayes_train",
event = "failed",
reason = "Unknown store id",
@@ -63,7 +62,7 @@ async fn train(ctx: PluginContext<'_>, is_train: bool) -> Variable {
let is_spam = ctx.arguments[2].to_bool();
if text.is_empty() {
tracing::debug!(
parent: span,
context = "sieve:bayes_train",
event = "failed",
reason = "Empty message",
@@ -82,7 +81,7 @@ async fn train(ctx: PluginContext<'_>, is_train: bool) -> Variable {
);
if model.weights.is_empty() {
tracing::debug!(
parent: span,
context = "sieve:bayes_train",
event = "failed",
reason = "No weights found",
@@ -91,7 +90,7 @@ async fn train(ctx: PluginContext<'_>, is_train: bool) -> Variable {
}
tracing::debug!(
parent: span,
context = "sieve:bayes_train",
event = "train",
is_spam = is_spam,
@@ -152,7 +151,7 @@ async fn train(ctx: PluginContext<'_>, is_train: bool) -> Variable {
}
pub async fn exec_classify(ctx: PluginContext<'_>) -> Variable {
let span = ctx.span;
let store = match &ctx.arguments[0] {
Variable::String(v) if !v.is_empty() => ctx.core.storage.lookups.get(v.as_ref()),
_ => Some(&ctx.core.storage.lookup),
@@ -161,7 +160,7 @@ pub async fn exec_classify(ctx: PluginContext<'_>) -> Variable {
store
} else {
tracing::warn!(
parent: span,
context = "sieve:bayes_classify",
event = "failed",
reason = "Unknown store id",
@@ -198,7 +197,7 @@ pub async fn exec_classify(ctx: PluginContext<'_>) -> Variable {
(weights.spam, weights.ham)
} else {
tracing::warn!(
parent: span,
context = "sieve:classify",
event = "failed",
reason = "Failed to obtain training counts",
@@ -209,7 +208,7 @@ pub async fn exec_classify(ctx: PluginContext<'_>) -> Variable {
// Make sure we have enough training data
if spam_learns < classifier.min_learns || ham_learns < classifier.min_learns {
tracing::debug!(
parent: span,
context = "sieve:bayes_classify",
event = "skip-classify",
reason = "Not enough training data",
@@ -249,7 +248,7 @@ pub async fn exec_is_balanced(ctx: PluginContext<'_>) -> Variable {
return true.into();
}
let span = ctx.span;
let store = match &ctx.arguments[0] {
Variable::String(v) if !v.is_empty() => ctx.core.storage.lookups.get(v.as_ref()),
_ => Some(&ctx.core.storage.lookup),
@@ -258,7 +257,7 @@ pub async fn exec_is_balanced(ctx: PluginContext<'_>) -> Variable {
store
} else {
tracing::warn!(
parent: span,
context = "sieve:bayes_is_balanced",
event = "failed",
reason = "Unknown store id",
@@ -275,7 +274,7 @@ pub async fn exec_is_balanced(ctx: PluginContext<'_>) -> Variable {
(weights.spam as f64, weights.ham as f64)
} else {
tracing::warn!(
parent: span,
context = "sieve:bayes_is_balanced",
event = "failed",
reason = "Failed to obtain training counts",
@@ -294,7 +293,7 @@ pub async fn exec_is_balanced(ctx: PluginContext<'_>) -> Variable {
};
tracing::debug!(
parent: span,
context = "sieve:bayes_is_balanced",
event = "result",
is_balanced = %result,

View File

@@ -15,7 +15,6 @@ pub fn register(plugin_id: u32, fnc_map: &mut FunctionMap) {
}
pub async fn exec(ctx: PluginContext<'_>) -> Variable {
let span = ctx.span.clone();
let mut arguments = ctx.arguments.into_iter();
tokio::task::spawn_blocking(move || {
@@ -36,7 +35,6 @@ pub async fn exec(ctx: PluginContext<'_>) -> Variable {
Ok(result) => result.status.success(),
Err(err) => {
tracing::warn!(
parent: span,
context = "sieve",
event = "execute-failed",
reason = %err,

View File

@@ -67,7 +67,6 @@ pub async fn exec(ctx: PluginContext<'_>) -> Variable {
}
} else {
tracing::debug!(
parent: ctx.span,
context = "sieve:lookup",
event = "failed",
reason = "Unknown lookup id",
@@ -93,7 +92,6 @@ pub async fn exec_get(ctx: PluginContext<'_>) -> Variable {
.unwrap_or_default()
} else {
tracing::debug!(
parent: ctx.span,
context = "sieve:key_get",
event = "failed",
reason = "Unknown store or lookup id",
@@ -131,7 +129,6 @@ pub async fn exec_set(ctx: PluginContext<'_>) -> Variable {
.into()
} else {
tracing::warn!(
parent: ctx.span,
context = "sieve:key_set",
event = "failed",
reason = "Unknown store id",
@@ -293,7 +290,7 @@ pub async fn exec_remote(ctx: PluginContext<'_>) -> Variable {
}
Err(err) => {
tracing::warn!(
parent: ctx.span,
context = "sieve:key_exists_http",
event = "failed",
resource = resource.as_ref(),
@@ -309,7 +306,6 @@ pub async fn exec_remote(ctx: PluginContext<'_>) -> Variable {
}
tracing::debug!(
parent: ctx.span,
context = "sieve:key_exists_http",
event = "fetch",
resource = resource.as_ref(),
@@ -322,7 +318,7 @@ pub async fn exec_remote(ctx: PluginContext<'_>) -> Variable {
}
Err(err) => {
tracing::warn!(
parent: ctx.span,
context = "sieve:key_exists_http",
event = "failed",
resource = resource.as_ref(),
@@ -333,7 +329,7 @@ pub async fn exec_remote(ctx: PluginContext<'_>) -> Variable {
}
Ok(response) => {
tracing::warn!(
parent: ctx.span,
context = "sieve:key_exists_http",
event = "failed",
resource = resource.as_ref(),
@@ -342,7 +338,7 @@ pub async fn exec_remote(ctx: PluginContext<'_>) -> Variable {
}
Err(err) => {
tracing::warn!(
parent: ctx.span,
context = "sieve:key_exists_http",
event = "failed",
resource = resource.as_ref(),
@@ -384,7 +380,6 @@ pub async fn exec_local_domain(ctx: PluginContext<'_>) -> Variable {
.into();
} else {
tracing::warn!(
parent: ctx.span,
context = "sieve:is_local_domain",
event = "failed",
reason = "Unknown directory",

View File

@@ -24,7 +24,7 @@ use super::ScriptModification;
type RegisterPluginFnc = fn(u32, &mut FunctionMap) -> ();
pub struct PluginContext<'x> {
pub span: &'x tracing::Span,
pub session_id: u64,
pub core: &'x Core,
pub cache: &'x ScriptCache,
pub message: &'x Message<'x>,

View File

@@ -77,7 +77,6 @@ pub async fn exec(ctx: PluginContext<'_>) -> Variable {
}
}
let span = ctx.span;
let address = ctx.arguments[0].to_string();
let timeout = Duration::from_secs((ctx.arguments[1].to_integer() as u64).clamp(5, 60));
// Send message to address
@@ -85,7 +84,6 @@ pub async fn exec(ctx: PluginContext<'_>) -> Variable {
Ok(response) => response.into(),
Err(err) => {
tracing::debug!(
parent: span,
context = "sieve:pyzor_check",
event = "failed",
reason = %err,

View File

@@ -17,8 +17,6 @@ pub fn register(plugin_id: u32, fnc_map: &mut FunctionMap) {
}
pub async fn exec(ctx: PluginContext<'_>) -> Variable {
let span = ctx.span;
// Obtain store name
let store = match &ctx.arguments[0] {
Variable::String(v) if !v.is_empty() => ctx.core.storage.lookups.get(v.as_ref()),
@@ -29,7 +27,6 @@ pub async fn exec(ctx: PluginContext<'_>) -> Variable {
store
} else {
tracing::warn!(
parent: span,
context = "sieve:query",
event = "failed",
reason = "Unknown store",
@@ -42,7 +39,6 @@ pub async fn exec(ctx: PluginContext<'_>) -> Variable {
let query = ctx.arguments[1].to_string();
if query.is_empty() {
tracing::warn!(
parent: span,
context = "sieve:query",
event = "invalid",
reason = "Empty query string",