Skip to content

Commit

Permalink
Migrate more events to telemetry::event (#22178)
Browse files Browse the repository at this point in the history
Release Notes:

- N/A
  • Loading branch information
JosephTLyons authored Jan 14, 2025
1 parent b7fd571 commit 077767a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 47 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/assistant/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 22 additions & 39 deletions crates/client/src/telemetry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod event_coalescer;

use crate::{ChannelId, TelemetrySettings};
use crate::TelemetrySettings;
use anyhow::Result;
use clock::SystemClock;
use collections::{HashMap, HashSet};
Expand All @@ -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};
Expand Down Expand Up @@ -338,38 +333,26 @@ impl Telemetry {
drop(state);
}

pub fn report_inline_completion_event(
self: &Arc<Self>,
provider: String,
suggestion_accepted: bool,
file_extension: Option<String>,
) {
let event = Event::InlineCompletion(InlineCompletionEvent {
provider,
suggestion_accepted,
file_extension,
});

self.report_event(event)
}

pub fn report_assistant_event(self: &Arc<Self>, event: AssistantEvent) {
self.report_event(Event::Assistant(event));
}

pub fn report_call_event(
self: &Arc<Self>,
operation: &'static str,
room_id: Option<u64>,
channel_id: Option<ChannelId>,
) {
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<Self>, operation: String) -> Event {
Expand Down
19 changes: 11 additions & 8 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
);
}

Expand Down

0 comments on commit 077767a

Please sign in to comment.