Skip to content

Commit

Permalink
feat(telemetry): reduce data volume (#8944)
Browse files Browse the repository at this point in the history
### Description

Reduce volume of telemetry logs

### Testing Instructions

<!--
  Give a quick description of steps to test your changes.
-->
  • Loading branch information
tknickman authored Aug 5, 2024
1 parent 91e3028 commit 7922912
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 23 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,11 +1301,6 @@ pub async fn run(
}
};

if cli_result.is_err() {
root_telemetry.track_failure();
} else {
root_telemetry.track_success();
}
root_telemetry.track_end();
match telemetry_handle {
Some(handle) => handle.close_with_timeout().await,
Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-telemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tokio = { workspace = true, features = ["full", "time"] }
tracing = { workspace = true }
turbopath = { workspace = true }
turborepo-api-client = { workspace = true }
turborepo-ci = { workspace = true }
turborepo-dirs = { path = "../turborepo-dirs" }
turborepo-ui = { workspace = true }
turborepo-vercel-api = { workspace = true }
Expand Down
15 changes: 15 additions & 0 deletions crates/turborepo-telemetry/src/events/command.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fmt::Display;

use serde::{Deserialize, Serialize};
use turborepo_ci;
use turborepo_vercel_api::telemetry::{TelemetryCommandEvent, TelemetryEvent};
use uuid::Uuid;

Expand All @@ -12,6 +13,7 @@ pub struct CommandEventBuilder {
id: String,
command: String,
parent_id: Option<String>,
is_ci: bool,
}

impl Identifiable for CommandEventBuilder {
Expand All @@ -27,6 +29,10 @@ impl EventBuilder for CommandEventBuilder {
}

fn track(&self, event: Event) {
if self.is_ci && !event.send_in_ci {
return;
}

let val = match event.is_sensitive {
EventType::Sensitive => TelemetryConfig::one_way_hash(&event.value),
EventType::NonSensitive => event.value.to_string(),
Expand Down Expand Up @@ -60,6 +66,7 @@ impl CommandEventBuilder {
id: Uuid::new_v4().to_string(),
command: command.to_string(),
parent_id: None,
is_ci: turborepo_ci::is_ci(),
}
}

Expand All @@ -68,6 +75,7 @@ impl CommandEventBuilder {
key: "command".to_string(),
value: "called".to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: true,
});
self
}
Expand All @@ -78,6 +86,7 @@ impl CommandEventBuilder {
key: format!("arg:{}", arg),
value: if is_set { "set" } else { "default" }.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: true,
});
self
}
Expand All @@ -87,6 +96,7 @@ impl CommandEventBuilder {
key: format!("arg:{}", arg),
value: val.to_string(),
is_sensitive,
send_in_ci: true,
});
self
}
Expand All @@ -97,6 +107,7 @@ impl CommandEventBuilder {
key: "action".to_string(),
value: if enabled { "enabled" } else { "disabled" }.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: false,
});
self
}
Expand All @@ -107,6 +118,7 @@ impl CommandEventBuilder {
key: "option".to_string(),
value: option.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: false,
});
self
}
Expand All @@ -116,6 +128,7 @@ impl CommandEventBuilder {
key: "tag".to_string(),
value: tag.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: false,
});
self
}
Expand All @@ -129,6 +142,7 @@ impl CommandEventBuilder {
LoginMethod::Standard => "standard".to_string(),
},
is_sensitive: EventType::NonSensitive,
send_in_ci: false,
});
self
}
Expand All @@ -139,6 +153,7 @@ impl CommandEventBuilder {
key: "success".to_string(),
value: succeeded.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: false,
});
self
}
Expand Down
38 changes: 20 additions & 18 deletions crates/turborepo-telemetry/src/events/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum DaemonInitStatus {
pub struct GenericEventBuilder {
id: String,
parent_id: Option<String>,
is_ci: bool,
}

impl Identifiable for GenericEventBuilder {
Expand All @@ -40,6 +41,10 @@ impl EventBuilder for GenericEventBuilder {
}

fn track(&self, event: Event) {
if self.is_ci && !event.send_in_ci {
return;
}

let val = match event.is_sensitive {
EventType::Sensitive => TelemetryConfig::one_way_hash(&event.value),
EventType::NonSensitive => event.value.to_string(),
Expand All @@ -63,6 +68,7 @@ impl Default for GenericEventBuilder {
Self {
id: Uuid::new_v4().to_string(),
parent_id: None,
is_ci: turborepo_ci::is_ci(),
}
}
}
Expand All @@ -78,6 +84,7 @@ impl GenericEventBuilder {
key: "execution".to_string(),
value: "started".to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: false,
});
self
}
Expand All @@ -87,24 +94,7 @@ impl GenericEventBuilder {
key: "execution".to_string(),
value: "ended".to_string(),
is_sensitive: EventType::NonSensitive,
});
self
}

pub fn track_success(&self) -> &Self {
self.track(Event {
key: "execution".to_string(),
value: "succeeded".to_string(),
is_sensitive: EventType::NonSensitive,
});
self
}

