diff --git a/Cargo.lock b/Cargo.lock index 1d236bfb9d5f0..44165e8a442b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -437,6 +437,7 @@ dependencies = [ "smallvec", "smol", "strum", + "telemetry", "telemetry_events", "terminal", "terminal_view", diff --git a/crates/assistant/Cargo.toml b/crates/assistant/Cargo.toml index 63a2afa71a868..6f05d7811ddfa 100644 --- a/crates/assistant/Cargo.toml +++ b/crates/assistant/Cargo.toml @@ -80,6 +80,7 @@ similar.workspace = true smallvec.workspace = true smol.workspace = true strum.workspace = true +telemetry.workspace = true telemetry_events.workspace = true terminal.workspace = true terminal_view.workspace = true diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index 96e539e167d65..26f793ba575c0 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -1,6 +1,6 @@ mod event_coalescer; -use crate::{ChannelId, TelemetrySettings}; +use crate::TelemetrySettings; use anyhow::Result; use clock::SystemClock; use collections::{HashMap, HashSet}; @@ -14,16 +14,11 @@ use settings::{Settings, SettingsStore}; use sha2::{Digest, Sha256}; use std::fs::File; use std::io::Write; +use std::sync::LazyLock; use std::time::Instant; -use std::{ - env, mem, - path::PathBuf, - sync::{Arc, LazyLock}, - time::Duration, -}; +use std::{env, mem, path::PathBuf, sync::Arc, time::Duration}; use telemetry_events::{ - AppEvent, AssistantEvent, CallEvent, EditEvent, Event, EventRequestBody, EventWrapper, - InlineCompletionEvent, + AppEvent, AssistantEvent, AssistantPhase, EditEvent, Event, EventRequestBody, EventWrapper, }; use util::{ResultExt, TryFutureExt}; use worktree::{UpdatedEntriesSet, WorktreeId}; @@ -338,38 +333,26 @@ impl Telemetry { drop(state); } - pub fn report_inline_completion_event( - self: &Arc, - provider: String, - suggestion_accepted: bool, - file_extension: Option, - ) { - let event = Event::InlineCompletion(InlineCompletionEvent { - provider, - suggestion_accepted, - file_extension, - }); - - self.report_event(event) - } - pub fn report_assistant_event(self: &Arc, event: AssistantEvent) { - self.report_event(Event::Assistant(event)); - } - - pub fn report_call_event( - self: &Arc, - operation: &'static str, - room_id: Option, - channel_id: Option, - ) { - let event = Event::Call(CallEvent { - operation: operation.to_string(), - room_id, - channel_id: channel_id.map(|cid| cid.0), - }); + let event_type = match event.phase { + AssistantPhase::Response => "Assistant Responded", + AssistantPhase::Invoked => "Assistant Invoked", + AssistantPhase::Accepted => "Assistant Response Accepted", + AssistantPhase::Rejected => "Assistant Response Rejected", + }; - self.report_event(event) + telemetry::event!( + event_type, + conversation_id = event.conversation_id, + kind = event.kind, + phase = event.phase, + message_id = event.message_id, + model = event.model, + model_provider = event.model_provider, + response_latency = event.response_latency, + error_message = event.error_message, + language_name = event.language_name, + ); } pub fn report_app_event(self: &Arc, operation: String) -> Event { diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 71224c3366236..81938bbe87995 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -4733,9 +4733,7 @@ impl Editor { let Some(provider) = self.inline_completion_provider() else { return; }; - let Some(project) = self.project.as_ref() else { - return; - }; + let Some((_, buffer, _)) = self .buffer .read(cx) @@ -4744,15 +4742,20 @@ impl Editor { return; }; - let project = project.read(cx); let extension = buffer .read(cx) .file() .and_then(|file| Some(file.path().extension()?.to_string_lossy().to_string())); - project.client().telemetry().report_inline_completion_event( - provider.name().into(), - accepted, - extension, + + let event_type = match accepted { + true => "Inline Completion Accepted", + false => "Inline Completion Discarded", + }; + telemetry::event!( + event_type, + provider = provider.name(), + suggestion_accepted = accepted, + file_extension = extension, ); }