aKode fase 2c: eliminato il codice di invio dati (crate analytics, otel-trace-websocket, sentry, esportatori OTLP); /feedback salva solo in locale; chiavi legacy [analytics]/[otel] accettate e ignorate; test di analytics/OTLP/upload rimossi
Some checks failed
blocking-ci / rust-ci (push) Has been cancelled
blocking-ci / sdk (push) Has been cancelled
blocking-ci / CI required (push) Has been cancelled
blocking-ci / Bazel (push) Has been cancelled
blocking-ci / Blob size policy (push) Has been cancelled
blocking-ci / cargo-deny (push) Has been cancelled
blocking-ci / Codespell (push) Has been cancelled
blocking-ci / repo-checks (push) Has been cancelled
postmerge-ci / rust-ci-full (push) Has been cancelled
postmerge-ci / v8-canary (push) Has been cancelled
postmerge-ci / Postmerge CI results (push) Has been cancelled

This commit is contained in:
Andrea
2026-11-09 18:45:41 +01:00
parent 981745ccc8
commit 60532b6337
509 changed files with 2043 additions and 46606 deletions

View File

@@ -57,8 +57,6 @@ use codex_config::types::Notice;
use codex_config::types::NotificationCondition;
use codex_config::types::NotificationMethod;
use codex_config::types::Notifications;
use codex_config::types::OtelConfigToml;
use codex_config::types::OtelExporterKind;
use codex_config::types::ResumeCwdMode;
use codex_config::types::SandboxWorkspaceWrite;
use codex_config::types::SessionPickerViewMode;
@@ -10413,9 +10411,6 @@ fn create_test_fixture() -> std::io::Result<PrecedenceTestFixture> {
model = "o3"
approval_policy = "on-request"
[analytics]
enabled = true
[model_providers.openai-custom]
name = "OpenAI custom"
base_url = "https://api.openai.com/v1"
@@ -10442,9 +10437,6 @@ model = "o3"
model_provider = "openai"
approval_policy = "on-request"
[profiles.zdr.analytics]
enabled = false
[profiles.gpt5]
model = "gpt-5.4"
model_provider = "openai"
@@ -10499,7 +10491,7 @@ async fn legacy_profile_selection_is_rejected() -> std::io::Result<()> {
}
#[tokio::test]
async fn metrics_exporter_defaults_to_statsig_when_missing() -> std::io::Result<()> {
async fn otel_defaults_keep_local_logging_only() -> std::io::Result<()> {
let fixture = create_test_fixture()?;
let config = Config::load_from_base_config_with_overrides(
@@ -10512,34 +10504,37 @@ async fn metrics_exporter_defaults_to_statsig_when_missing() -> std::io::Result<
)
.await?;
assert_eq!(config.otel.metrics_exporter, OtelExporterKind::None);
assert!(config.otel.log_sse_deltas);
assert!(!config.otel.agent_response_logging_enabled());
assert!(!config.otel.guardian_assessment_logging_enabled());
assert!(!config.otel.log_user_prompt);
Ok(())
}
#[tokio::test]
async fn trace_exporter_defaults_to_none_when_log_exporter_is_set() -> std::io::Result<()> {
let fixture = create_test_fixture()?;
let mut cfg = fixture.cfg.clone();
cfg.otel = Some(OtelConfigToml {
tool_result: Some(toml::from_str("max_bytes = 8192").expect("tool-result logging config")),
log_sse_deltas: Some(false),
log_agent_responses: Some(true),
log_guardian_assessments: Some(true),
exporter: Some(OtelExporterKind::OtlpHttp {
endpoint: "http://localhost:14318/v1/logs".to_string(),
headers: HashMap::new(),
protocol: codex_config::types::OtelHttpProtocol::Binary,
tls: None,
}),
metrics_exporter: Some(OtelExporterKind::None),
..Default::default()
});
async fn legacy_otel_exporter_keys_are_accepted_and_ignored() -> std::io::Result<()> {
let mut fixture = create_test_fixture()?;
fixture.cfg = toml::from_str(
r#"
[analytics]
enabled = true
let mut config = Config::load_from_base_config_with_overrides(
cfg,
[otel]
tool_result = { max_bytes = 8192 }
log_sse_deltas = false
log_agent_responses = true
log_guardian_assessments = true
environment = "prod"
exporter = { otlp-http = { endpoint = "http://localhost:14318/v1/logs", protocol = "binary" } }
trace_exporter = "statsig"
metrics_exporter = "statsig"
[otel.span_attributes]
"example.trace_attr" = "enabled"
"#,
)
.expect("legacy telemetry config should still deserialize");
let config = Config::load_from_base_config_with_overrides(
fixture.cfg.clone(),
ConfigOverrides {
cwd: Some(fixture.cwd_path()),
..Default::default()
@@ -10550,128 +10545,7 @@ async fn trace_exporter_defaults_to_none_when_log_exporter_is_set() -> std::io::
assert_eq!(config.otel.tool_result.max_bytes, 8192);
assert!(!config.otel.log_sse_deltas);
assert!(config.otel.agent_response_logging_enabled());
assert!(config.otel.guardian_assessment_logging_enabled());
assert!(matches!(
config.otel.exporter,
OtelExporterKind::OtlpHttp { .. }
));
assert_eq!(config.otel.trace_exporter, OtelExporterKind::None);
config.otel.exporter = OtelExporterKind::None;
assert!(!config.otel.guardian_assessment_logging_enabled());
Ok(())
}
#[tokio::test]
async fn load_config_applies_otel_trace_metadata() -> std::io::Result<()> {
let mut fixture = create_test_fixture()?;
fixture.cfg = toml::from_str(
r#"
[otel.span_attributes]
"example.trace_attr" = "enabled"
[otel.tracestate.example]
alpha = "one"
beta = "two"
"#,
)
.expect("TOML deserialization should succeed");
let config = Config::load_from_base_config_with_overrides(
fixture.cfg.clone(),
ConfigOverrides {
cwd: Some(fixture.cwd_path()),
..Default::default()
},
fixture.codex_home(),
)
.await?;
assert_eq!(
config.otel.span_attributes,
HashMap::from([("example.trace_attr".to_string(), "enabled".to_string())])
);
assert_eq!(
config.otel.tracestate,
BTreeMap::from([(
"example".to_string(),
BTreeMap::from([
("alpha".to_string(), "one".to_string()),
("beta".to_string(), "two".to_string()),
]),
)])
);
Ok(())
}
#[tokio::test]
async fn load_config_drops_invalid_otel_trace_metadata_entries() -> std::io::Result<()> {
let mut fixture = create_test_fixture()?;
fixture.cfg = toml::from_str(
r#"
[otel]
environment = "test"
[otel.span_attributes]
"" = "missing-key"
"example.trace_attr" = "enabled"
[otel.tracestate.example]
alpha = "one"
beta = "two\ntoo"
[otel.tracestate.bad]
alpha = "one\ntwo"
"#,
)
.expect("TOML deserialization should succeed");
let config = Config::load_from_base_config_with_overrides(
fixture.cfg.clone(),
ConfigOverrides {
cwd: Some(fixture.cwd_path()),
..Default::default()
},
fixture.codex_home(),
)
.await?;
assert_eq!(config.otel.environment, "test");
assert_eq!(
config.otel.span_attributes,
HashMap::from([("example.trace_attr".to_string(), "enabled".to_string())])
);
assert_eq!(
config.otel.tracestate,
BTreeMap::from([(
"example".to_string(),
BTreeMap::from([("alpha".to_string(), "one".to_string())]),
)])
);
assert!(
config.startup_warnings.iter().any(|warning| {
warning.contains("Ignoring invalid `otel.span_attributes` config")
&& warning.contains("configured span attribute key must not be empty")
}),
"{:?}",
config.startup_warnings
);
assert!(
config.startup_warnings.iter().any(|warning| {
warning.contains("Ignoring invalid `otel.tracestate` config")
&& warning.contains("invalid configured tracestate value for example.beta")
}),
"{:?}",
config.startup_warnings
);
assert!(
config.startup_warnings.iter().any(|warning| {
warning.contains("Ignoring invalid `otel.tracestate` config")
&& warning.contains("invalid configured tracestate value for bad.alpha")
}),
"{:?}",
config.startup_warnings
);
assert!(!config.otel.log_user_prompt);
Ok(())
}
@@ -14184,7 +14058,7 @@ tracestate = { vendor = { tenant = "managed", region = "us" }, other = { keep =
#[test_case::test_case(
"[otel]\nlog_agent_responses = false\nlog_guardian_assessments = true",
"[otel]\nlog_agent_responses = true\nlog_guardian_assessments = false",
"[otel]\nlog_agent_responses = true\nlog_guardian_assessments = false", true; "managed_logging_flags"
"[otel]\nlog_agent_responses = true\nlog_guardian_assessments = false", false; "ignored_legacy_logging_flags"
)]
#[test_case::test_case(
"[otel]\nlog_sse_deltas = true", "[otel]\nlog_sse_deltas = false",
@@ -14202,10 +14076,9 @@ async fn otel_requirements_resolve_config(
let config = load_with_enterprise_requirement(&codex_home, requirements).await?;
let expected: ConfigToml =
toml::from_str(expected_config).expect("expected OTEL config should deserialize");
let mut warnings = Vec::new();
assert_eq!(
config.otel,
super::otel::resolve_config(expected.otel.unwrap_or_default(), &mut warnings)
super::otel::resolve_config(expected.otel.unwrap_or_default())
);
assert_eq!(
config
@@ -14227,7 +14100,7 @@ async fn otel_requirements_resolve_config(
}
#[tokio::test]
async fn analytics_disabled_preserves_managed_metrics_exporter() -> std::io::Result<()> {
async fn legacy_managed_metrics_exporter_requirement_is_ignored() -> std::io::Result<()> {
let codex_home = TempDir::new()?;
std::fs::write(
codex_home.path().join(CONFIG_TOML_FILE),
@@ -14246,21 +14119,7 @@ metrics_exporter = { otlp-http = { endpoint = "http://127.0.0.1:1/v1/metrics", p
)
.await?;
assert!(matches!(
config.otel.metrics_exporter,
OtelExporterKind::OtlpHttp { .. }
));
assert!(
crate::otel_init::build_provider(
&config,
env!("CARGO_PKG_VERSION"),
/*service_name_override*/ None,
/*default_analytics_enabled*/ true,
)
.expect("managed metrics configuration should remain valid")
.is_some(),
"analytics.enabled=false should preserve the custom managed metrics exporter"
);
assert_eq!(config.otel, codex_config::types::OtelConfig::default());
Ok(())
}