Skip to content

Commit

Permalink
[cli] Allow disabling telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario authored and davidiw committed Oct 17, 2022
1 parent e47c1b9 commit 01108a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/aptos-telemetry/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static TELEMETRY_TOKEN: Lazy<String> = Lazy::new(|| {

/// Returns true iff telemetry is disabled
#[inline]
fn telemetry_is_disabled() -> bool {
pub fn telemetry_is_disabled() -> bool {
env::var(ENV_APTOS_DISABLE_TELEMETRY).is_ok()
}

Expand Down
19 changes: 12 additions & 7 deletions crates/aptos/src/common/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use aptos_build_info::build_information;
use aptos_logger::{debug, Level};
use aptos_rest_client::aptos_api_types::HashValue;
use aptos_rest_client::{Account, Client};
use aptos_telemetry::service::telemetry_is_disabled;
use aptos_types::{chain_id::ChainId, transaction::authenticator::AuthenticationKey};
use itertools::Itertools;
use move_deps::move_core_types::account_address::AccountAddress;
Expand Down Expand Up @@ -63,13 +64,17 @@ pub async fn to_common_result<T: Serialize>(
) -> CliResult {
let latency = start_time.elapsed();
let is_err = result.is_err();
let error = if let Err(ref error) = result {
// Only print the error type
Some(error.to_str())
} else {
None
};
send_telemetry_event(command, latency, !is_err, error).await;

if !telemetry_is_disabled() {
let error = if let Err(ref error) = result {
// Only print the error type
Some(error.to_str())
} else {
None
};
send_telemetry_event(command, latency, !is_err, error).await;
}

let result: ResultWrapper<T> = result.into();
let string = serde_json::to_string_pretty(&result).unwrap();
if is_err {
Expand Down

0 comments on commit 01108a2

Please sign in to comment.