Add telemetry::event! (#22146)

CC @JosephTLyons

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin 2024-12-17 11:39:18 -07:00 committed by GitHub
parent b17f2089a2
commit 7425d242bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 179 additions and 140 deletions

View file

@ -43,6 +43,7 @@ serde.workspace = true
serde_json.workspace = true
settings.workspace = true
smol.workspace = true
telemetry.workspace = true
terminal.workspace = true
terminal_view.workspace = true
theme.workspace = true

View file

@ -24,16 +24,15 @@ pub use crate::repl_sessions_ui::{
};
use crate::repl_store::ReplStore;
pub use crate::session::Session;
use client::telemetry::Telemetry;
pub const KERNEL_DOCS_URL: &str = "https://zed.dev/docs/repl#changing-kernels";
pub fn init(fs: Arc<dyn Fs>, telemetry: Arc<Telemetry>, cx: &mut AppContext) {
pub fn init(fs: Arc<dyn Fs>, cx: &mut AppContext) {
set_dispatcher(zed_dispatcher(cx));
JupyterSettings::register(cx);
::editor::init_settings(cx);
repl_sessions_ui::init(cx);
ReplStore::init(fs, telemetry, cx);
ReplStore::init(fs, cx);
}
fn zed_dispatcher(cx: &mut AppContext) -> impl Dispatcher {

View file

@ -33,7 +33,6 @@ pub fn assign_kernelspec(
});
let fs = store.read(cx).fs().clone();
let telemetry = store.read(cx).telemetry().clone();
if let Some(session) = store.read(cx).get_session(weak_editor.entity_id()).cloned() {
// Drop previous session, start new one
@ -44,8 +43,7 @@ pub fn assign_kernelspec(
});
}
let session = cx
.new_view(|cx| Session::new(weak_editor.clone(), fs, telemetry, kernel_specification, cx));
let session = cx.new_view(|cx| Session::new(weak_editor.clone(), fs, kernel_specification, cx));
weak_editor
.update(cx, |_editor, cx| {
@ -105,15 +103,13 @@ pub fn run(editor: WeakView<Editor>, move_down: bool, cx: &mut WindowContext) ->
.ok_or_else(|| anyhow::anyhow!("No kernel found for language: {}", language.name()))?;
let fs = store.read(cx).fs().clone();
let telemetry = store.read(cx).telemetry().clone();
let session = if let Some(session) = store.read(cx).get_session(editor.entity_id()).cloned()
{
session
} else {
let weak_editor = editor.downgrade();
let session = cx
.new_view(|cx| Session::new(weak_editor, fs, telemetry, kernel_specification, cx));
let session = cx.new_view(|cx| Session::new(weak_editor, fs, kernel_specification, cx));
editor.update(cx, |_editor, cx| {
cx.notify();

View file

@ -1,7 +1,6 @@
use std::sync::Arc;
use anyhow::Result;
use client::telemetry::Telemetry;
use collections::HashMap;
use command_palette_hooks::CommandPaletteFilter;
use gpui::{
@ -28,15 +27,14 @@ pub struct ReplStore {
kernel_specifications: Vec<KernelSpecification>,
selected_kernel_for_worktree: HashMap<WorktreeId, KernelSpecification>,
kernel_specifications_for_worktree: HashMap<WorktreeId, Vec<KernelSpecification>>,
telemetry: Arc<Telemetry>,
_subscriptions: Vec<Subscription>,
}
impl ReplStore {
const NAMESPACE: &'static str = "repl";
pub(crate) fn init(fs: Arc<dyn Fs>, telemetry: Arc<Telemetry>, cx: &mut AppContext) {
let store = cx.new_model(move |cx| Self::new(fs, telemetry, cx));
pub(crate) fn init(fs: Arc<dyn Fs>, cx: &mut AppContext) {
let store = cx.new_model(move |cx| Self::new(fs, cx));
store
.update(cx, |store, cx| store.refresh_kernelspecs(cx))
@ -49,14 +47,13 @@ impl ReplStore {
cx.global::<GlobalReplStore>().0.clone()
}
pub fn new(fs: Arc<dyn Fs>, telemetry: Arc<Telemetry>, cx: &mut ModelContext<Self>) -> Self {
pub fn new(fs: Arc<dyn Fs>, cx: &mut ModelContext<Self>) -> Self {
let subscriptions = vec![cx.observe_global::<SettingsStore>(move |this, cx| {
this.set_enabled(JupyterSettings::enabled(cx), cx);
})];
let this = Self {
fs,
telemetry,
enabled: JupyterSettings::enabled(cx),
sessions: HashMap::default(),
kernel_specifications: Vec::new(),
@ -72,10 +69,6 @@ impl ReplStore {
&self.fs
}
pub fn telemetry(&self) -> &Arc<Telemetry> {
&self.telemetry
}
pub fn is_enabled(&self) -> bool {
self.enabled
}

View file

@ -6,7 +6,6 @@ use crate::{
outputs::{ExecutionStatus, ExecutionView},
KernelStatus,
};
use client::telemetry::Telemetry;
use collections::{HashMap, HashSet};
use editor::{
display_map::{
@ -37,7 +36,6 @@ pub struct Session {
pub kernel: Kernel,
blocks: HashMap<String, EditorBlock>,
pub kernel_specification: KernelSpecification,
telemetry: Arc<Telemetry>,
_buffer_subscription: Subscription,
}
@ -194,7 +192,6 @@ impl Session {
pub fn new(
editor: WeakView<Editor>,
fs: Arc<dyn Fs>,
telemetry: Arc<Telemetry>,
kernel_specification: KernelSpecification,
cx: &mut ViewContext<Self>,
) -> Self {
@ -221,7 +218,6 @@ impl Session {
blocks: HashMap::default(),
kernel_specification,
_buffer_subscription: subscription,
telemetry,
};
session.start_kernel(cx);
@ -237,10 +233,11 @@ impl Session {
.and_then(|editor| editor.read(cx).working_directory(cx))
.unwrap_or_else(temp_dir);
self.telemetry.report_repl_event(
kernel_language.into(),
KernelStatus::Starting.to_string(),
cx.entity_id().to_string(),
telemetry::event!(
"Kernel Status Changed",
kernel_language,
kernel_status = KernelStatus::Starting.to_string(),
repl_session_id = cx.entity_id().to_string(),
);
let session_view = cx.view().clone();
@ -488,10 +485,11 @@ impl Session {
JupyterMessageContent::Status(status) => {
self.kernel.set_execution_state(&status.execution_state);
self.telemetry.report_repl_event(
self.kernel_specification.language().into(),
KernelStatus::from(&self.kernel).to_string(),
cx.entity_id().to_string(),
telemetry::event!(
"Kernel Status Changed",
kernel_language = self.kernel_specification.language(),
kernel_status = KernelStatus::from(&self.kernel).to_string(),
repl_session_id = cx.entity_id().to_string(),
);
cx.notify();
@ -540,12 +538,13 @@ impl Session {
}
let kernel_status = KernelStatus::from(&kernel).to_string();
let kernel_language = self.kernel_specification.language().into();
let kernel_language = self.kernel_specification.language();
self.telemetry.report_repl_event(
telemetry::event!(
"Kernel Status Changed",
kernel_language,
kernel_status,
cx.entity_id().to_string(),
repl_session_id = cx.entity_id().to_string(),
);
self.kernel = kernel;