pub fn track_failure(&self) -> &Self {
self.track(Event {
key: "execution".to_string(),
value: "failed".to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: false,
});
self
}
Expand All @@ -114,6 +104,7 @@ impl GenericEventBuilder {
key: "platform".to_string(),
value: platform.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: true,
});
self
}
Expand All @@ -123,6 +114,7 @@ impl GenericEventBuilder {
key: "cpu_count".to_string(),
value: cpus.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: true,
});
self
}
Expand All @@ -132,6 +124,7 @@ impl GenericEventBuilder {
key: "turbo_version".to_string(),
value: version.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: true,
});
self
}
Expand All @@ -142,6 +135,7 @@ impl GenericEventBuilder {
key: format!("arg:{}", arg),
value: if is_set { "set" } else { "default" }.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: true,
});
self
}
Expand All @@ -151,6 +145,7 @@ impl GenericEventBuilder {
key: format!("arg:{}", arg),
value: val.to_string(),
is_sensitive,
send_in_ci: true,
});
self
}
Expand All @@ -161,6 +156,7 @@ impl GenericEventBuilder {
key: "is_linked".to_string(),
value: if is_linked { "true" } else { "false" }.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: true,
});
self
}
Expand All @@ -174,6 +170,7 @@ impl GenericEventBuilder {
} else {
EventType::Sensitive
},
send_in_ci: true,
});
self
}
Expand All @@ -184,6 +181,8 @@ impl GenericEventBuilder {
key: "ci".to_string(),
value: ci.to_string(),
is_sensitive: EventType::NonSensitive,
// yo dawg
send_in_ci: true,
});
}
self
Expand All @@ -194,6 +193,7 @@ impl GenericEventBuilder {
key: "run_type".to_string(),
value: if is_dry { "dry" } else { "full" }.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: true,
});
self
}
Expand All @@ -208,6 +208,7 @@ impl GenericEventBuilder {
DaemonInitStatus::Disabled => "disabled".to_string(),
},
is_sensitive: EventType::NonSensitive,
send_in_ci: false,
});
self
}
Expand All @@ -218,6 +219,7 @@ impl GenericEventBuilder {
key: "error".to_string(),
value: error.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: true,
});
self
}
Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-telemetry/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct Event {
key: String,
value: String,
is_sensitive: EventType,
send_in_ci: bool,
}

pub trait Identifiable {
Expand Down
5 changes: 5 additions & 0 deletions crates/turborepo-telemetry/src/events/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct RepoEventBuilder {
id: String,
repo: String,
parent_id: Option<String>,
is_ci: bool,
}

impl Identifiable for RepoEventBuilder {
Expand Down Expand Up @@ -56,6 +57,7 @@ impl RepoEventBuilder {
id: Uuid::new_v4().to_string(),
repo: TelemetryConfig::one_way_hash(repo_identifier),
parent_id: None,
is_ci: turborepo_ci::is_ci(),
}
}

Expand All @@ -64,6 +66,7 @@ impl RepoEventBuilder {
key: "package_manager".to_string(),
value: name.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: true,
});
self
}
Expand All @@ -76,6 +79,7 @@ impl RepoEventBuilder {
RepoType::Monorepo => "monorepo".to_string(),
},
is_sensitive: EventType::NonSensitive,
send_in_ci: false,
});
self
}
Expand All @@ -85,6 +89,7 @@ impl RepoEventBuilder {
key: "workspace_count".to_string(),
value: size.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: false,
});
self
}
Expand Down
11 changes: 11 additions & 0 deletions crates/turborepo-telemetry/src/events/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct PackageTaskEventBuilder {
package: String,
task: String,
parent_id: Option<String>,
is_ci: bool,
}

impl Identifiable for PackageTaskEventBuilder {
Expand All @@ -43,6 +44,10 @@ impl EventBuilder for PackageTaskEventBuilder {
}

fn track(&self, event: Event) {
if self.is_ci && !event.send_in_ci {
return;
}

let val = match event.is_sensitive {
EventType::Sensitive => TelemetryConfig::one_way_hash(&event.value),
EventType::NonSensitive => event.value.to_string(),
Expand Down Expand Up @@ -84,6 +89,7 @@ impl PackageTaskEventBuilder {
parent_id: None,
package,
task,
is_ci: turborepo_ci::is_ci(),
}
}

Expand All @@ -93,6 +99,7 @@ impl PackageTaskEventBuilder {
key: "framework".to_string(),
value: framework.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: false,
});
self
}
Expand All @@ -102,6 +109,7 @@ impl PackageTaskEventBuilder {
key: "env_mode".to_string(),
value: mode.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: true,
});
self
}
Expand All @@ -114,6 +122,7 @@ impl PackageTaskEventBuilder {
FileHashMethod::Manual => "manual".to_string(),
},
is_sensitive: EventType::NonSensitive,
send_in_ci: false,
});
self
}
Expand All @@ -123,6 +132,7 @@ impl PackageTaskEventBuilder {
key: "scm_mode".to_string(),
value: method.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: false,
});
self
}
Expand All @@ -133,6 +143,7 @@ impl PackageTaskEventBuilder {
key: "error".to_string(),
value: error.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: true,
});
self
}
Expand Down

0 comments on commit 7922912

Please sign in to comment.