Commit 0542e950 authored by Jan-Erik Rediger's avatar Jan-Erik Rediger
Browse files

Bug 1632131 - Implement a string metric for the in-tree Glean API. r=chutten

Currently there's no user, so we do some trickery to actually make sure
it gets compiled.

It also lacks a test, that will follow in the next commit,
as it's a bit more complex to set up a Glean instance for a test run.

Differential Revision: https://phabricator.services.mozilla.com/D72128
parent 2291f694
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -1413,6 +1413,7 @@ checksum = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
name = "fog"
version = "0.1.0"
dependencies = [
 "glean",
 "glean-core",
 "log",
 "nserror",
@@ -1810,6 +1811,14 @@ dependencies = [
 "gl_generator",
]

[[package]]
name = "glean"
version = "0.1.0"
dependencies = [
 "glean-core",
 "log",
]

[[package]]
name = "glean-core"
version = "25.1.0"
+2 −1
Original line number Diff line number Diff line
[package]
name = "fog"
version = "0.1.0"
authors = ["The Mozilla Project Developers"]
authors = ["Glean SDK team <glean-team@mozilla.com>"]
edition = "2018"
license = "MPL-2.0"

@@ -13,3 +13,4 @@ nsstring = { path = "../../../xpcom/rust/nsstring" }
static_prefs = { path = "../../../modules/libpref/init/static_prefs" }
xpcom = { path = "../../../xpcom/rust/xpcom" }
once_cell = "1.2.0"
glean = { path = "./api" }
+10 −0
Original line number Diff line number Diff line
[package]
name = "glean"
version = "0.1.0"
authors = ["Glean SDK team <glean-team@mozilla.com>"]
edition = "2018"
publish = false

[dependencies]
glean-core = "25.1.0"
log = "0.4"
+29 −0
Original line number Diff line number Diff line
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! The public Glean SDK API, for Rust consumers.
//!
//! ## Example:
//!
//! ```rust,ignore
//! assert!(glean::is_upload_enabled())
//! ```

pub mod metrics;

/// Run a closure with a mutable reference to the locked global Glean object.
fn with_glean<F, R>(f: F) -> R
where
    F: FnOnce(&glean_core::Glean) -> R,
{
    let lock = glean_core::global_glean().lock().unwrap();
    f(&lock)
}

/// Determine whether upload is enabled.
///
/// See `glean_core::Glean.is_upload_enabled`.
pub fn is_upload_enabled() -> bool {
    with_glean(|glean| glean.is_upload_enabled())
}
+14 −0
Original line number Diff line number Diff line
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! The different metric types supported by the Glean SDK to handle data.

// Re-export of `glean_core` types we can re-use.
// That way a user only needs to depend on this crate, not on glean_core (and there can't be a
// version mismatch).
pub use glean_core::{CommonMetricData, Lifetime};

mod string;

pub use string::StringMetric;
Loading