Skip to content

Commit

Permalink
Bug 1812738 - allow user to set Glean log level
Browse files Browse the repository at this point in the history
  • Loading branch information
rosahbruno committed May 4, 2023
1 parent dd5c3eb commit 37c48d7
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

[Full changelog](https://github.com/mozilla/glean/compare/v52.6.0...main)

* General
* Allow user to configure how verbose the internal logging is ([#2459](https://github.com/mozilla/glean/pull/2459))

# v52.6.0 (2023-04-20)

[Full changelog](https://github.com/mozilla/glean/compare/v52.5.0...v52.6.0)
Expand Down
1 change: 1 addition & 0 deletions docs/user/reference/general/initializing.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Below are listed the configuration options available on most SDKs.
- `httpUploader`: A custom HTTP uploader instance, that will overwrite Glean's provided uploader. Useful
for users that wish to use specific uploader implementations. See [Custom Uploaders](#custom-uploaders)
for more information on how and when the use this feature.
- `logLevel`: The level for how verbose the internal logging is. The level filter options in order from least to most verbose are: `Off`, `Error`, `Warn`, `Info`, `Debug`, `Trace`. See the [`log` crate docs](https://docs.rs/log/latest/log/) for more information.

To learn about SDK specific configuration options available, refer to the [Reference](#reference) section.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ open class GleanInternalAPI internal constructor() {
delayPingLifetimeIo = false,
appBuild = "none",
useCoreMps = false,
trimDataToRegisteredPings = false
trimDataToRegisteredPings = false,
logLevel = configuration.logLevel
)
val clientInfo = getClientInfo(configuration, buildInfo)
val callbacks = OnGleanEventsImpl(this@GleanInternalAPI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package mozilla.telemetry.glean.config

import mozilla.telemetry.glean.internal.LevelFilter
import mozilla.telemetry.glean.net.HttpURLConnectionUploader
import mozilla.telemetry.glean.net.PingUploader

Expand All @@ -18,6 +19,7 @@ import mozilla.telemetry.glean.net.PingUploader
* sent along with all the pings, in the `client_info` section.
* @property dataPath An optional [String] that specifies where to store data locally on the device.
* This should ONLY be used when setting up Glean on a non-main process.
* @property logLevel An optional [LevelFilter] that controls how verbose the internal logging is.
*/
data class Configuration @JvmOverloads constructor(
val serverEndpoint: String = DEFAULT_TELEMETRY_ENDPOINT,
Expand All @@ -27,7 +29,8 @@ data class Configuration @JvmOverloads constructor(
// default values for the lines below are ever changed, they are required
// to change in the public constructor below.
val httpClient: PingUploader = HttpURLConnectionUploader(),
val dataPath: String? = null
val dataPath: String? = null,
val logLevel: LevelFilter? = null
) {
companion object {
/**
Expand Down
6 changes: 5 additions & 1 deletion glean-core/ios/Glean/Config/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public struct Configuration {
let maxEvents: Int32?
let channel: String?
let dataPath: String?
let logLevel: LevelFilter?

struct Constants {
static let defaultTelemetryEndpoint = "https://incoming.telemetry.mozilla.org"
Expand All @@ -23,15 +24,18 @@ public struct Configuration {
/// * serverEndpoint the server endpoint Glean should send data to
/// * dataPath an optional String that specifies where to store data locally on the device.
/// This should ONLY be used when setting up Glean on a non-main process.
/// * logLevel an optional log level that controls how verbose the internal logging is.
public init(
maxEvents: Int32? = nil,
channel: String? = nil,
serverEndpoint: String? = nil,
dataPath: String? = nil
dataPath: String? = nil,
logLevel: LevelFilter? = nil
) {
self.serverEndpoint = serverEndpoint ?? Constants.defaultTelemetryEndpoint
self.maxEvents = maxEvents
self.channel = channel
self.dataPath = dataPath
self.logLevel = logLevel
}
}
3 changes: 2 additions & 1 deletion glean-core/ios/Glean/Glean.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ public class Glean {
delayPingLifetimeIo: false,
appBuild: "0.0.0",
useCoreMps: false,
trimDataToRegisteredPings: false
trimDataToRegisteredPings: false,
logLevel: configuration.logLevel
)
let clientInfo = getClientInfo(configuration, buildInfo: buildInfo)
let callbacks = OnGleanEventsImpl(glean: self)
Expand Down
1 change: 1 addition & 0 deletions glean-core/python/glean/glean.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def initialize(
use_core_mps=False,
app_build=cls._application_build_id,
trim_data_to_registered_pings=False,
log_level=None,
)

_uniffi.glean_initialize(cfg, client_info, callbacks)
Expand Down
1 change: 1 addition & 0 deletions glean-core/python/glean/net/ping_upload_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def _process(data_dir: Path, application_id: str, configuration) -> bool:
use_core_mps=False,
app_build="",
trim_data_to_registered_pings=False,
log_level=None,
)
if not glean_initialize_for_subprocess(cfg):
log.error("Couldn't initialize Glean in subprocess")
Expand Down
9 changes: 9 additions & 0 deletions glean-core/rlb/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// 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/.

use log::LevelFilter;

use crate::net::PingUploader;

use std::path::PathBuf;
Expand Down Expand Up @@ -34,6 +36,8 @@ pub struct Configuration {
/// Unless you know that all your and your libraries' pings are appropriately registered
/// _before_ init, you shouldn't use this.
pub trim_data_to_registered_pings: bool,
/// The internal logging level.
pub log_level: Option<LevelFilter>,
}

/// Configuration builder.
Expand Down Expand Up @@ -68,6 +72,9 @@ pub struct Builder {
/// _before_ init, you shouldn't use this.
/// Default: `false`
pub trim_data_to_registered_pings: bool,
/// Optional: The internal logging level.
/// Default: `None`
pub log_level: Option<LevelFilter>,
}

impl Builder {
Expand All @@ -87,6 +94,7 @@ impl Builder {
uploader: None,
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
}
}

Expand All @@ -102,6 +110,7 @@ impl Builder {
uploader: self.uploader,
use_core_mps: self.use_core_mps,
trim_data_to_registered_pings: self.trim_data_to_registered_pings,
log_level: self.log_level,
}
}

Expand Down
1 change: 1 addition & 0 deletions glean-core/rlb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ fn initialize_internal(cfg: Configuration, client_info: ClientInfoMetrics) -> Op
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,
log_level: cfg.log_level,
};

glean_core::glean_initialize(core_cfg, client_info.into(), callbacks);
Expand Down
27 changes: 27 additions & 0 deletions glean-core/rlb/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fn send_a_ping() {
uploader: Some(Box::new(FakeUploader { sender: s })),
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
};

let _t = new_glean(Some(cfg), true);
Expand Down Expand Up @@ -142,6 +143,7 @@ fn test_experiments_recording_before_glean_inits() {
uploader: None,
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
},
ClientInfoMetrics::unknown(),
false,
Expand Down Expand Up @@ -202,6 +204,7 @@ fn sending_of_foreground_background_pings() {
uploader: Some(Box::new(FakeUploader { sender: s })),
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
};

let _t = new_glean(Some(cfg), true);
Expand Down Expand Up @@ -284,6 +287,7 @@ fn sending_of_startup_baseline_ping() {
uploader: Some(Box::new(FakeUploader { sender: s })),
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
},
ClientInfoMetrics::unknown(),
false,
Expand Down Expand Up @@ -343,6 +347,7 @@ fn no_dirty_baseline_on_clean_shutdowns() {
uploader: Some(Box::new(FakeUploader { sender: s })),
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
},
ClientInfoMetrics::unknown(),
false,
Expand Down Expand Up @@ -373,6 +378,7 @@ fn initialize_must_not_crash_if_data_dir_is_messed_up() {
uploader: None,
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
};

test_reset_glean(cfg, ClientInfoMetrics::unknown(), false);
Expand Down Expand Up @@ -419,6 +425,7 @@ fn queued_recorded_metrics_correctly_record_during_init() {
uploader: None,
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
};
let _t = new_glean(Some(cfg), false);

Expand All @@ -445,6 +452,7 @@ fn initializing_twice_is_a_noop() {
uploader: None,
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
},
ClientInfoMetrics::unknown(),
true,
Expand All @@ -465,6 +473,7 @@ fn initializing_twice_is_a_noop() {
uploader: None,
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
},
ClientInfoMetrics::unknown(),
);
Expand Down Expand Up @@ -493,6 +502,7 @@ fn dont_handle_events_when_uninitialized() {
uploader: None,
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
},
ClientInfoMetrics::unknown(),
true,
Expand Down Expand Up @@ -557,6 +567,7 @@ fn the_app_channel_must_be_correctly_set_if_requested() {
uploader: None,
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
},
client_info,
true,
Expand All @@ -579,6 +590,7 @@ fn the_app_channel_must_be_correctly_set_if_requested() {
uploader: None,
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
},
client_info,
true,
Expand Down Expand Up @@ -642,6 +654,7 @@ fn ping_collection_must_happen_after_concurrently_scheduled_metrics_recordings()
uploader: Some(Box::new(FakeUploader { sender: s })),
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
},
ClientInfoMetrics::unknown(),
true,
Expand Down Expand Up @@ -723,6 +736,7 @@ fn core_metrics_should_be_cleared_and_restored_when_disabling_and_enabling_uploa
uploader: None,
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
},
ClientInfoMetrics::unknown(),
true,
Expand Down Expand Up @@ -785,6 +799,7 @@ fn sending_deletion_ping_if_disabled_outside_of_run() {
uploader: None,
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
};

let _t = new_glean(Some(cfg), true);
Expand All @@ -802,6 +817,7 @@ fn sending_deletion_ping_if_disabled_outside_of_run() {
uploader: Some(Box::new(FakeUploader { sender: s })),
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
},
ClientInfoMetrics::unknown(),
false,
Expand Down Expand Up @@ -850,6 +866,7 @@ fn no_sending_of_deletion_ping_if_unchanged_outside_of_run() {
uploader: None,
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
};

let _t = new_glean(Some(cfg), true);
Expand All @@ -867,6 +884,7 @@ fn no_sending_of_deletion_ping_if_unchanged_outside_of_run() {
uploader: Some(Box::new(FakeUploader { sender: s })),
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
},
ClientInfoMetrics::unknown(),
false,
Expand Down Expand Up @@ -923,6 +941,7 @@ fn test_sending_of_startup_baseline_ping_with_application_lifetime_metric() {
uploader: None,
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
},
ClientInfoMetrics::unknown(),
true,
Expand Down Expand Up @@ -955,6 +974,7 @@ fn test_sending_of_startup_baseline_ping_with_application_lifetime_metric() {
uploader: Some(Box::new(FakeUploader { sender: s })),
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
},
ClientInfoMetrics::unknown(),
false,
Expand Down Expand Up @@ -1013,6 +1033,7 @@ fn setting_debug_view_tag_before_initialization_should_not_crash() {
uploader: Some(Box::new(FakeUploader { sender: s })),
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
};

let _t = new_glean(Some(cfg), true);
Expand Down Expand Up @@ -1071,6 +1092,7 @@ fn setting_source_tags_before_initialization_should_not_crash() {
uploader: Some(Box::new(FakeUploader { sender: s })),
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
};

let _t = new_glean(Some(cfg), true);
Expand Down Expand Up @@ -1128,6 +1150,7 @@ fn setting_source_tags_after_initialization_should_not_crash() {
uploader: Some(Box::new(FakeUploader { sender: s })),
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
};

let _t = new_glean(Some(cfg), true);
Expand Down Expand Up @@ -1199,6 +1222,7 @@ fn flipping_upload_enabled_respects_order_of_events() {
uploader: Some(Box::new(FakeUploader { sender: s })),
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
};

// We create a ping and a metric before we initialize Glean
Expand Down Expand Up @@ -1267,6 +1291,7 @@ fn registering_pings_before_init_must_work() {
uploader: Some(Box::new(FakeUploader { sender: s })),
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
};

let _t = new_glean(Some(cfg), true);
Expand Down Expand Up @@ -1317,6 +1342,7 @@ fn test_a_ping_before_submission() {
uploader: Some(Box::new(FakeUploader { sender: s })),
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
};

let _t = new_glean(Some(cfg), true);
Expand Down Expand Up @@ -1445,6 +1471,7 @@ fn signaling_done() {
})),
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
};

let _t = new_glean(Some(cfg), true);
Expand Down
2 changes: 2 additions & 0 deletions glean-core/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ where
/// app_build: "".into(),
/// use_core_mps: false,
/// trim_data_to_registered_pings: false,
/// log_level: None,
/// };
/// let mut glean = Glean::new(cfg).unwrap();
/// let ping = PingType::new("sample", true, false, vec![]);
Expand Down Expand Up @@ -293,6 +294,7 @@ impl Glean {
app_build: "Unknown".into(),
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
};

let mut glean = Self::new(cfg).unwrap();
Expand Down
Loading

0 comments on commit 37c48d7

Please sign in to comment.