Skip to content

Instantly share code, notes, and snippets.

@badboy
Last active April 8, 2019 15:35
Show Gist options
  • Save badboy/7361520100c06e83afee04fc87d17731 to your computer and use it in GitHub Desktop.
Save badboy/7361520100c06e83afee04fc87d17731 to your computer and use it in GitHub Desktop.
❯ cargo run --example sample
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `/Users/jrediger/mozilla/src/glean.rs/target/debug/examples/sample`
{
  "bool": {
    "flags.a11yEnabled": true
  },
  "string": {
    "app.clientId": "c0ffee",
    "global_metric": "I can set this",
    "local_metric": "and set this too"
  }
}
use lazy_static::lazy_static;
use glean_core::metrics::{self, StringMetric, CommonMetricData};
lazy_static! {
pub static ref GLOBAL_METRIC : StringMetric = StringMetric::new(CommonMetricData { name: "global_metric".into() });
}
fn main() {
let local_metric : StringMetric = StringMetric::new(CommonMetricData { name: "local_metric".into() });
metrics::flags::a11yEnabled.set(true);
metrics::app::clientId.set("c0ffee");
GLOBAL_METRIC.set("I can set this");
local_metric.set("and set this too");
println!("{}", metrics::StorageManager.dump());
}
use std::collections::HashMap;
pub struct CommonMetricData {
name: String,
}
pub struct StringStorageImpl {
store: HashMap<String, String>,
}
impl StringStorageImpl {
fn new() -> Self {
Self {
store: HashMap::new()
}
}
fn record(&mut self, data: &CommonMetricData, value: String) {
let name = data.name.clone();
self.store.insert(name, value);
}
fn dump(&self) -> JsonValue {
json!(self.store)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment