mirror of
https://github.com/openai/codex.git
synced 2026-02-01 22:47:52 +00:00
feat: add session source as otel metadata tag (#9720)
Add session.source and user.account_id as global OTEL metric tags to identify client surface and user.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user