Make report_assistant_event take an AssistantEvent struct (#18741)

This PR makes the `report_assistant_event` method take an
`AssistantEvent` struct instead of all of the struct fields as
individual parameters.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-10-04 13:19:18 -04:00 committed by GitHub
parent 07e808d16f
commit e3a6f89e2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 44 additions and 59 deletions

View file

@ -46,7 +46,7 @@ use std::{
sync::Arc, sync::Arc,
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use telemetry_events::{AssistantKind, AssistantPhase}; use telemetry_events::{AssistantEvent, AssistantKind, AssistantPhase};
use text::BufferSnapshot; use text::BufferSnapshot;
use util::{post_inc, ResultExt, TryFutureExt}; use util::{post_inc, ResultExt, TryFutureExt};
use uuid::Uuid; use uuid::Uuid;
@ -2133,14 +2133,14 @@ impl Context {
}); });
if let Some(telemetry) = this.telemetry.as_ref() { if let Some(telemetry) = this.telemetry.as_ref() {
telemetry.report_assistant_event( telemetry.report_assistant_event(AssistantEvent {
Some(this.id.0.clone()), conversation_id: Some(this.id.0.clone()),
AssistantKind::Panel, kind: AssistantKind::Panel,
AssistantPhase::Response, phase: AssistantPhase::Response,
model.telemetry_id(), model: model.telemetry_id(),
response_latency, response_latency,
error_message, error_message,
); });
} }
if let Ok(stop_reason) = result { if let Ok(stop_reason) = result {

View file

@ -50,6 +50,7 @@ use std::{
task::{self, Poll}, task::{self, Poll},
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use telemetry_events::{AssistantEvent, AssistantKind, AssistantPhase};
use terminal_view::terminal_panel::TerminalPanel; use terminal_view::terminal_panel::TerminalPanel;
use text::{OffsetRangeExt, ToPoint as _}; use text::{OffsetRangeExt, ToPoint as _};
use theme::ThemeSettings; use theme::ThemeSettings;
@ -211,14 +212,14 @@ impl InlineAssistant {
) { ) {
if let Some(telemetry) = self.telemetry.as_ref() { if let Some(telemetry) = self.telemetry.as_ref() {
if let Some(model) = LanguageModelRegistry::read_global(cx).active_model() { if let Some(model) = LanguageModelRegistry::read_global(cx).active_model() {
telemetry.report_assistant_event( telemetry.report_assistant_event(AssistantEvent {
None, conversation_id: None,
telemetry_events::AssistantKind::Inline, kind: AssistantKind::Inline,
telemetry_events::AssistantPhase::Invoked, phase: AssistantPhase::Invoked,
model.telemetry_id(), model: model.telemetry_id(),
None, response_latency: None,
None, error_message: None,
); });
} }
} }
let snapshot = editor.read(cx).buffer().read(cx).snapshot(cx); let snapshot = editor.read(cx).buffer().read(cx).snapshot(cx);
@ -763,18 +764,18 @@ impl InlineAssistant {
pub fn finish_assist(&mut self, assist_id: InlineAssistId, undo: bool, cx: &mut WindowContext) { pub fn finish_assist(&mut self, assist_id: InlineAssistId, undo: bool, cx: &mut WindowContext) {
if let Some(telemetry) = self.telemetry.as_ref() { if let Some(telemetry) = self.telemetry.as_ref() {
if let Some(model) = LanguageModelRegistry::read_global(cx).active_model() { if let Some(model) = LanguageModelRegistry::read_global(cx).active_model() {
telemetry.report_assistant_event( telemetry.report_assistant_event(AssistantEvent {
None, conversation_id: None,
telemetry_events::AssistantKind::Inline, kind: AssistantKind::Inline,
if undo { phase: if undo {
telemetry_events::AssistantPhase::Rejected AssistantPhase::Rejected
} else { } else {
telemetry_events::AssistantPhase::Accepted AssistantPhase::Accepted
}, },
model.telemetry_id(), model: model.telemetry_id(),
None, response_latency: None,
None, error_message: None,
); });
} }
} }
if let Some(assist) = self.assists.get(&assist_id) { if let Some(assist) = self.assists.get(&assist_id) {
@ -2920,14 +2921,14 @@ impl CodegenAlternative {
let error_message = let error_message =
result.as_ref().err().map(|error| error.to_string()); result.as_ref().err().map(|error| error.to_string());
if let Some(telemetry) = telemetry { if let Some(telemetry) = telemetry {
telemetry.report_assistant_event( telemetry.report_assistant_event(AssistantEvent {
None, conversation_id: None,
telemetry_events::AssistantKind::Inline, kind: AssistantKind::Inline,
telemetry_events::AssistantPhase::Response, phase: AssistantPhase::Response,
model_telemetry_id, model: model_telemetry_id,
response_latency, response_latency,
error_message, error_message,
); });
} }
result?; result?;

View file

@ -25,6 +25,7 @@ use std::{
sync::Arc, sync::Arc,
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use telemetry_events::{AssistantEvent, AssistantKind, AssistantPhase};
use terminal::Terminal; use terminal::Terminal;
use terminal_view::TerminalView; use terminal_view::TerminalView;
use theme::ThemeSettings; use theme::ThemeSettings;
@ -1063,14 +1064,14 @@ impl Codegen {
let error_message = result.as_ref().err().map(|error| error.to_string()); let error_message = result.as_ref().err().map(|error| error.to_string());
if let Some(telemetry) = telemetry { if let Some(telemetry) = telemetry {
telemetry.report_assistant_event( telemetry.report_assistant_event(AssistantEvent {
None, conversation_id: None,
telemetry_events::AssistantKind::Inline, kind: AssistantKind::Inline,
telemetry_events::AssistantPhase::Response, phase: AssistantPhase::Response,
model_telemetry_id, model: model_telemetry_id,
response_latency, response_latency,
error_message, error_message,
); });
} }
result?; result?;

View file

@ -16,9 +16,9 @@ use std::io::Write;
use std::{env, mem, path::PathBuf, sync::Arc, time::Duration}; use std::{env, mem, path::PathBuf, sync::Arc, time::Duration};
use sysinfo::{CpuRefreshKind, Pid, ProcessRefreshKind, RefreshKind, System}; use sysinfo::{CpuRefreshKind, Pid, ProcessRefreshKind, RefreshKind, System};
use telemetry_events::{ use telemetry_events::{
ActionEvent, AppEvent, AssistantEvent, AssistantKind, AssistantPhase, CallEvent, CpuEvent, ActionEvent, AppEvent, AssistantEvent, CallEvent, CpuEvent, EditEvent, EditorEvent, Event,
EditEvent, EditorEvent, Event, EventRequestBody, EventWrapper, ExtensionEvent, EventRequestBody, EventWrapper, ExtensionEvent, InlineCompletionEvent, MemoryEvent, ReplEvent,
InlineCompletionEvent, MemoryEvent, ReplEvent, SettingEvent, SettingEvent,
}; };
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
#[cfg(not(debug_assertions))] #[cfg(not(debug_assertions))]
@ -391,25 +391,8 @@ impl Telemetry {
self.report_event(event) self.report_event(event)
} }
pub fn report_assistant_event( pub fn report_assistant_event(self: &Arc<Self>, event: AssistantEvent) {
self: &Arc<Self>, self.report_event(Event::Assistant(event));
conversation_id: Option<String>,
kind: AssistantKind,
phase: AssistantPhase,
model: String,
response_latency: Option<Duration>,
error_message: Option<String>,
) {
let event = Event::Assistant(AssistantEvent {
conversation_id,
kind,
phase,
model: model.to_string(),
response_latency,
error_message,
});
self.report_event(event)
} }
pub fn report_call_event( pub fn report_call_event(