Skip to content

Commit 0fa45fb

Browse files
authored
feat: add session source as otel metadata tag (openai#9720)
Add session.source and user.account_id as global OTEL metric tags to identify client surface and user.
1 parent 02fced2 commit 0fa45fb

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

codex-rs/otel/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub struct OtelEventMetadata {
3131
pub(crate) auth_mode: Option<String>,
3232
pub(crate) account_id: Option<String>,
3333
pub(crate) account_email: Option<String>,
34+
pub(crate) session_source: String,
3435
pub(crate) model: String,
3536
pub(crate) slug: String,
3637
pub(crate) log_user_prompts: bool,
@@ -149,8 +150,13 @@ impl OtelManager {
149150
if !self.metrics_use_metadata_tags {
150151
return Ok(Vec::new());
151152
}
152-
let mut tags = Vec::with_capacity(5);
153+
let mut tags = Vec::with_capacity(6);
153154
Self::push_metadata_tag(&mut tags, "auth_mode", self.metadata.auth_mode.as_deref())?;
155+
Self::push_metadata_tag(
156+
&mut tags,
157+
"session_source",
158+
Some(self.metadata.session_source.as_str()),
159+
)?;
154160
Self::push_metadata_tag(&mut tags, "model", Some(self.metadata.model.as_str()))?;
155161
Self::push_metadata_tag(&mut tags, "app.version", Some(self.metadata.app_version))?;
156162
Ok(tags)

codex-rs/otel/src/traces/otel_manager.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ impl OtelManager {
4040
auth_mode: Option<AuthMode>,
4141
log_user_prompts: bool,
4242
terminal_type: String,
43-
_session_source: SessionSource,
43+
session_source: SessionSource,
4444
) -> OtelManager {
4545
Self {
4646
metadata: OtelEventMetadata {
4747
conversation_id,
4848
auth_mode: auth_mode.map(|m| m.to_string()),
4949
account_id,
5050
account_email,
51+
session_source: session_source.to_string(),
5152
model: model.to_owned(),
5253
slug: slug.to_owned(),
5354
log_user_prompts,

codex-rs/otel/tests/suite/manager_metrics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ fn manager_attaches_metadata_tags_to_metrics() -> Result<()> {
5555
("auth_mode".to_string(), AuthMode::ApiKey.to_string()),
5656
("model".to_string(), "gpt-5.1".to_string()),
5757
("service".to_string(), "codex-cli".to_string()),
58+
("session_source".to_string(), "cli".to_string()),
5859
("source".to_string(), "tui".to_string()),
5960
]);
6061
assert_eq!(attrs, expected);

0 commit comments

Comments
 (0)