mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
## 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
66 lines
2.3 KiB
Rust
66 lines
2.3 KiB
Rust
//! Records automatic daemon startup and ensures launch observations survive setup failures.
|
|
|
|
use super::*;
|
|
|
|
/// Emit once after connection, or as unconfirmed if startup returns early.
|
|
pub(super) struct Launch<F: FnOnce(&AppServerTarget, bool)>(pub(super) Option<F>);
|
|
|
|
impl<F: FnOnce(&AppServerTarget, bool)> Launch<F> {
|
|
pub(super) fn record(mut self, target: &AppServerTarget, connected: bool) {
|
|
if let Some(record) = self.0.take() {
|
|
record(target, connected);
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<F: FnOnce(&AppServerTarget, bool)> Drop for Launch<F> {
|
|
fn drop(&mut self) {
|
|
if let Some(record) = self.0.take() {
|
|
record(&AppServerTarget::Embedded, /*connected*/ false);
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(super) async fn record_start(
|
|
config: &Config,
|
|
result: &anyhow::Result<codex_app_server_daemon::LifecycleOutput>,
|
|
) {
|
|
use codex_app_server_daemon::LifecycleStatus;
|
|
let outcome = match result {
|
|
Ok(output) => match output.status {
|
|
LifecycleStatus::Started => "started",
|
|
LifecycleStatus::AlreadyRunning => "already_running",
|
|
LifecycleStatus::Restarted => "restarted",
|
|
LifecycleStatus::Stopped | LifecycleStatus::NotRunning | LifecycleStatus::Running => {
|
|
"unconfirmed"
|
|
}
|
|
},
|
|
Err(_) => "failed",
|
|
};
|
|
// Failure can happen before normal TUI telemetry is initialized. This short-lived
|
|
// provider uses exactly the same consent and identity construction as TUI startup.
|
|
let Ok(Ok(Some(otel))) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
|
codex_app_server_client::build_otel_provider(
|
|
config,
|
|
env!("CARGO_PKG_VERSION"),
|
|
/*service_name_override*/ None,
|
|
/*default_analytics_enabled*/ true,
|
|
)
|
|
})) 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", "tui_auto_start"),
|
|
("outcome", outcome),
|
|
]);
|
|
let _ = metrics.counter("codex.daemon.start", /*inc*/ 1, &tags);
|
|
}
|
|
let _ = otel
|
|
.shutdown_with_timeout(INTERACTIVE_OTEL_SHUTDOWN_TIMEOUT)
|
|
.await;
|
|
}
|