Skip to content

Commit 7922912

Browse files
authored
feat(telemetry): reduce data volume (#8944)
### Description Reduce volume of telemetry logs ### Testing Instructions <!-- Give a quick description of steps to test your changes. -->
1 parent 91e3028 commit 7922912

File tree

8 files changed

+54
-23
lines changed

8 files changed

+54
-23
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/turborepo-lib/src/cli/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1301,11 +1301,6 @@ pub async fn run(
13011301
}
13021302
};
13031303

1304-
if cli_result.is_err() {
1305-
root_telemetry.track_failure();
1306-
} else {
1307-
root_telemetry.track_success();
1308-
}
13091304
root_telemetry.track_end();
13101305
match telemetry_handle {
13111306
Some(handle) => handle.close_with_timeout().await,

crates/turborepo-telemetry/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ tokio = { workspace = true, features = ["full", "time"] }
3030
tracing = { workspace = true }
3131
turbopath = { workspace = true }
3232
turborepo-api-client = { workspace = true }
33+
turborepo-ci = { workspace = true }
3334
turborepo-dirs = { path = "../turborepo-dirs" }
3435
turborepo-ui = { workspace = true }
3536
turborepo-vercel-api = { workspace = true }

crates/turborepo-telemetry/src/events/command.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::fmt::Display;
22

33
use serde::{Deserialize, Serialize};
4+
use turborepo_ci;
45
use turborepo_vercel_api::telemetry::{TelemetryCommandEvent, TelemetryEvent};
56
use uuid::Uuid;
67

@@ -12,6 +13,7 @@ pub struct CommandEventBuilder {
1213
id: String,
1314
command: String,
1415
parent_id: Option<String>,
16+
is_ci: bool,
1517
}
1618

1719
impl Identifiable for CommandEventBuilder {
@@ -27,6 +29,10 @@ impl EventBuilder for CommandEventBuilder {
2729
}
2830

2931
fn track(&self, event: Event) {
32+
if self.is_ci && !event.send_in_ci {
33+
return;
34+
}
35+
3036
let val = match event.is_sensitive {
3137
EventType::Sensitive => TelemetryConfig::one_way_hash(&event.value),
3238
EventType::NonSensitive => event.value.to_string(),
@@ -60,6 +66,7 @@ impl CommandEventBuilder {
6066
id: Uuid::new_v4().to_string(),
6167
command: command.to_string(),
6268
parent_id: None,
69+
is_ci: turborepo_ci::is_ci(),
6370
}
6471
}
6572

@@ -68,6 +75,7 @@ impl CommandEventBuilder {
6875
key: "command".to_string(),
6976
value: "called".to_string(),
7077
is_sensitive: EventType::NonSensitive,
78+
send_in_ci: true,
7179
});
7280
self
7381
}
@@ -78,6 +86,7 @@ impl CommandEventBuilder {
7886
key: format!("arg:{}", arg),
7987
value: if is_set { "set" } else { "default" }.to_string(),
8088
is_sensitive: EventType::NonSensitive,
89+
send_in_ci: true,
8190
});
8291
self
8392
}
@@ -87,6 +96,7 @@ impl CommandEventBuilder {
8796
key: format!("arg:{}", arg),
8897
value: val.to_string(),
8998
is_sensitive,
99+
send_in_ci: true,
90100
});
91101
self
92102
}
@@ -97,6 +107,7 @@ impl CommandEventBuilder {
97107
key: "action".to_string(),
98108
value: if enabled { "enabled" } else { "disabled" }.to_string(),
99109
is_sensitive: EventType::NonSensitive,
110+
send_in_ci: false,
100111
});
101112
self
102113
}
@@ -107,6 +118,7 @@ impl CommandEventBuilder {
107118
key: "option".to_string(),
108119
value: option.to_string(),
109120
is_sensitive: EventType::NonSensitive,
121+
send_in_ci: false,
110122
});
111123
self
112124
}
@@ -116,6 +128,7 @@ impl CommandEventBuilder {
116128
key: "tag".to_string(),
117129
value: tag.to_string(),
118130
is_sensitive: EventType::NonSensitive,
131+
send_in_ci: false,
119132
});
120133
self
121134
}
@@ -129,6 +142,7 @@ impl CommandEventBuilder {
129142
LoginMethod::Standard => "standard".to_string(),
130143
},
131144
is_sensitive: EventType::NonSensitive,
145+
send_in_ci: false,
132146
});
133147
self
134148
}
@@ -139,6 +153,7 @@ impl CommandEventBuilder {
139153
key: "success".to_string(),
140154
value: succeeded.to_string(),
141155
is_sensitive: EventType::NonSensitive,
156+
send_in_ci: false,
142157
});
143158
self
144159
}

