Skip to content

Commit a904fae

Browse files
Alex HolmbergAlex Holmberg
authored andcommitted
update: removed telemtry for start/complete phases
1 parent 2e9e34b commit a904fae

3 files changed

Lines changed: 185 additions & 151 deletions

File tree

src/main.rs

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,6 @@ async fn run() -> syncable_cli::Result<()> {
9090

9191
log::debug!("Command name: {}", command_name);
9292

93-
// Track command start for all commands
94-
let start_time = SystemTime::now();
95-
if let Some(telemetry_client) = telemetry::get_telemetry_client() {
96-
log::debug!("Tracking command start");
97-
telemetry_client.track_command_start(command_name);
98-
} else {
99-
log::debug!("No telemetry client available for command start");
100-
}
101-
10293
// Execute command
10394
let result = match cli.command {
10495
Commands::Analyze {
@@ -109,6 +100,11 @@ async fn run() -> syncable_cli::Result<()> {
109100
only,
110101
color_scheme,
111102
} => {
103+
// Track Analyze command
104+
if let Some(telemetry_client) = telemetry::get_telemetry_client() {
105+
telemetry_client.track_analyze();
106+
}
107+
112108
// Track Analyze Folder event
113109
if let Some(telemetry_client) = telemetry::get_telemetry_client() {
114110
telemetry_client.track_analyze_folder();
@@ -128,31 +124,64 @@ async fn run() -> syncable_cli::Result<()> {
128124
all,
129125
dry_run,
130126
force,
131-
} => handle_generate(
132-
path, output, dockerfile, compose, terraform, all, dry_run, force,
133-
),
134-
Commands::Validate { path, types, fix } => handle_validate(path, types, fix),
127+
} => {
128+
// Track Generate command
129+
if let Some(telemetry_client) = telemetry::get_telemetry_client() {
130+
telemetry_client.track_generate();
131+
}
132+
133+
handle_generate(
134+
path, output, dockerfile, compose, terraform, all, dry_run, force,
135+
)
136+
},
137+
Commands::Validate { path, types, fix } => {
138+
// Track Validate command
139+
if let Some(telemetry_client) = telemetry::get_telemetry_client() {
140+
telemetry_client.track_validate();
141+
}
142+
143+
handle_validate(path, types, fix)
144+
},
135145
Commands::Support {
136146
languages,
137147
frameworks,
138148
detailed,
139-
} => handle_support(languages, frameworks, detailed),
149+
} => {
150+
// Track Support command
151+
if let Some(telemetry_client) = telemetry::get_telemetry_client() {
152+
telemetry_client.track_support();
153+
}
154+
155+
handle_support(languages, frameworks, detailed)
156+
},
140157
Commands::Dependencies {
141158
path,
142159
licenses,
143160
vulnerabilities,
144161
prod_only,
145162
dev_only,
146163
format,
147-
} => handle_dependencies(path, licenses, vulnerabilities, prod_only, dev_only, format)
148-
.await
149-
.map(|_| ()),
164+
} => {
165+
// Track Dependencies command
166+
if let Some(telemetry_client) = telemetry::get_telemetry_client() {
167+
telemetry_client.track_dependencies();
168+
}
169+
170+
handle_dependencies(path, licenses, vulnerabilities, prod_only, dev_only, format)
171+
.await
172+
.map(|_| ())
173+
},
150174
Commands::Vulnerabilities {
151175
path,
152176
severity,
153177
format,
154178
output,
155179
} => {
180+
// Track Vulnerabilities command
181+
if let Some(telemetry_client) = telemetry::get_telemetry_client() {
182+
telemetry_client.track_vulnerabilities();
183+
}
184+
156185
// Track Vulnerability Scan event
157186
if let Some(telemetry_client) = telemetry::get_telemetry_client() {
158187
telemetry_client.track_vulnerability_scan();
@@ -173,6 +202,11 @@ async fn run() -> syncable_cli::Result<()> {
173202
output,
174203
fail_on_findings,
175204
} => {
205+
// Track Security command
206+
if let Some(telemetry_client) = telemetry::get_telemetry_client() {
207+
telemetry_client.track_security();
208+
}
209+
176210
// Track Security Scan event
177211
if let Some(telemetry_client) = telemetry::get_telemetry_client() {
178212
telemetry_client.track_security_scan();
@@ -192,16 +226,16 @@ async fn run() -> syncable_cli::Result<()> {
192226
fail_on_findings,
193227
)
194228
},
195-
Commands::Tools { command } => handle_tools(command).await,
229+
Commands::Tools { command } => {
230+
// Track Tools command
231+
if let Some(telemetry_client) = telemetry::get_telemetry_client() {
232+
telemetry_client.track_tools();
233+
}
234+
235+
handle_tools(command).await
236+
},
196237
};
197238

198-
// Track command completion for all commands
199-
let duration = SystemTime::now().duration_since(start_time).unwrap_or_default();
200-
let success = result.is_ok();
201-
if let Some(telemetry_client) = telemetry::get_telemetry_client() {
202-
telemetry_client.track_command_complete(command_name, duration, success);
203-
}
204-
205239
// Flush telemetry events before exiting
206240
if let Some(telemetry_client) = telemetry::get_telemetry_client() {
207241
telemetry_client.flush().await;

src/telemetry/client.rs

Lines changed: 34 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -40,117 +40,6 @@ impl TelemetryClient {
4040
properties
4141
}
4242

43-
pub fn track_command_start(&self, command: &str) {
44-
let properties = self.create_common_properties();
45-
let client = self.http_client.clone();
46-
let cmd = command.to_string();
47-
let pending_tasks = self.pending_tasks.clone();
48-
49-
log::debug!("Tracking command start: {}", cmd);
50-
51-
// Send the event asynchronously
52-
let handle = tokio::spawn(async move {
53-
// Create the event payload according to PostHog API
54-
let payload = json!({
55-
"api_key": POSTHOG_PROJECT_API_KEY,
56-
"event": "command_start",
57-
"properties": {
58-
"command": cmd,
59-
"version": env!("CARGO_PKG_VERSION"),
60-
"os": std::env::consts::OS,
61-
"personal_id": rand::random::<u32>(),
62-
"distinct_id": properties.get("distinct_id").unwrap_or(&json!("unknown")),
63-
},
64-
"timestamp": chrono::Utc::now().format("%Y-%m-%dT%H:%M:%SZ").to_string(),
65-
});
66-
67-
log::debug!("Sending telemetry payload: {:?}", payload);
68-
69-
match client
70-
.post(POSTHOG_API_ENDPOINT)
71-
.json(&payload)
72-
.send()
73-
.await
74-
{
75-
Ok(response) => {
76-
if response.status().is_success() {
77-
log::debug!("Successfully sent telemetry event: command_start");
78-
} else {
79-
let status = response.status();
80-
let body = response.text().await.unwrap_or_else(|_| "Unknown error".to_string());
81-
log::warn!("Failed to send telemetry event 'command_start': HTTP {} - {}", status, body);
82-
}
83-
}
84-
Err(e) => {
85-
log::warn!("Failed to send telemetry event 'command_start': {}", e);
86-
}
87-
}
88-
});
89-
90-
// Keep track of the task
91-
let pending_tasks_clone = pending_tasks.clone();
92-
tokio::spawn(async move {
93-
pending_tasks_clone.lock().await.push(handle);
94-
});
95-
}
96-
97-
pub fn track_command_complete(&self, command: &str, duration: Duration, success: bool) {
98-
let properties = self.create_common_properties();
99-
let client = self.http_client.clone();
100-
let cmd = command.to_string();
101-
let duration_ms = duration.as_millis() as u64;
102-
let pending_tasks = self.pending_tasks.clone();
103-
104-
log::debug!("Tracking command complete: {}", cmd);
105-
106-
// Send the event asynchronously
107-
let handle = tokio::spawn(async move {
108-
// Create the event payload according to PostHog API
109-
let payload = json!({
110-
"api_key": POSTHOG_PROJECT_API_KEY,
111-
"event": "command_complete",
112-
"properties": {
113-
"command": cmd,
114-
"duration_ms": duration_ms,
115-
"success": success,
116-
"version": env!("CARGO_PKG_VERSION"),
117-
"os": std::env::consts::OS,
118-
"personal_id": rand::random::<u32>(),
119-
"distinct_id": properties.get("distinct_id").unwrap_or(&json!("unknown")),
120-
},
121-
"timestamp": chrono::Utc::now().format("%Y-%m-%dT%H:%M:%SZ").to_string(),
122-
});
123-
124-
log::debug!("Sending telemetry payload: {:?}", payload);
125-
126-
match client
127-
.post(POSTHOG_API_ENDPOINT)
128-
.json(&payload)
129-
.send()
130-
.await
131-
{
132-
Ok(response) => {
133-
if response.status().is_success() {
134-
log::debug!("Successfully sent telemetry event: command_complete");
135-
} else {
136-
let status = response.status();
137-
let body = response.text().await.unwrap_or_else(|_| "Unknown error".to_string());
138-
log::warn!("Failed to send telemetry event 'command_complete': HTTP {} - {}", status, body);
139-
}
140-
}
141-
Err(e) => {
142-
log::warn!("Failed to send telemetry event 'command_complete': {}", e);
143-
}
144-
}
145-
});
146-
147-
// Keep track of the task
148-
let pending_tasks_clone = pending_tasks.clone();
149-
tokio::spawn(async move {
150-
pending_tasks_clone.lock().await.push(handle);
151-
});
152-
}
153-
15443
pub fn track_event(&self, name: &str, properties: HashMap<String, serde_json::Value>) {
15544
let mut event_properties = self.create_common_properties();
15645

@@ -205,7 +94,40 @@ impl TelemetryClient {
20594
});
20695
}
20796

208-
// Specific methods for the three events mentioned
97+
// Specific methods for the actual commands
98+
pub fn track_analyze(&self) {
99+
self.track_event("analyze", HashMap::new());
100+
}
101+
102+
pub fn track_generate(&self) {
103+
self.track_event("generate", HashMap::new());
104+
}
105+
106+
pub fn track_validate(&self) {
107+
self.track_event("validate", HashMap::new());
108+
}
109+
110+
pub fn track_support(&self) {
111+
self.track_event("support", HashMap::new());
112+
}
113+
114+
pub fn track_dependencies(&self) {
115+
self.track_event("dependencies", HashMap::new());
116+
}
117+
118+
pub fn track_vulnerabilities(&self) {
119+
self.track_event("vulnerabilities", HashMap::new());
120+
}
121+
122+
pub fn track_security(&self) {
123+
self.track_event("security", HashMap::new());
124+
}
125+
126+
pub fn track_tools(&self) {
127+
self.track_event("tools", HashMap::new());
128+
}
129+
130+
// Existing specific methods for events
209131
pub fn track_security_scan(&self) {
210132
self.track_event("Security Scan", HashMap::new());
211133
}

0 commit comments

Comments
 (0)