@@ -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