crates/turborepo-telemetry/src/events/generic.rs

+20-18
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub enum DaemonInitStatus {
2525
pub struct GenericEventBuilder {
2626
id: String,
2727
parent_id: Option<String>,
28+
is_ci: bool,
2829
}
2930

3031
impl Identifiable for GenericEventBuilder {
@@ -40,6 +41,10 @@ impl EventBuilder for GenericEventBuilder {
4041
}
4142

4243
fn track(&self, event: Event) {
44+
if self.is_ci && !event.send_in_ci {
45+
return;
46+
}
47+
4348
let val = match event.is_sensitive {
4449
EventType::Sensitive => TelemetryConfig::one_way_hash(&event.value),
4550
EventType::NonSensitive => event.value.to_string(),
@@ -63,6 +68,7 @@ impl Default for GenericEventBuilder {
6368
Self {
6469
id: Uuid::new_v4().to_string(),
6570
parent_id: None,
71+
is_ci: turborepo_ci::is_ci(),
6672
}
6773
}
6874
}
@@ -78,6 +84,7 @@ impl GenericEventBuilder {
7884
key: "execution".to_string(),
7985
value: "started".to_string(),
8086
is_sensitive: EventType::NonSensitive,
87+
send_in_ci: false,
8188
});
8289
self
8390
}
@@ -87,24 +94,7 @@ impl GenericEventBuilder {
8794
key: "execution".to_string(),
8895
value: "ended".to_string(),
8996
is_sensitive: EventType::NonSensitive,
90-
});
91-
self
92-
}
93-
94-
pub fn track_success(&self) -> &Self {
95-
self.track(Event {
96-
key: "execution".to_string(),
97-
value: "succeeded".to_string(),
98-
is_sensitive: EventType::NonSensitive,
99-
});
100-
self
101-
}
102-
103-
pub fn track_failure(&self) -> &Self {
104-
self.track(Event {
105-
key: "execution".to_string(),
106-
value: "failed".to_string(),
107-
is_sensitive: EventType::NonSensitive,
97+
send_in_ci: false,
10898
});
10999
self
110100
}
@@ -114,6 +104,7 @@ impl GenericEventBuilder {
114104
key: "platform".to_string(),
115105
value: platform.to_string(),
116106
is_sensitive: EventType::NonSensitive,
107+
send_in_ci: true,
117108
});
118109
self
119110
}
@@ -123,6 +114,7 @@ impl GenericEventBuilder {
123114
key: "cpu_count".to_string(),
124115
value: cpus.to_string(),
125116
is_sensitive: EventType::NonSensitive,
117+
send_in_ci: true,
126118
});
127119
self
128120
}
@@ -132,6 +124,7 @@ impl GenericEventBuilder {
132124
key: "turbo_version".to_string(),
133125
value: version.to_string(),
134126
is_sensitive: EventType::NonSensitive,
127+
send_in_ci: true,
135128
});
136129
self
137130
}
@@ -142,6 +135,7 @@ impl GenericEventBuilder {
142135
key: format!("arg:{}", arg),
143136
value: if is_set { "set" } else { "default" }.to_string(),
144137
is_sensitive: EventType::NonSensitive,
138+
send_in_ci: true,
145139
});
146140
self
147141
}
@@ -151,6 +145,7 @@ impl GenericEventBuilder {
151145
key: format!("arg:{}", arg),
152146
value: val.to_string(),
153147
is_sensitive,
148+
send_in_ci: true,
154149
});
155150
self
156151
}
@@ -161,6 +156,7 @@ impl GenericEventBuilder {
161156
key: "is_linked".to_string(),
162157
value: if is_linked { "true" } else { "false" }.to_string(),
163158
is_sensitive: EventType::NonSensitive,
159+
send_in_ci: true,
164160
});
165161
self
166162
}
@@ -174,6 +170,7 @@ impl GenericEventBuilder {
174170
} else {
175171
EventType::Sensitive
176172
},
173+
send_in_ci: true,
177174
});
178175
self
179176
}
@@ -184,6 +181,8 @@ impl GenericEventBuilder {
184181
key: "ci".to_string(),
185182
value: ci.to_string(),
186183
is_sensitive: EventType::NonSensitive,
184+
// yo dawg
185+
send_in_ci: true,
187186
});
188187
}
189188
self
@@ -194,6 +193,7 @@ impl GenericEventBuilder {
194193
key: "run_type".to_string(),
195194
value: if is_dry { "dry" } else { "full" }.to_string(),
196195
is_sensitive: EventType::NonSensitive,
196+
send_in_ci: true,
197197
});
198198
self
199199
}
@@ -208,6 +208,7 @@ impl GenericEventBuilder {
208208
DaemonInitStatus::Disabled => "disabled".to_string(),
209209
},
210210
is_sensitive: EventType::NonSensitive,
211+
send_in_ci: false,
211212
});
212213
self
213214
}
@@ -218,6 +219,7 @@ impl GenericEventBuilder {
218219
key: "error".to_string(),
219220
value: error.to_string(),
220221
is_sensitive: EventType::NonSensitive,
222+
send_in_ci: true,
221223
});
222224
self
223225
}

