Lightweight coding agent that runs in your terminal
Rust
feat: add session source as otel metadata tag (#9720)
alexsong-oai0fa45fbca4a3
diff --git a/codex-rs/otel/src/lib.rs b/codex-rs/otel/src/lib.rsindex 32540d1071..93975cbf9d 100644--- a/codex-rs/otel/src/lib.rs+++ b/codex-rs/otel/src/lib.rs@@ -31,6 +31,7 @@ pub struct OtelEventMetadata {pub(crate) auth_mode: Option<String>,pub(crate) account_id: Option<String>,pub(crate) account_email: Option<String>,+ pub(crate) session_source: String,pub(crate) model: String,pub(crate) slug: String,pub(crate) log_user_prompts: bool,@@ -149,8 +150,13 @@ impl OtelManager {if !self.metrics_use_metadata_tags {return Ok(Vec::new());}- let mut tags = Vec::with_capacity(5);+ let mut tags = Vec::with_capacity(6);Self::push_metadata_tag(&mut tags, "auth_mode", self.metadata.auth_mode.as_deref())?;+ Self::push_metadata_tag(+ &mut tags,+ "session_source",+ Some(self.metadata.session_source.as_str()),+ )?;Self::push_metadata_tag(&mut tags, "model", Some(self.metadata.model.as_str()))?;Self::push_metadata_tag(&mut tags, "app.version", Some(self.metadata.app_version))?;Ok(tags)diff --git a/codex-rs/otel/src/traces/otel_manager.rs b/codex-rs/otel/src/traces/otel_manager.rsindex 0847fd882a..7ce411970c 100644--- a/codex-rs/otel/src/traces/otel_manager.rs+++ b/codex-rs/otel/src/traces/otel_manager.rs@@ -40,7 +40,7 @@ impl OtelManager {auth_mode: Option<AuthMode>,log_user_prompts: bool,terminal_type: String,- _session_source: SessionSource,+ session_source: SessionSource,) -> OtelManager {Self {metadata: OtelEventMetadata {@@ -48,6 +48,7 @@ impl OtelManager {auth_mode: auth_mode.map(|m| m.to_string()),account_id,account_email,+ session_source: session_source.to_string(),model: model.to_owned(),slug: slug.to_owned(),log_user_prompts,diff --git a/codex-rs/otel/tests/suite/manager_metrics.rs b/codex-rs/otel/tests/suite/manager_metrics.rsindex 1497a5f84c..ad98543bc1 100644--- a/codex-rs/otel/tests/suite/manager_metrics.rs+++ b/codex-rs/otel/tests/suite/manager_metrics.rs@@ -55,6 +55,7 @@ fn manager_attaches_metadata_tags_to_metrics() -> Result<()> {("auth_mode".to_string(), AuthMode::ApiKey.to_string()),("model".to_string(), "gpt-5.1".to_string()),("service".to_string(), "codex-cli".to_string()),+ ("session_source".to_string(), "cli".to_string()),("source".to_string(), "tui".to_string()),]);assert_eq!(attrs, expected);