From 201901e9cc14097d2c06414a4edab11a7b099d9b Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Mon, 22 Jan 2024 14:29:33 +0100 Subject: [PATCH] WIP: Add a trait method for error recording that's exposed on every metric type TODO: - Add it to all metrics - Test it --- glean-core/src/glean.udl | 2 ++ glean-core/src/lib.rs | 1 + glean-core/src/metrics/mod.rs | 10 +++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/glean-core/src/glean.udl b/glean-core/src/glean.udl index e31de42e70..48970c6571 100644 --- a/glean-core/src/glean.udl +++ b/glean-core/src/glean.udl @@ -328,6 +328,8 @@ interface CounterMetric { i32? test_get_value(optional string? ping_name = null); i32 test_get_num_recorded_errors(ErrorType error); + + void record_error(ErrorType error, i32 count); }; // Different resolutions supported by the time related metric types diff --git a/glean-core/src/lib.rs b/glean-core/src/lib.rs index b7f9d73beb..6637b967a9 100644 --- a/glean-core/src/lib.rs +++ b/glean-core/src/lib.rs @@ -1213,6 +1213,7 @@ pub fn glean_enable_logging_to_fd(_fd: u64) { #[allow(missing_docs)] mod ffi { use super::*; + use crate::metrics::MetricType; uniffi::include_scaffolding!("glean"); type CowString = Cow<'static, str>; diff --git a/glean-core/src/metrics/mod.rs b/glean-core/src/metrics/mod.rs index 92001efd2a..0dc07be91e 100644 --- a/glean-core/src/metrics/mod.rs +++ b/glean-core/src/metrics/mod.rs @@ -43,7 +43,7 @@ pub use crate::event_database::RecordedEvent; use crate::histogram::{Functional, Histogram, PrecomputedExponential, PrecomputedLinear}; pub use crate::metrics::datetime::Datetime; use crate::util::get_iso_time_string; -use crate::Glean; +use crate::{error_recording, Glean}; pub use self::boolean::BooleanMetric; pub use self::counter::CounterMetric; @@ -229,6 +229,14 @@ pub trait MetricType { // Return a boolean indicating whether or not the metric should be recorded current_disabled == 0 } + + /// Record an error for this + fn record_error(&self, error: crate::ErrorType, count: i32) { + let meta = self.meta().clone(); + crate::launch_with_glean(move |glean| { + error_recording::record_error(glean, &meta, error, "external error", count); + }) + } } impl Metric {