summaryrefslogtreecommitdiffstats
path: root/third_party/rust/glean-core/src/metrics/object.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/glean-core/src/metrics/object.rs')
-rw-r--r--third_party/rust/glean-core/src/metrics/object.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/third_party/rust/glean-core/src/metrics/object.rs b/third_party/rust/glean-core/src/metrics/object.rs
index 6071e2b33a..58c8a04c73 100644
--- a/third_party/rust/glean-core/src/metrics/object.rs
+++ b/third_party/rust/glean-core/src/metrics/object.rs
@@ -48,6 +48,10 @@ impl ObjectMetric {
/// * `value` - the value to set.
#[doc(hidden)]
pub fn set_sync(&self, glean: &Glean, value: JsonValue) {
+ if !self.should_record(glean) {
+ return;
+ }
+
let value = Metric::Object(serde_json::to_string(&value).unwrap());
glean.storage().record(glean, &self.meta, &value)
}
@@ -65,6 +69,31 @@ impl ObjectMetric {
crate::launch_with_glean(move |glean| metric.set_sync(glean, value))
}
+ /// Sets to the specified structure.
+ ///
+ /// Parses the passed JSON string.
+ /// If it can't be parsed into a valid object it records an invalid value error.
+ ///
+ /// Note: This does not check the structure. This needs to be done by the wrapper.
+ ///
+ /// # Arguments
+ ///
+ /// * `object` - JSON representation of the object to set.
+ pub fn set_string(&self, object: String) {
+ let metric = self.clone();
+ crate::launch_with_glean(move |glean| {
+ let object = match serde_json::from_str(&object) {
+ Ok(object) => object,
+ Err(_) => {
+ let msg = "Value did not match predefined schema";
+ record_error(glean, &metric.meta, ErrorType::InvalidValue, msg, None);
+ return;
+ }
+ };
+ metric.set_sync(glean, object)
+ })
+ }
+
/// Record an `InvalidValue` error for this metric.
///
/// Only to be used by the RLB.