[codex][otel] propagate user email in otel events (#5223)
include user email into otel events for proper user-level attribution in case of workspace setup
This commit is contained in:
@@ -135,6 +135,10 @@ impl CodexAuth {
|
|||||||
self.get_current_token_data().and_then(|t| t.account_id)
|
self.get_current_token_data().and_then(|t| t.account_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_account_email(&self) -> Option<String> {
|
||||||
|
self.get_current_token_data().and_then(|t| t.id_token.email)
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn get_plan_type(&self) -> Option<PlanType> {
|
pub(crate) fn get_plan_type(&self) -> Option<PlanType> {
|
||||||
self.get_current_token_data()
|
self.get_current_token_data()
|
||||||
.and_then(|t| t.id_token.chatgpt_plan_type)
|
.and_then(|t| t.id_token.chatgpt_plan_type)
|
||||||
|
|||||||
@@ -1030,6 +1030,7 @@ mod tests {
|
|||||||
"test",
|
"test",
|
||||||
"test",
|
"test",
|
||||||
None,
|
None,
|
||||||
|
Some("test@test.com".to_string()),
|
||||||
Some(AuthMode::ChatGPT),
|
Some(AuthMode::ChatGPT),
|
||||||
false,
|
false,
|
||||||
"test".to_string(),
|
"test".to_string(),
|
||||||
|
|||||||
@@ -445,6 +445,7 @@ impl Session {
|
|||||||
config.model.as_str(),
|
config.model.as_str(),
|
||||||
config.model_family.slug.as_str(),
|
config.model_family.slug.as_str(),
|
||||||
auth_manager.auth().and_then(|a| a.get_account_id()),
|
auth_manager.auth().and_then(|a| a.get_account_id()),
|
||||||
|
auth_manager.auth().and_then(|a| a.get_account_email()),
|
||||||
auth_manager.auth().map(|a| a.mode),
|
auth_manager.auth().map(|a| a.mode),
|
||||||
config.otel.log_user_prompt,
|
config.otel.log_user_prompt,
|
||||||
terminal::user_agent(),
|
terminal::user_agent(),
|
||||||
@@ -2744,6 +2745,7 @@ mod tests {
|
|||||||
config.model.as_str(),
|
config.model.as_str(),
|
||||||
config.model_family.slug.as_str(),
|
config.model_family.slug.as_str(),
|
||||||
None,
|
None,
|
||||||
|
Some("test@test.com".to_string()),
|
||||||
Some(AuthMode::ChatGPT),
|
Some(AuthMode::ChatGPT),
|
||||||
false,
|
false,
|
||||||
"test".to_string(),
|
"test".to_string(),
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ async fn run_request(input: Vec<ResponseItem>) -> Value {
|
|||||||
config.model.as_str(),
|
config.model.as_str(),
|
||||||
config.model_family.slug.as_str(),
|
config.model_family.slug.as_str(),
|
||||||
None,
|
None,
|
||||||
|
Some("test@test.com".to_string()),
|
||||||
Some(AuthMode::ChatGPT),
|
Some(AuthMode::ChatGPT),
|
||||||
false,
|
false,
|
||||||
"test".to_string(),
|
"test".to_string(),
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ async fn run_stream_with_bytes(sse_body: &[u8]) -> Vec<ResponseEvent> {
|
|||||||
config.model.as_str(),
|
config.model.as_str(),
|
||||||
config.model_family.slug.as_str(),
|
config.model_family.slug.as_str(),
|
||||||
None,
|
None,
|
||||||
|
Some("test@test.com".to_string()),
|
||||||
Some(AuthMode::ChatGPT),
|
Some(AuthMode::ChatGPT),
|
||||||
false,
|
false,
|
||||||
"test".to_string(),
|
"test".to_string(),
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ async fn responses_stream_includes_task_type_header() {
|
|||||||
config.model.as_str(),
|
config.model.as_str(),
|
||||||
config.model_family.slug.as_str(),
|
config.model_family.slug.as_str(),
|
||||||
None,
|
None,
|
||||||
|
Some("test@test.com".to_string()),
|
||||||
Some(AuthMode::ChatGPT),
|
Some(AuthMode::ChatGPT),
|
||||||
false,
|
false,
|
||||||
"test".to_string(),
|
"test".to_string(),
|
||||||
|
|||||||
@@ -657,6 +657,7 @@ async fn azure_responses_request_includes_store_and_reasoning_ids() {
|
|||||||
config.model.as_str(),
|
config.model.as_str(),
|
||||||
config.model_family.slug.as_str(),
|
config.model_family.slug.as_str(),
|
||||||
None,
|
None,
|
||||||
|
Some("test@test.com".to_string()),
|
||||||
Some(AuthMode::ChatGPT),
|
Some(AuthMode::ChatGPT),
|
||||||
false,
|
false,
|
||||||
"test".to_string(),
|
"test".to_string(),
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ pub struct OtelEventMetadata {
|
|||||||
conversation_id: ConversationId,
|
conversation_id: ConversationId,
|
||||||
auth_mode: Option<String>,
|
auth_mode: Option<String>,
|
||||||
account_id: Option<String>,
|
account_id: Option<String>,
|
||||||
|
account_email: Option<String>,
|
||||||
model: String,
|
model: String,
|
||||||
slug: String,
|
slug: String,
|
||||||
log_user_prompts: bool,
|
log_user_prompts: bool,
|
||||||
@@ -46,11 +47,13 @@ pub struct OtelEventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl OtelEventManager {
|
impl OtelEventManager {
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
conversation_id: ConversationId,
|
conversation_id: ConversationId,
|
||||||
model: &str,
|
model: &str,
|
||||||
slug: &str,
|
slug: &str,
|
||||||
account_id: Option<String>,
|
account_id: Option<String>,
|
||||||
|
account_email: Option<String>,
|
||||||
auth_mode: Option<AuthMode>,
|
auth_mode: Option<AuthMode>,
|
||||||
log_user_prompts: bool,
|
log_user_prompts: bool,
|
||||||
terminal_type: String,
|
terminal_type: String,
|
||||||
@@ -60,6 +63,7 @@ impl OtelEventManager {
|
|||||||
conversation_id,
|
conversation_id,
|
||||||
auth_mode: auth_mode.map(|m| m.to_string()),
|
auth_mode: auth_mode.map(|m| m.to_string()),
|
||||||
account_id,
|
account_id,
|
||||||
|
account_email,
|
||||||
model: model.to_owned(),
|
model: model.to_owned(),
|
||||||
slug: slug.to_owned(),
|
slug: slug.to_owned(),
|
||||||
log_user_prompts,
|
log_user_prompts,
|
||||||
@@ -98,6 +102,7 @@ impl OtelEventManager {
|
|||||||
app.version = %self.metadata.app_version,
|
app.version = %self.metadata.app_version,
|
||||||
auth_mode = self.metadata.auth_mode,
|
auth_mode = self.metadata.auth_mode,
|
||||||
user.account_id = self.metadata.account_id,
|
user.account_id = self.metadata.account_id,
|
||||||
|
user.email = self.metadata.account_email,
|
||||||
terminal.type = %self.metadata.terminal_type,
|
terminal.type = %self.metadata.terminal_type,
|
||||||
model = %self.metadata.model,
|
model = %self.metadata.model,
|
||||||
slug = %self.metadata.slug,
|
slug = %self.metadata.slug,
|
||||||
@@ -136,6 +141,7 @@ impl OtelEventManager {
|
|||||||
app.version = %self.metadata.app_version,
|
app.version = %self.metadata.app_version,
|
||||||
auth_mode = self.metadata.auth_mode,
|
auth_mode = self.metadata.auth_mode,
|
||||||
user.account_id = self.metadata.account_id,
|
user.account_id = self.metadata.account_id,
|
||||||
|
user.email = self.metadata.account_email,
|
||||||
terminal.type = %self.metadata.terminal_type,
|
terminal.type = %self.metadata.terminal_type,
|
||||||
model = %self.metadata.model,
|
model = %self.metadata.model,
|
||||||
slug = %self.metadata.slug,
|
slug = %self.metadata.slug,
|
||||||
@@ -205,6 +211,7 @@ impl OtelEventManager {
|
|||||||
app.version = %self.metadata.app_version,
|
app.version = %self.metadata.app_version,
|
||||||
auth_mode = self.metadata.auth_mode,
|
auth_mode = self.metadata.auth_mode,
|
||||||
user.account_id = self.metadata.account_id,
|
user.account_id = self.metadata.account_id,
|
||||||
|
user.email = self.metadata.account_email,
|
||||||
terminal.type = %self.metadata.terminal_type,
|
terminal.type = %self.metadata.terminal_type,
|
||||||
model = %self.metadata.model,
|
model = %self.metadata.model,
|
||||||
slug = %self.metadata.slug,
|
slug = %self.metadata.slug,
|
||||||
@@ -226,6 +233,7 @@ impl OtelEventManager {
|
|||||||
app.version = %self.metadata.app_version,
|
app.version = %self.metadata.app_version,
|
||||||
auth_mode = self.metadata.auth_mode,
|
auth_mode = self.metadata.auth_mode,
|
||||||
user.account_id = self.metadata.account_id,
|
user.account_id = self.metadata.account_id,
|
||||||
|
user.email = self.metadata.account_email,
|
||||||
terminal.type = %self.metadata.terminal_type,
|
terminal.type = %self.metadata.terminal_type,
|
||||||
model = %self.metadata.model,
|
model = %self.metadata.model,
|
||||||
slug = %self.metadata.slug,
|
slug = %self.metadata.slug,
|
||||||
@@ -240,6 +248,7 @@ impl OtelEventManager {
|
|||||||
app.version = %self.metadata.app_version,
|
app.version = %self.metadata.app_version,
|
||||||
auth_mode = self.metadata.auth_mode,
|
auth_mode = self.metadata.auth_mode,
|
||||||
user.account_id = self.metadata.account_id,
|
user.account_id = self.metadata.account_id,
|
||||||
|
user.email = self.metadata.account_email,
|
||||||
terminal.type = %self.metadata.terminal_type,
|
terminal.type = %self.metadata.terminal_type,
|
||||||
model = %self.metadata.model,
|
model = %self.metadata.model,
|
||||||
slug = %self.metadata.slug,
|
slug = %self.metadata.slug,
|
||||||
@@ -262,6 +271,7 @@ impl OtelEventManager {
|
|||||||
app.version = %self.metadata.app_version,
|
app.version = %self.metadata.app_version,
|
||||||
auth_mode = self.metadata.auth_mode,
|
auth_mode = self.metadata.auth_mode,
|
||||||
user.account_id = self.metadata.account_id,
|
user.account_id = self.metadata.account_id,
|
||||||
|
user.email = self.metadata.account_email,
|
||||||
terminal.type = %self.metadata.terminal_type,
|
terminal.type = %self.metadata.terminal_type,
|
||||||
model = %self.metadata.model,
|
model = %self.metadata.model,
|
||||||
slug = %self.metadata.slug,
|
slug = %self.metadata.slug,
|
||||||
@@ -286,6 +296,7 @@ impl OtelEventManager {
|
|||||||
app.version = %self.metadata.app_version,
|
app.version = %self.metadata.app_version,
|
||||||
auth_mode = self.metadata.auth_mode,
|
auth_mode = self.metadata.auth_mode,
|
||||||
user.account_id = self.metadata.account_id,
|
user.account_id = self.metadata.account_id,
|
||||||
|
user.email = self.metadata.account_email,
|
||||||
terminal.type = %self.metadata.terminal_type,
|
terminal.type = %self.metadata.terminal_type,
|
||||||
model = %self.metadata.model,
|
model = %self.metadata.model,
|
||||||
slug = %self.metadata.slug,
|
slug = %self.metadata.slug,
|
||||||
@@ -320,6 +331,7 @@ impl OtelEventManager {
|
|||||||
app.version = %self.metadata.app_version,
|
app.version = %self.metadata.app_version,
|
||||||
auth_mode = self.metadata.auth_mode,
|
auth_mode = self.metadata.auth_mode,
|
||||||
user.account_id = self.metadata.account_id,
|
user.account_id = self.metadata.account_id,
|
||||||
|
user.email = self.metadata.account_email,
|
||||||
terminal.type = %self.metadata.terminal_type,
|
terminal.type = %self.metadata.terminal_type,
|
||||||
model = %self.metadata.model,
|
model = %self.metadata.model,
|
||||||
slug = %self.metadata.slug,
|
slug = %self.metadata.slug,
|
||||||
@@ -343,6 +355,7 @@ impl OtelEventManager {
|
|||||||
app.version = %self.metadata.app_version,
|
app.version = %self.metadata.app_version,
|
||||||
auth_mode = self.metadata.auth_mode,
|
auth_mode = self.metadata.auth_mode,
|
||||||
user.account_id = self.metadata.account_id,
|
user.account_id = self.metadata.account_id,
|
||||||
|
user.email = self.metadata.account_email,
|
||||||
terminal.type = %self.metadata.terminal_type,
|
terminal.type = %self.metadata.terminal_type,
|
||||||
model = %self.metadata.model,
|
model = %self.metadata.model,
|
||||||
slug = %self.metadata.slug,
|
slug = %self.metadata.slug,
|
||||||
@@ -383,7 +396,8 @@ impl OtelEventManager {
|
|||||||
conversation.id = %self.metadata.conversation_id,
|
conversation.id = %self.metadata.conversation_id,
|
||||||
app.version = %self.metadata.app_version,
|
app.version = %self.metadata.app_version,
|
||||||
auth_mode = self.metadata.auth_mode,
|
auth_mode = self.metadata.auth_mode,
|
||||||
user.account_id = self.metadata.account_id,
|
user.account_id= self.metadata.account_id,
|
||||||
|
user.email = self.metadata.account_email,
|
||||||
terminal.type = %self.metadata.terminal_type,
|
terminal.type = %self.metadata.terminal_type,
|
||||||
model = %self.metadata.model,
|
model = %self.metadata.model,
|
||||||
slug = %self.metadata.slug,
|
slug = %self.metadata.slug,
|
||||||
@@ -408,6 +422,7 @@ impl OtelEventManager {
|
|||||||
app.version = %self.metadata.app_version,
|
app.version = %self.metadata.app_version,
|
||||||
auth_mode = self.metadata.auth_mode,
|
auth_mode = self.metadata.auth_mode,
|
||||||
user.account_id = self.metadata.account_id,
|
user.account_id = self.metadata.account_id,
|
||||||
|
user.email = self.metadata.account_email,
|
||||||
terminal.type = %self.metadata.terminal_type,
|
terminal.type = %self.metadata.terminal_type,
|
||||||
model = %self.metadata.model,
|
model = %self.metadata.model,
|
||||||
slug = %self.metadata.slug,
|
slug = %self.metadata.slug,
|
||||||
@@ -437,6 +452,7 @@ impl OtelEventManager {
|
|||||||
app.version = %self.metadata.app_version,
|
app.version = %self.metadata.app_version,
|
||||||
auth_mode = self.metadata.auth_mode,
|
auth_mode = self.metadata.auth_mode,
|
||||||
user.account_id = self.metadata.account_id,
|
user.account_id = self.metadata.account_id,
|
||||||
|
user.email = self.metadata.account_email,
|
||||||
terminal.type = %self.metadata.terminal_type,
|
terminal.type = %self.metadata.terminal_type,
|
||||||
model = %self.metadata.model,
|
model = %self.metadata.model,
|
||||||
slug = %self.metadata.slug,
|
slug = %self.metadata.slug,
|
||||||
|
|||||||
@@ -509,7 +509,7 @@ crate—the events listed below—is forwarded to the exporter.
|
|||||||
|
|
||||||
Every event shares a common set of metadata fields: `event.timestamp`,
|
Every event shares a common set of metadata fields: `event.timestamp`,
|
||||||
`conversation.id`, `app.version`, `auth_mode` (when available),
|
`conversation.id`, `app.version`, `auth_mode` (when available),
|
||||||
`user.account_id` (when available), `terminal.type`, `model`, and `slug`.
|
`user.account_id` (when available), `user.email` (when available), `terminal.type`, `model`, and `slug`.
|
||||||
|
|
||||||
With OTEL enabled Codex emits the following event types (in addition to the
|
With OTEL enabled Codex emits the following event types (in addition to the
|
||||||
metadata above):
|
metadata above):
|
||||||
|
|||||||
Reference in New Issue
Block a user