#![allow(clippy::uninlined_format_args)]
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(missing_docs)]
use std::collections::HashMap;
use std::path::Path;
use configuration::DEFAULT_GLEAN_ENDPOINT;
pub use configuration::{Builder as ConfigurationBuilder, Configuration};
pub use core_metrics::ClientInfoMetrics;
pub use glean_core::{
metrics::{Datetime, DistributionData, MemoryUnit, Rate, RecordedEvent, TimeUnit, TimerId},
traits, CommonMetricData, Error, ErrorType, Glean, HistogramType, Lifetime, RecordedExperiment,
Result,
};
mod configuration;
mod core_metrics;
pub mod net;
pub mod private;
mod system;
#[cfg(test)]
mod common_test;
const LANGUAGE_BINDING_NAME: &str = "Rust";
pub fn initialize(cfg: Configuration, client_info: ClientInfoMetrics) {
initialize_internal(cfg, client_info);
}
struct GleanEvents {
upload_manager: net::UploadManager,
}
impl glean_core::OnGleanEvents for GleanEvents {
fn on_initialize_finished(&self) {
}
fn trigger_upload(&self) -> Result<(), glean_core::CallbackError> {
self.upload_manager.trigger_upload();
Ok(())
}
fn start_metrics_ping_scheduler(&self) -> bool {
true
}
fn cancel_uploads(&self) -> Result<(), glean_core::CallbackError> {
Ok(())
}
}
fn initialize_internal(cfg: Configuration, client_info: ClientInfoMetrics) -> Option<()> {
let upload_manager = net::UploadManager::new(
cfg.server_endpoint
.unwrap_or_else(|| DEFAULT_GLEAN_ENDPOINT.to_string()),
cfg.uploader
.unwrap_or_else(|| Box::new(net::HttpUploader) as Box<dyn net::PingUploader>),
);
let callbacks = Box::new(GleanEvents { upload_manager });
let core_cfg = glean_core::InternalConfiguration {
upload_enabled: cfg.upload_enabled,
data_path: cfg.data_path.display().to_string(),
application_id: cfg.application_id.clone(),
language_binding_name: LANGUAGE_BINDING_NAME.into(),
max_events: cfg.max_events.map(|m| m as u32),
delay_ping_lifetime_io: cfg.delay_ping_lifetime_io,
app_build: client_info.app_build.clone(),
use_core_mps: cfg.use_core_mps,
trim_data_to_registered_pings: cfg.trim_data_to_registered_pings,
};
glean_core::glean_initialize(core_cfg, client_info.into(), callbacks);
Some(())
}
pub fn shutdown() {
glean_core::shutdown()
}
pub fn set_upload_enabled(enabled: bool) {
glean_core::glean_set_upload_enabled(enabled)
}
pub fn 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)
}
pub fn 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())
}
pub fn set_experiment_inactive(experiment_id: String) {
glean_core::glean_set_experiment_inactive(experiment_id)
}
pub fn glean_set_metrics_disabled_config(json: String) {
glean_core::glean_set_metrics_disabled_config(json)
}
pub fn handle_client_active() {
glean_core::glean_handle_client_active()
}
pub fn handle_client_inactive() {
glean_core::glean_handle_client_inactive()
}
pub fn test_is_experiment_active(experiment_id: String) -> bool {
glean_core::glean_test_get_experiment_data(experiment_id).is_some()
}
pub fn test_get_experiment_data(experiment_id: String) -> Option<RecordedExperiment> {
glean_core::glean_test_get_experiment_data(experiment_id)
}
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))
}
pub fn 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();
}
pub fn set_debug_view_tag(tag: &str) -> bool {
glean_core::glean_set_debug_view_tag(tag.to_string())
}
pub fn set_log_pings(value: bool) {
glean_core::glean_set_log_pings(value)
}
pub fn set_source_tags(tags: Vec<String>) {
glean_core::glean_set_source_tags(tags);
}
pub fn get_timestamp_ms() -> u64 {
glean_core::get_timestamp_ms()
}
pub fn persist_ping_lifetime_data() {
glean_core::persist_ping_lifetime_data();
}
#[cfg(test)]
mod test;