crates/turborepo-telemetry/src/events/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub struct Event {
2929
key: String,
3030
value: String,
3131
is_sensitive: EventType,
32+
send_in_ci: bool,
3233
}
3334

3435
pub trait Identifiable {

crates/turborepo-telemetry/src/events/repo.rs

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub struct RepoEventBuilder {
1515
id: String,
1616
repo: String,
1717
parent_id: Option<String>,
18+
is_ci: bool,
1819
}
1920

2021
impl Identifiable for RepoEventBuilder {
@@ -56,6 +57,7 @@ impl RepoEventBuilder {
5657
id: Uuid::new_v4().to_string(),
5758
repo: TelemetryConfig::one_way_hash(repo_identifier),
5859
parent_id: None,
60+
is_ci: turborepo_ci::is_ci(),
5961
}
6062
}
6163

@@ -64,6 +66,7 @@ impl RepoEventBuilder {
6466
key: "package_manager".to_string(),
6567
value: name.to_string(),
6668
is_sensitive: EventType::NonSensitive,
69+
send_in_ci: true,
6770
});
6871
self
6972
}
@@ -76,6 +79,7 @@ impl RepoEventBuilder {
7679
RepoType::Monorepo => "monorepo".to_string(),
7780
},
7881
is_sensitive: EventType::NonSensitive,
82+
send_in_ci: false,
7983
});
8084
self
8185
}
@@ -85,6 +89,7 @@ impl RepoEventBuilder {
8589
key: "workspace_count".to_string(),
8690
value: size.to_string(),
8791
is_sensitive: EventType::NonSensitive,
92+
send_in_ci: false,
8893
});
8994
self
9095
}

crates/turborepo-telemetry/src/events/task.rs

+11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub struct PackageTaskEventBuilder {
2828
package: String,
2929
task: String,
3030
parent_id: Option<String>,
31+
is_ci: bool,
3132
}
3233

3334
impl Identifiable for PackageTaskEventBuilder {
@@ -43,6 +44,10 @@ impl EventBuilder for PackageTaskEventBuilder {
4344
}
4445

4546
fn track(&self, event: Event) {
47+
if self.is_ci && !event.send_in_ci {
48+
return;
49+
}
50+
4651
let val = match event.is_sensitive {
4752
EventType::Sensitive => TelemetryConfig::one_way_hash(&event.value),
4853
EventType::NonSensitive => event.value.to_string(),
@@ -84,6 +89,7 @@ impl PackageTaskEventBuilder {
8489
parent_id: None,
8590
package,
8691
task,
92+
is_ci: turborepo_ci::is_ci(),
8793
}
8894
}
8995

@@ -93,6 +99,7 @@ impl PackageTaskEventBuilder {
9399
key: "framework".to_string(),
94100
value: framework.to_string(),
95101
is_sensitive: EventType::NonSensitive,
102+
send_in_ci: false,
96103
});
97104
self
98105
}
@@ -102,6 +109,7 @@ impl PackageTaskEventBuilder {
102109
key: "env_mode".to_string(),
103110
value: mode.to_string(),
104111
is_sensitive: EventType::NonSensitive,
112+
send_in_ci: true,
105113
});
106114
self
107115
}
@@ -114,6 +122,7 @@ impl PackageTaskEventBuilder {
114122
FileHashMethod::Manual => "manual".to_string(),
115123
},
116124
is_sensitive: EventType::NonSensitive,
125+
send_in_ci: false,
117126
});
118127
self
119128
}
@@ -123,6 +132,7 @@ impl PackageTaskEventBuilder {
123132
key: "scm_mode".to_string(),
124133
value: method.to_string(),
125134
is_sensitive: EventType::NonSensitive,
135+
send_in_ci: false,
126136
});
127137
self
128138
}
@@ -133,6 +143,7 @@ impl PackageTaskEventBuilder {
133143
key: "error".to_string(),
134144
value: error.to_string(),
135145
is_sensitive: EventType::NonSensitive,
146+
send_in_ci: true,
136147
});
137148
self
138149
}

0 commit comments

Comments
 (0)