Don't write temp files for telemetry logs (#20209)
This still keeps a telemetry.log for the current session, but not one file per load of zed. Closes: #20045 Release Notes: - Fixed a bug where Zed would create a new temporary file on each boot for telemetry logs
This commit is contained in:
parent
765626a007
commit
66e06616db
4 changed files with 8 additions and 15 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2432,7 +2432,6 @@ dependencies = [
|
||||||
"smol",
|
"smol",
|
||||||
"sysinfo",
|
"sysinfo",
|
||||||
"telemetry_events",
|
"telemetry_events",
|
||||||
"tempfile",
|
|
||||||
"text",
|
"text",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"time",
|
"time",
|
||||||
|
|
|
@ -44,7 +44,6 @@ sha2.workspace = true
|
||||||
smol.workspace = true
|
smol.workspace = true
|
||||||
sysinfo.workspace = true
|
sysinfo.workspace = true
|
||||||
telemetry_events.workspace = true
|
telemetry_events.workspace = true
|
||||||
tempfile.workspace = true
|
|
||||||
text.workspace = true
|
text.workspace = true
|
||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
time.workspace = true
|
time.workspace = true
|
||||||
|
|
|
@ -13,6 +13,7 @@ use parking_lot::Mutex;
|
||||||
use release_channel::ReleaseChannel;
|
use release_channel::ReleaseChannel;
|
||||||
use settings::{Settings, SettingsStore};
|
use settings::{Settings, SettingsStore};
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
|
use std::fs::File;
|
||||||
use std::io::Write;
|
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};
|
||||||
|
@ -21,10 +22,7 @@ use telemetry_events::{
|
||||||
EventRequestBody, EventWrapper, ExtensionEvent, InlineCompletionEvent, MemoryEvent, ReplEvent,
|
EventRequestBody, EventWrapper, ExtensionEvent, InlineCompletionEvent, MemoryEvent, ReplEvent,
|
||||||
SettingEvent,
|
SettingEvent,
|
||||||
};
|
};
|
||||||
use tempfile::NamedTempFile;
|
use util::{ResultExt, TryFutureExt};
|
||||||
#[cfg(not(debug_assertions))]
|
|
||||||
use util::ResultExt;
|
|
||||||
use util::TryFutureExt;
|
|
||||||
use worktree::{UpdatedEntriesSet, WorktreeId};
|
use worktree::{UpdatedEntriesSet, WorktreeId};
|
||||||
|
|
||||||
use self::event_coalescer::EventCoalescer;
|
use self::event_coalescer::EventCoalescer;
|
||||||
|
@ -46,7 +44,7 @@ struct TelemetryState {
|
||||||
architecture: &'static str,
|
architecture: &'static str,
|
||||||
events_queue: Vec<EventWrapper>,
|
events_queue: Vec<EventWrapper>,
|
||||||
flush_events_task: Option<Task<()>>,
|
flush_events_task: Option<Task<()>>,
|
||||||
log_file: Option<NamedTempFile>,
|
log_file: Option<File>,
|
||||||
is_staff: Option<bool>,
|
is_staff: Option<bool>,
|
||||||
first_event_date_time: Option<DateTime<Utc>>,
|
first_event_date_time: Option<DateTime<Utc>>,
|
||||||
event_coalescer: EventCoalescer,
|
event_coalescer: EventCoalescer,
|
||||||
|
@ -223,15 +221,13 @@ impl Telemetry {
|
||||||
os_name: os_name(),
|
os_name: os_name(),
|
||||||
app_version: release_channel::AppVersion::global(cx).to_string(),
|
app_version: release_channel::AppVersion::global(cx).to_string(),
|
||||||
}));
|
}));
|
||||||
|
Self::log_file_path();
|
||||||
|
|
||||||
#[cfg(not(debug_assertions))]
|
|
||||||
cx.background_executor()
|
cx.background_executor()
|
||||||
.spawn({
|
.spawn({
|
||||||
let state = state.clone();
|
let state = state.clone();
|
||||||
async move {
|
async move {
|
||||||
if let Some(tempfile) =
|
if let Some(tempfile) = File::create(Self::log_file_path()).log_err() {
|
||||||
NamedTempFile::new_in(paths::logs_dir().as_path()).log_err()
|
|
||||||
{
|
|
||||||
state.lock().log_file = Some(tempfile);
|
state.lock().log_file = Some(tempfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,8 +276,8 @@ impl Telemetry {
|
||||||
Task::ready(())
|
Task::ready(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn log_file_path(&self) -> Option<PathBuf> {
|
pub fn log_file_path() -> PathBuf {
|
||||||
Some(self.state.lock().log_file.as_ref()?.path().to_path_buf())
|
paths::logs_dir().join("telemetry.log")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(
|
pub fn start(
|
||||||
|
@ -645,7 +641,6 @@ impl Telemetry {
|
||||||
let mut json_bytes = Vec::new();
|
let mut json_bytes = Vec::new();
|
||||||
|
|
||||||
if let Some(file) = &mut this.state.lock().log_file {
|
if let Some(file) = &mut this.state.lock().log_file {
|
||||||
let file = file.as_file_mut();
|
|
||||||
for event in &mut events {
|
for event in &mut events {
|
||||||
json_bytes.clear();
|
json_bytes.clear();
|
||||||
serde_json::to_writer(&mut json_bytes, event)?;
|
serde_json::to_writer(&mut json_bytes, event)?;
|
||||||
|
|
|
@ -999,7 +999,7 @@ fn open_telemetry_log_file(workspace: &mut Workspace, cx: &mut ViewContext<Works
|
||||||
let app_state = workspace.app_state().clone();
|
let app_state = workspace.app_state().clone();
|
||||||
cx.spawn(|workspace, mut cx| async move {
|
cx.spawn(|workspace, mut cx| async move {
|
||||||
async fn fetch_log_string(app_state: &Arc<AppState>) -> Option<String> {
|
async fn fetch_log_string(app_state: &Arc<AppState>) -> Option<String> {
|
||||||
let path = app_state.client.telemetry().log_file_path()?;
|
let path = client::telemetry::Telemetry::log_file_path();
|
||||||
app_state.fs.load(&path).await.log_err()
|
app_state.fs.load(&path).await.log_err()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue