Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1691073 - Expose method to record errors for any metric type #2766

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions glean-core/src/glean.udl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions glean-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
10 changes: 9 additions & 1 deletion glean-core/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Loading