mirror of
https://github.com/openai/codex.git
synced 2026-04-30 17:36:40 +00:00
Include real OS info in metrics. (#10425)
calculated a hashed user ID from either auth user id or API key Also correctly populates OS. These will make our metrics more useful and powerful for analysis.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use codex_utils_string::sanitize_metric_tag_value;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::fs;
|
||||
@@ -126,7 +127,7 @@ impl SetupFailure {
|
||||
}
|
||||
|
||||
pub fn metric_message(&self) -> String {
|
||||
sanitize_tag_value(&self.message)
|
||||
sanitize_setup_metric_tag_value(&self.message)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,30 +182,9 @@ pub fn read_setup_error_report(codex_home: &Path) -> Result<Option<SetupErrorRep
|
||||
Ok(Some(report))
|
||||
}
|
||||
|
||||
/// Sanitize a tag value to comply with metric tag validation rules:
|
||||
/// only ASCII alphanumeric, '.', '_', '-', and '/' are allowed.
|
||||
pub fn sanitize_tag_value(value: &str) -> String {
|
||||
const MAX_LEN: usize = 256;
|
||||
let redacted = redact_home_paths(value);
|
||||
let sanitized: String = redacted
|
||||
.chars()
|
||||
.map(|ch| {
|
||||
if ch.is_ascii_alphanumeric() || matches!(ch, '.' | '_' | '-' | '/') {
|
||||
ch
|
||||
} else {
|
||||
'_'
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let trimmed = sanitized.trim_matches('_');
|
||||
if trimmed.is_empty() {
|
||||
return "unspecified".to_string();
|
||||
}
|
||||
if trimmed.len() <= MAX_LEN {
|
||||
trimmed.to_string()
|
||||
} else {
|
||||
trimmed[..MAX_LEN].to_string()
|
||||
}
|
||||
/// Sanitize a setup error message for use as a metric tag.
|
||||
pub fn sanitize_setup_metric_tag_value(value: &str) -> String {
|
||||
sanitize_metric_tag_value(redact_home_paths(value).as_str())
|
||||
}
|
||||
|
||||
fn redact_home_paths(value: &str) -> String {
|
||||
@@ -267,7 +247,7 @@ fn redact_username_segments(value: &str, usernames: &[String]) -> String {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use super::redact_username_segments;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user