mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Record daemon startup and update telemetry with consent handling (#46126)
## Why TUI startup metrics report the selected app-server mode before a connection succeeds, which can misrepresent embedded fallback or failed startup. Daemon startup and update actions also need distinct outcome observations. ## What changed - Record `codex.tui.start` once after the first connection attempt, using the actual mode or `unconfirmed`, and include daemon selection and auto-start tags. - Add `codex.daemon.start` for TUI auto-start and `codex.daemon.update` for foreground CLI updates and TUI update handoffs, using existing analytics consent and identity handling. - Report TUI handoffs as `handoff_requested` and suppress duplicate child reporting. Remove the suppression flag when spawning long-lived daemon processes. - Tag daemon settings by enabled state and explicit presence, without exporting setting values or contents; report invalid or unreadable settings as `unknown`. ## Testing Add coverage for analytics defaults and explicit consent overrides, unconfirmed CLI updates, settings presence, and exactly-once launch observations. Extend the worktree TUI test to check startup tags and a single update handoff observation. GitOrigin-RevId: 176d2ee594f930033fa1ece55d4c1c9603dbbc16
This commit is contained in:
1 parent
1bd1bfa7ca
commit
b0659c5386
13 files changed
+454
-33
No files matched your search
@@ -0,0 +1,60 @@
|
||||
//! Foreground daemon observations use the CLI's existing consent and identity handling.
|
||||
//! Detached updater entry points never call this module.
|
||||
|
||||
use codex_utils_cli::CliConfigOverrides;
|
||||
use std::time::Duration;
|
||||
use tokio::time::timeout;
|
||||
|
||||
pub(crate) async fn record_command(
|
||||
overrides: &CliConfigOverrides,
|
||||
analytics_default_enabled: bool,
|
||||
target: &'static str,
|
||||
result: &anyhow::Result<Option<codex_app_server_daemon::UpdateOutput>>,
|
||||
) {
|
||||
if std::env::var_os(codex_app_server_daemon::telemetry::HANDOFF_ENV).is_some() {
|
||||
return;
|
||||
}
|
||||
// Skip telemetry if consent-aware configuration cannot be loaded promptly.
|
||||
let Ok(Ok(config)) = timeout(
|
||||
Duration::from_secs(/*secs*/ 2),
|
||||
crate::cloud_config::load_config(overrides, codex_config::LoaderOverrides::default()),
|
||||
)
|
||||
.await
|
||||
else {
|
||||
return;
|
||||
};
|
||||
use codex_app_server_daemon::UpdateStatus;
|
||||
let outcome = match result {
|
||||
Ok(Some(output)) => match output.status {
|
||||
UpdateStatus::Updated => "updated",
|
||||
UpdateStatus::NoUpdate => "no_update",
|
||||
UpdateStatus::Unsupported => "unsupported",
|
||||
},
|
||||
Ok(None) => "cancelled",
|
||||
Err(_) => "unconfirmed",
|
||||
};
|
||||
let Ok(Ok(Some(otel))) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||
codex_core::otel_init::build_provider(
|
||||
&config,
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
/*service_name_override*/ None,
|
||||
analytics_default_enabled,
|
||||
)
|
||||
})) else {
|
||||
return;
|
||||
};
|
||||
if let Some(metrics) = otel.metrics() {
|
||||
let mut tags = codex_app_server_daemon::telemetry::settings_tags(&config.codex_home)
|
||||
.await
|
||||
.to_vec();
|
||||
tags.extend([
|
||||
("initiation_source", "cli"),
|
||||
("update_target", target),
|
||||
("outcome", outcome),
|
||||
]);
|
||||
let _ = metrics.counter("codex.daemon.update", /*inc*/ 1, &tags);
|
||||
}
|
||||
let _ = otel
|
||||
.shutdown_with_timeout(std::time::Duration::from_secs(/*secs*/ 2))
|
||||
.await;
|
||||
}
|
||||
Reference in new issue
Block a user