// 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/.
//! Glean is a modern approach for recording and sending Telemetry data. //! //! It's in use at Mozilla. //! //! All documentation can be found online: //! //! ## [The Glean SDK Book](https://mozilla.github.io/glean) //! //! ## Example //! //! Initialize Glean, register a ping and then send it. //! //! ```rust,no_run //! # use glean::{ConfigurationBuilder, ClientInfoMetrics, Error, private::*}; //! let cfg = ConfigurationBuilder::new(true, "/tmp/data", "org.mozilla.glean_core.example").build(); //! glean::initialize(cfg, ClientInfoMetrics::unknown()); //! //! let prototype_ping = PingType::new("prototype", true, true, true, true, true, vec!(), vec!(), true); //! //! prototype_ping.submit(None); //! ```
use std::collections::HashMap; use std::path::Path;
mod configuration; mod core_metrics; pubmod net; pubmod private; mod system;
#[cfg(test)] mod common_test;
const LANGUAGE_BINDING_NAME: &str = "Rust";
/// Creates and initializes a new Glean object. /// /// See [`glean_core::Glean::new`] for more information. /// /// # Arguments /// /// * `cfg` - the [`Configuration`] options to initialize with. /// * `client_info` - the [`ClientInfoMetrics`] values used to set Glean /// core metrics. pubfn initialize(cfg: Configuration, client_info: ClientInfoMetrics) {
initialize_internal(cfg, client_info);
}
struct GleanEvents { /// An instance of the upload manager
upload_manager: net::UploadManager,
}
impl glean_core::OnGleanEvents for GleanEvents { fn initialize_finished(&self) { // intentionally left empty
}
fn start_metrics_ping_scheduler(&self) -> bool { // We rely on the glean-core MPS. // We always trigger an upload as it might have submitted a ping. true
}
/// Shuts down Glean in an orderly fashion. pubfn shutdown() {
glean_core::shutdown()
}
/// **DEPRECATED** Sets whether upload is enabled or not. /// /// **DEPRECATION NOTICE**: /// This API is deprecated. Use `set_collection_enabled` instead. /// /// See [`glean_core::Glean::set_upload_enabled`]. pubfn set_upload_enabled(enabled: bool) {
glean_core::glean_set_upload_enabled(enabled)
}
/// Sets whether upload is enabled or not. /// /// See [`glean_core::Glean::set_upload_enabled`]. pubfn set_collection_enabled(enabled: bool) {
glean_core::glean_set_collection_enabled(enabled)
}
/// Collects and submits a ping for eventual uploading by name. /// /// Note that this needs to be public in order for RLB consumers to /// use Glean debugging facilities. /// /// See [`glean_core::Glean.submit_ping_by_name`]. pubfn submit_ping_by_name(ping: &str, reason: Option<&str>) { let ping = ping.to_string(); let reason = reason.map(|s| s.to_string());
glean_core::glean_submit_ping_by_name(ping, reason)
}
/// Indicate that an experiment is running. Glean will then add an /// experiment annotation to the environment which is sent with pings. This /// infomration is not persisted between runs. /// /// See [`glean_core::Glean::set_experiment_active`]. pubfn set_experiment_active(
experiment_id: String,
branch: String,
extra: Option<HashMap<String, String>>,
) {
glean_core::glean_set_experiment_active(experiment_id, branch, extra.unwrap_or_default())
}
/// Indicate that an experiment is no longer running. /// /// See [`glean_core::Glean::set_experiment_inactive`]. pubfn set_experiment_inactive(experiment_id: String) {
glean_core::glean_set_experiment_inactive(experiment_id)
}
/// Dynamically set the experimentation identifier, as opposed to setting it through the configuration /// during initialization. pubfn set_experimentation_id(experimentation_id: String) {
glean_core::glean_set_experimentation_id(experimentation_id);
}
/// TEST ONLY FUNCTION. /// Gets stored experimentation id. pubfn test_get_experimentation_id() -> Option<String> {
glean_core::glean_test_get_experimentation_id()
}
/// Set the remote configuration values for the metrics' disabled property /// /// See [`glean_core::Glean::glean_apply_server_knobs_config`]. pubfn glean_apply_server_knobs_config(json: String) {
glean_core::glean_apply_server_knobs_config(json)
}
/// Performs the collection/cleanup operations required by becoming active. /// /// This functions generates a baseline ping with reason `active` /// and then sets the dirty bit. /// This should be called whenever the consuming product becomes active (e.g. /// getting to foreground). pubfn handle_client_active() {
glean_core::glean_handle_client_active()
}
/// Performs the collection/cleanup operations required by becoming inactive. /// /// This functions generates a baseline and an events ping with reason /// `inactive` and then clears the dirty bit. /// This should be called whenever the consuming product becomes inactive (e.g. /// getting to background). pubfn handle_client_inactive() {
glean_core::glean_handle_client_inactive()
}
/// TEST ONLY FUNCTION. /// Checks if an experiment is currently active. pubfn test_is_experiment_active(experiment_id: String) -> bool {
glean_core::glean_test_get_experiment_data(experiment_id).is_some()
}
/// TEST ONLY FUNCTION. /// Returns the [`RecordedExperiment`] for the given `experiment_id` or panics if /// the id isn't found. pubfn test_get_experiment_data(experiment_id: String) -> Option<RecordedExperiment> {
glean_core::glean_test_get_experiment_data(experiment_id)
}
/// Destroy the global Glean state. pub(crate) fn destroy_glean(clear_stores: bool, data_path: &Path) { let data_path = data_path.display().to_string();
glean_core::glean_test_destroy_glean(clear_stores, Some(data_path))
}
/// TEST ONLY FUNCTION. /// Resets the Glean state and triggers init again. pubfn test_reset_glean(cfg: Configuration, client_info: ClientInfoMetrics, clear_stores: bool) {
destroy_glean(clear_stores, &cfg.data_path);
initialize_internal(cfg, client_info);
glean_core::join_init();
}
/// Sets a debug view tag. /// /// When the debug view tag is set, pings are sent with a `X-Debug-ID` header with the /// value of the tag and are sent to the ["Ping Debug Viewer"](https://mozilla.github.io/glean/book/dev/core/internal/debug-pings.html). /// /// # Arguments /// /// * `tag` - A valid HTTP header value. Must match the regex: "[a-zA-Z0-9-]{1,20}". /// /// # Returns /// /// This will return `false` in case `tag` is not a valid tag and `true` otherwise. /// If called before Glean is initialized it will always return `true`. pubfn set_debug_view_tag(tag: &str) -> bool {
glean_core::glean_set_debug_view_tag(tag.to_string())
}
/// Gets the currently set debug view tag. /// /// The `debug_view_tag` may be set from an environment variable /// (`GLEAN_DEBUG_VIEW_TAG`) or through the [`set_debug_view_tag`] function. /// /// **WARNING** This function will block if Glean hasn't been initialized and /// should only be used for debug purposes. /// /// # Returns /// /// Return the value for the debug view tag or [`None`] if it hasn't been set. pubfn glean_get_debug_view_tag() -> Option<String> {
glean_core::glean_get_debug_view_tag()
}
/// Sets the log pings debug option. /// /// When the log pings debug option is `true`, /// we log the payload of all succesfully assembled pings. /// /// # Arguments /// /// * `value` - The value of the log pings option pubfn set_log_pings(value: bool) {
glean_core::glean_set_log_pings(value)
}
/// Gets the current log pings value. /// /// The `log_pings` option may be set from an environment variable (`GLEAN_LOG_PINGS`) /// or through the [`set_log_pings`] function. /// /// **WARNING** This function will block if Glean hasn't been initialized and /// should only be used for debug purposes. /// /// # Returns /// /// Return the value for the log pings debug option. pubfn glean_get_log_pings() -> bool {
glean_core::glean_get_log_pings()
}
/// Sets source tags. /// /// Overrides any existing source tags. /// Source tags will show in the destination datasets, after ingestion. /// /// **Note** If one or more tags are invalid, all tags are ignored. /// /// # Arguments /// /// * `tags` - A vector of at most 5 valid HTTP header values. Individual /// tags must match the regex: "[a-zA-Z0-9-]{1,20}". pubfn set_source_tags(tags: Vec<String>) {
glean_core::glean_set_source_tags(tags);
}
/// Returns a timestamp corresponding to "now" with millisecond precision. pubfn get_timestamp_ms() -> u64 {
glean_core::get_timestamp_ms()
}
/// Asks the database to persist ping-lifetime data to disk. /// /// Probably expensive to call. /// Only has effect when Glean is configured with `delay_ping_lifetime_io: true`. /// If Glean hasn't been initialized this will dispatch and return Ok(()), /// otherwise it will block until the persist is done and return its Result. pubfn persist_ping_lifetime_data() {
glean_core::glean_persist_ping_lifetime_data();
}
/// Gets a list of currently registered ping names. /// /// **WARNING** This function will block if Glean hasn't been initialized and /// should only be used for debug purposes. /// /// # Returns /// /// The list of ping names that are currently registered. pubfn get_registered_ping_names() -> Vec<String> {
glean_core::glean_get_registered_ping_names()
}
#[cfg(test)] mod test;
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.20 Sekunden
(vorverarbeitet am 2026-06-18)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.