mirror of
https://github.com/openai/codex.git
synced 2026-11-06 20:20:34 +00:00
Add originator to metrics
This commit is contained in:
@@ -17,6 +17,7 @@ use crate::compact;
|
||||
use crate::compact::run_inline_auto_compact_task;
|
||||
use crate::compact::should_use_remote_compact_task;
|
||||
use crate::compact_remote::run_inline_remote_auto_compact_task;
|
||||
use crate::default_client::originator;
|
||||
use crate::exec_policy::ExecPolicyManager;
|
||||
use crate::features::Feature;
|
||||
use crate::features::Features;
|
||||
@@ -657,6 +658,7 @@ impl Session {
|
||||
auth.and_then(CodexAuth::get_account_id),
|
||||
auth.and_then(CodexAuth::get_account_email),
|
||||
auth.map(|a| a.mode),
|
||||
originator().value,
|
||||
config.otel.log_user_prompt,
|
||||
terminal::user_agent(),
|
||||
session_configuration.session_source.clone(),
|
||||
@@ -3816,6 +3818,7 @@ mod tests {
|
||||
None,
|
||||
Some("test@test.com".to_string()),
|
||||
Some(AuthMode::ChatGPT),
|
||||
originator().value,
|
||||
false,
|
||||
"test".to_string(),
|
||||
session_source,
|
||||
|
||||
@@ -83,6 +83,7 @@ async fn run_request(input: Vec<ResponseItem>) -> Value {
|
||||
None,
|
||||
Some("test@test.com".to_string()),
|
||||
Some(AuthMode::ApiKey),
|
||||
"test_originator".to_string(),
|
||||
false,
|
||||
"test".to_string(),
|
||||
SessionSource::Exec,
|
||||
|
||||
@@ -84,6 +84,7 @@ async fn run_stream_with_bytes(sse_body: &[u8]) -> Vec<ResponseEvent> {
|
||||
None,
|
||||
Some("test@test.com".to_string()),
|
||||
auth_mode,
|
||||
"test_originator".to_string(),
|
||||
false,
|
||||
"test".to_string(),
|
||||
SessionSource::Exec,
|
||||
|
||||
@@ -79,6 +79,7 @@ async fn responses_stream_includes_subagent_header_on_review() {
|
||||
None,
|
||||
Some("test@test.com".to_string()),
|
||||
Some(auth_mode),
|
||||
"test_originator".to_string(),
|
||||
false,
|
||||
"test".to_string(),
|
||||
session_source.clone(),
|
||||
@@ -175,6 +176,7 @@ async fn responses_stream_includes_subagent_header_on_other() {
|
||||
None,
|
||||
Some("test@test.com".to_string()),
|
||||
Some(auth_mode),
|
||||
"test_originator".to_string(),
|
||||
false,
|
||||
"test".to_string(),
|
||||
session_source.clone(),
|
||||
@@ -329,6 +331,7 @@ async fn responses_respects_model_info_overrides_from_config() {
|
||||
None,
|
||||
Some("test@test.com".to_string()),
|
||||
auth_mode,
|
||||
"test_originator".to_string(),
|
||||
false,
|
||||
"test".to_string(),
|
||||
session_source.clone(),
|
||||
|
||||
@@ -1240,6 +1240,7 @@ async fn azure_responses_request_includes_store_and_reasoning_ids() {
|
||||
None,
|
||||
Some("test@test.com".to_string()),
|
||||
auth_manager.get_auth_mode(),
|
||||
"test_originator".to_string(),
|
||||
false,
|
||||
"test".to_string(),
|
||||
SessionSource::Exec,
|
||||
|
||||
@@ -177,6 +177,7 @@ async fn websocket_harness(server: &WebSocketTestServer) -> WebsocketTestHarness
|
||||
None,
|
||||
Some("test@test.com".to_string()),
|
||||
auth_manager.get_auth_mode(),
|
||||
"test_originator".to_string(),
|
||||
false,
|
||||
"test".to_string(),
|
||||
SessionSource::Exec,
|
||||
|
||||
@@ -63,6 +63,7 @@ let manager = OtelManager::new(
|
||||
account_id,
|
||||
account_email,
|
||||
auth_mode,
|
||||
originator,
|
||||
log_user_prompts,
|
||||
terminal_type,
|
||||
session_source,
|
||||
|
||||
@@ -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) originator: 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,
|
||||
"originator",
|
||||
Some(self.metadata.originator.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)
|
||||
|
||||
@@ -38,6 +38,7 @@ impl OtelManager {
|
||||
account_id: Option<String>,
|
||||
account_email: Option<String>,
|
||||
auth_mode: Option<AuthMode>,
|
||||
originator: String,
|
||||
log_user_prompts: bool,
|
||||
terminal_type: String,
|
||||
_session_source: SessionSource,
|
||||
@@ -48,6 +49,7 @@ impl OtelManager {
|
||||
auth_mode: auth_mode.map(|m| m.to_string()),
|
||||
account_id,
|
||||
account_email,
|
||||
originator,
|
||||
model: model.to_owned(),
|
||||
slug: slug.to_owned(),
|
||||
log_user_prompts,
|
||||
|
||||
@@ -23,6 +23,7 @@ fn manager_attaches_metadata_tags_to_metrics() -> Result<()> {
|
||||
Some("account-id".to_string()),
|
||||
None,
|
||||
Some(AuthMode::ApiKey),
|
||||
"originator_123".to_string(),
|
||||
true,
|
||||
"tty".to_string(),
|
||||
SessionSource::Cli,
|
||||
@@ -54,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()),
|
||||
("originator".to_string(), "originator_123".to_string()),
|
||||
("service".to_string(), "codex-cli".to_string()),
|
||||
("source".to_string(), "tui".to_string()),
|
||||
]);
|
||||
@@ -73,6 +75,7 @@ fn manager_allows_disabling_metadata_tags() -> Result<()> {
|
||||
Some("account-id".to_string()),
|
||||
None,
|
||||
Some(AuthMode::ApiKey),
|
||||
"codex_cli_rs".to_string(),
|
||||
true,
|
||||
"tty".to_string(),
|
||||
SessionSource::Cli,
|
||||
|
||||
Reference in New Issue
Block a user