❯ 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"
}
}
Last active
April 8, 2019 15:35
-
-
Save badboy/7361520100c06e83afee04fc87d17731 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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