mirror of
https://github.com/openai/codex.git
synced 2026-04-24 06:35:50 +00:00
- creates custom event that emits subagent thread analytics from core - wires client metadata (`product_client_id, client_name, client_version`), through from app-server - creates `created_at `timestamp in core - subagent analytics are behind `FeatureFlag::GeneralAnalytics` PR stack - [[telemetry] thread events #15690](https://github.com/openai/codex/pull/15690) - --> [[telemetry] subagent events #15915](https://github.com/openai/codex/pull/15915) - [[telemetry] turn events #15591](https://github.com/openai/codex/pull/15591) - [[telemetry] steer events #15697](https://github.com/openai/codex/pull/15697) - [[telemetry] queued prompt data #15804](https://github.com/openai/codex/pull/15804) Notes: - core does not spawn a subagent thread for compact, but represented in mapping for consistency `INFO | 2026-04-01 13:08:12 | codex_backend.routers.analytics_events | analytics_events.track_analytics_events:399 | Tracked codex_thread_initialized event params={'thread_id': '019d4aa9-233b-70f2-a958-c3dbae1e30fa', 'product_surface': 'codex', 'app_server_client': {'product_client_id': 'CODEX_CLI', 'client_name': 'codex-tui', 'client_version': '0.0.0', 'rpc_transport': 'in_process', 'experimental_api_enabled': None}, 'runtime': {'codex_rs_version': '0.0.0', 'runtime_os': 'macos', 'runtime_os_version': '26.4.0', 'runtime_arch': 'aarch64'}, 'model': 'gpt-5.3-codex', 'ephemeral': False, 'initialization_mode': 'new', 'created_at': 1775074091, 'thread_source': 'subagent', 'subagent_source': 'thread_spawn', 'parent_thread_id': '019d4aa8-51ec-77e3-bafb-2c1b8e29e385'} | ` `INFO | 2026-04-01 13:08:41 | codex_backend.routers.analytics_events | analytics_events.track_analytics_events:399 | Tracked codex_thread_initialized event params={'thread_id': '019d4aa9-94e3-75f1-8864-ff8ad0e55e1e', 'product_surface': 'codex', 'app_server_client': {'product_client_id': 'CODEX_CLI', 'client_name': 'codex-tui', 'client_version': '0.0.0', 'rpc_transport': 'in_process', 'experimental_api_enabled': None}, 'runtime': {'codex_rs_version': '0.0.0', 'runtime_os': 'macos', 'runtime_os_version': '26.4.0', 'runtime_arch': 'aarch64'}, 'model': 'gpt-5.3-codex', 'ephemeral': False, 'initialization_mode': 'new', 'created_at': 1775074120, 'thread_source': 'subagent', 'subagent_source': 'review', 'parent_thread_id': None} | ` --------- Co-authored-by: jif-oai <jif@openai.com> Co-authored-by: Michael Bolin <mbolin@openai.com>
131 lines
3.2 KiB
Rust
131 lines
3.2 KiB
Rust
use crate::events::AppServerRpcTransport;
|
|
use crate::events::CodexRuntimeMetadata;
|
|
use codex_app_server_protocol::ClientRequest;
|
|
use codex_app_server_protocol::ClientResponse;
|
|
use codex_app_server_protocol::InitializeParams;
|
|
use codex_app_server_protocol::RequestId;
|
|
use codex_app_server_protocol::ServerNotification;
|
|
use codex_plugin::PluginTelemetryMetadata;
|
|
use codex_protocol::protocol::SkillScope;
|
|
use codex_protocol::protocol::SubAgentSource;
|
|
use serde::Serialize;
|
|
use std::path::PathBuf;
|
|
|
|
#[derive(Clone)]
|
|
pub struct TrackEventsContext {
|
|
pub model_slug: String,
|
|
pub thread_id: String,
|
|
pub turn_id: String,
|
|
}
|
|
|
|
pub fn build_track_events_context(
|
|
model_slug: String,
|
|
thread_id: String,
|
|
turn_id: String,
|
|
) -> TrackEventsContext {
|
|
TrackEventsContext {
|
|
model_slug,
|
|
thread_id,
|
|
turn_id,
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct SkillInvocation {
|
|
pub skill_name: String,
|
|
pub skill_scope: SkillScope,
|
|
pub skill_path: PathBuf,
|
|
pub invocation_type: InvocationType,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Serialize)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum InvocationType {
|
|
Explicit,
|
|
Implicit,
|
|
}
|
|
|
|
pub struct AppInvocation {
|
|
pub connector_id: Option<String>,
|
|
pub app_name: Option<String>,
|
|
pub invocation_type: Option<InvocationType>,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct SubAgentThreadStartedInput {
|
|
pub thread_id: String,
|
|
pub product_client_id: String,
|
|
pub client_name: String,
|
|
pub client_version: String,
|
|
pub model: String,
|
|
pub ephemeral: bool,
|
|
pub subagent_source: SubAgentSource,
|
|
pub created_at: u64,
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub(crate) enum AnalyticsFact {
|
|
Initialize {
|
|
connection_id: u64,
|
|
params: InitializeParams,
|
|
product_client_id: String,
|
|
runtime: CodexRuntimeMetadata,
|
|
rpc_transport: AppServerRpcTransport,
|
|
},
|
|
Request {
|
|
connection_id: u64,
|
|
request_id: RequestId,
|
|
request: Box<ClientRequest>,
|
|
},
|
|
Response {
|
|
connection_id: u64,
|
|
response: Box<ClientResponse>,
|
|
},
|
|
Notification(Box<ServerNotification>),
|
|
// Facts that do not naturally exist on the app-server protocol surface, or
|
|
// would require non-trivial protocol reshaping on this branch.
|
|
Custom(CustomAnalyticsFact),
|
|
}
|
|
|
|
pub(crate) enum CustomAnalyticsFact {
|
|
SubAgentThreadStarted(SubAgentThreadStartedInput),
|
|
SkillInvoked(SkillInvokedInput),
|
|
AppMentioned(AppMentionedInput),
|
|
AppUsed(AppUsedInput),
|
|
PluginUsed(PluginUsedInput),
|
|
PluginStateChanged(PluginStateChangedInput),
|
|
}
|
|
|
|
pub(crate) struct SkillInvokedInput {
|
|
pub tracking: TrackEventsContext,
|
|
pub invocations: Vec<SkillInvocation>,
|
|
}
|
|
|
|
pub(crate) struct AppMentionedInput {
|
|
pub tracking: TrackEventsContext,
|
|
pub mentions: Vec<AppInvocation>,
|
|
}
|
|
|
|
pub(crate) struct AppUsedInput {
|
|
pub tracking: TrackEventsContext,
|
|
pub app: AppInvocation,
|
|
}
|
|
|
|
pub(crate) struct PluginUsedInput {
|
|
pub tracking: TrackEventsContext,
|
|
pub plugin: PluginTelemetryMetadata,
|
|
}
|
|
|
|
pub(crate) struct PluginStateChangedInput {
|
|
pub plugin: PluginTelemetryMetadata,
|
|
pub state: PluginState,
|
|
}
|
|
|
|
#[derive(Clone, Copy)]
|
|
pub(crate) enum PluginState {
|
|
Installed,
|
|
Uninstalled,
|
|
Enabled,
|
|
Disabled,
|
|
}
|