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

@@ -358,7 +358,6 @@ fn run_setup_refresh_inner(
deny_write_paths,
proxy_ports: offline_proxy_settings.proxy_ports,
allow_local_binding: offline_proxy_settings.allow_local_binding,
otel: None,
real_user: crate::runtime_ownership::current_setup_user()?,
user_profile: std::env::var_os("USERPROFILE")
.filter(|value| !value.is_empty())
@@ -720,7 +719,6 @@ struct ElevationPayload {
proxy_ports: Vec<u16>,
#[serde(default)]
allow_local_binding: bool,
otel: Option<codex_otel::StatsigMetricsSettings>,
real_user: String,
#[serde(skip_serializing_if = "Option::is_none")]
user_profile: Option<PathBuf>,
@@ -1171,7 +1169,6 @@ fn elevated_provisioning_payload(
proxy_ports: offline_proxy_settings.proxy_ports,
allow_local_binding: offline_proxy_settings.allow_local_binding,
real_user,
otel: codex_otel::global_statsig_metrics_settings(),
user_profile: None,
mode: SetupMode::InteractiveProvision,
runtime: SetupRuntime::Legacy,
@@ -1251,7 +1248,6 @@ pub fn run_elevated_provisioning_setup_with_retained_handles(
deny_write_paths: Vec::new(),
proxy_ports: settings.proxy_ports,
allow_local_binding: settings.allow_local_binding,
otel: codex_otel::global_statsig_metrics_settings(),
real_user: real_user.to_string(),
user_profile: std::env::var_os("USERPROFILE")
.filter(|value| !value.is_empty())

View File

@@ -47,7 +47,6 @@ use anyhow::Context;
use anyhow::Result;
use base64::Engine;
use base64::engine::general_purpose::STANDARD as BASE64;
use codex_otel::StatsigMetricsSettings;
use serde::Deserialize;
use serde::Serialize;
use std::collections::HashSet;
@@ -123,8 +122,6 @@ struct Payload {
proxy_ports: Vec<u16>,
#[serde(default)]
allow_local_binding: bool,
#[serde(default)]
otel: Option<StatsigMetricsSettings>,
real_user: String,
#[serde(default)]
user_profile: Option<PathBuf>,
@@ -761,14 +758,9 @@ fn provision_sandbox(payload: &Payload, log: &mut dyn Write, sbx_dir: &Path) ->
})?;
let offline_sid_str = string_from_sid_bytes(&offline_sid).map_err(anyhow::Error::msg)?;
configure_offline_sandbox_network(payload, &offline_sid_str, log)?;
let wfp_result = install_wfp_filters(
&payload.codex_home,
&payload.offline_username,
payload.otel.as_ref(),
|message| {
let _ = log_line(log, message);
},
);
let wfp_result = install_wfp_filters(&payload.offline_username, |message| {
let _ = log_line(log, message);
});
if repairing_disabled_accounts {
// Ordinary setup keeps its best-effort WFP behavior. Recovery must not reopen logons
// after cleanup removed protections unless restoring those protections succeeded.
@@ -1236,7 +1228,6 @@ mod tests {
use crate::path_mask_allows;
use crate::path_write_aces_need_refresh;
use crate::workspace_write_cap_sid_for_root;
use codex_otel::StatsigMetricsSettings;
use pretty_assertions::assert_eq;
use serde_json::json;
use std::fs;
@@ -1258,13 +1249,6 @@ mod tests {
})
}
#[test]
fn payload_defaults_otel_absent() {
let payload: Payload = serde_json::from_value(payload_json()).expect("payload");
assert_eq!(payload.otel, None);
}
#[test]
fn payload_accepts_provision_only_mode() {
let mut payload = payload_json();
@@ -1284,19 +1268,14 @@ mod tests {
}
#[test]
fn payload_accepts_otel_settings() {
fn payload_ignores_legacy_telemetry_settings() {
let mut payload = payload_json();
payload["otel"] = json!({
"environment": "prod",
});
let payload: Payload = serde_json::from_value(payload).expect("payload");
assert_eq!(
payload.otel,
Some(StatsigMetricsSettings {
environment: "prod".to_string(),
})
);
assert_eq!(payload.offline_username, "CodexSandboxOffline");
}
#[test]

View File

@@ -32,7 +32,6 @@ pub fn provision_sandbox_in_process(
deny_write_paths: Vec::new(),
proxy_ports: settings.proxy_ports,
allow_local_binding: settings.allow_local_binding,
otel: codex_otel::global_statsig_metrics_settings(),
real_user: real_user.to_string(),
user_profile: None,
mode: SetupMode::ProvisionOnly,

View File

@@ -1,30 +1,5 @@
use crate::install_wfp_filters_for_account;
use crate::setup_error::sanitize_setup_metric_tag_value;
use anyhow::Result;
use codex_otel::OtelExporter;
use codex_otel::OtelProvider;
use codex_otel::OtelSettings;
use codex_otel::StatsigMetricsSettings;
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::path::Path;
const WFP_SETUP_SERVICE_NAME: &str = "codex-windows-sandbox-setup";
const WFP_SETUP_SUCCESS_METRIC: &str = "codex.windows_sandbox.wfp_setup_success";
const WFP_SETUP_FAILURE_METRIC: &str = "codex.windows_sandbox.wfp_setup_failure";
#[derive(Debug, Clone, Copy)]
enum WfpSetupMetricOutcome {
Success,
Failure,
}
struct WfpSetupMetric {
outcome: WfpSetupMetricOutcome,
target_account: String,
installed_filter_count: usize,
error: Option<String>,
}
fn panic_payload_to_string(panic_payload: Box<dyn std::any::Any + Send>) -> String {
match panic_payload.downcast::<String>() {
@@ -36,146 +11,35 @@ fn panic_payload_to_string(panic_payload: Box<dyn std::any::Any + Send>) -> Stri
}
}
fn build_wfp_metrics_provider(
codex_home: &Path,
otel: Option<&StatsigMetricsSettings>,
) -> Result<Option<OtelProvider>> {
let Some(otel) = otel else {
return Ok(None);
};
// The setup helper cannot call codex-core's OTEL builder because core
// depends on this crate, so the parent process passes only the resolved
// Statsig environment in the elevation payload. Other exporters are
// intentionally omitted from this helper path.
OtelProvider::try_new(&OtelSettings {
http_client_factory: codex_http_client::HttpClientFactory::new(
codex_http_client::OutboundProxyPolicy::ReqwestDefault,
),
environment: otel.environment.clone(),
service_name: WFP_SETUP_SERVICE_NAME.to_string(),
service_version: env!("CARGO_PKG_VERSION").to_string(),
codex_home: codex_home.to_path_buf(),
exporter: OtelExporter::None,
trace_exporter: OtelExporter::None,
metrics_exporter: OtelExporter::Statsig,
runtime_metrics: false,
span_attributes: HashMap::new(),
tracestate: BTreeMap::new(),
})
.map_err(|err| anyhow::anyhow!("failed to initialize WFP setup metrics provider: {err}"))
}
fn emit_wfp_setup_metric(
codex_home: &Path,
otel: Option<&StatsigMetricsSettings>,
metric: &WfpSetupMetric,
) -> Result<()> {
let Some(provider) = build_wfp_metrics_provider(codex_home, otel)? else {
return Ok(());
};
if let Some(metrics) = provider.metrics() {
let target_account = sanitize_setup_metric_tag_value(&metric.target_account);
match metric.outcome {
WfpSetupMetricOutcome::Success => {
let installed_filter_count = metric.installed_filter_count.to_string();
metrics.counter(
WFP_SETUP_SUCCESS_METRIC,
/*inc*/ 1,
&[
("target_account", target_account.as_str()),
("installed_filter_count", installed_filter_count.as_str()),
],
)?;
}
WfpSetupMetricOutcome::Failure => {
let mut tags = vec![("target_account", target_account.as_str())];
let error_tag = metric.error.as_deref().map(sanitize_setup_metric_tag_value);
if let Some(error) = error_tag.as_deref() {
tags.push(("message", error));
}
metrics.counter(WFP_SETUP_FAILURE_METRIC, /*inc*/ 1, &tags)?;
}
}
}
provider.shutdown();
Ok(())
}
fn emit_wfp_setup_metric_safely<F>(
codex_home: &Path,
otel: Option<&StatsigMetricsSettings>,
offline_username: &str,
metric: &WfpSetupMetric,
log: &mut F,
) where
F: FnMut(&str),
{
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
emit_wfp_setup_metric(codex_home, otel, metric)
}));
match result {
Ok(Ok(())) => {}
Ok(Err(err)) => log(&format!(
"failed to emit WFP setup metric for {offline_username}: {err}"
)),
Err(panic_payload) => {
let error = panic_payload_to_string(panic_payload);
log(&format!(
"WFP setup metric emission panicked for {offline_username}: {error}"
));
}
}
}
pub fn install_wfp_filters<F>(
codex_home: &Path,
offline_username: &str,
otel: Option<&StatsigMetricsSettings>,
mut log: F,
) -> Result<()>
/// Installs WFP filters for the offline sandbox account. Outcomes are logged locally only.
pub fn install_wfp_filters<F>(offline_username: &str, mut log: F) -> Result<()>
where
F: FnMut(&str),
{
let metric = match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
let outcome = match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
install_wfp_filters_for_account(offline_username)
})) {
Ok(Ok(installed_filter_count)) => {
log(&format!(
"WFP setup succeeded for {offline_username} with {installed_filter_count} installed filters"
));
WfpSetupMetric {
outcome: WfpSetupMetricOutcome::Success,
target_account: offline_username.to_string(),
installed_filter_count,
error: None,
}
None
}
Ok(Err(err)) => {
let error = err.to_string();
log(&format!("WFP setup failed for {offline_username}: {error}"));
WfpSetupMetric {
outcome: WfpSetupMetricOutcome::Failure,
target_account: offline_username.to_string(),
installed_filter_count: 0,
error: Some(error),
}
Some(error)
}
Err(panic_payload) => {
let error = panic_payload_to_string(panic_payload);
log(&format!(
"WFP setup panicked for {offline_username}: {error}"
));
WfpSetupMetric {
outcome: WfpSetupMetricOutcome::Failure,
target_account: offline_username.to_string(),
installed_filter_count: 0,
error: Some(format!("panic: {error}")),
}
Some(format!("panic: {error}"))
}
};
emit_wfp_setup_metric_safely(codex_home, otel, offline_username, &metric, &mut log);
match metric.error {
match outcome {
Some(error) => Err(anyhow::anyhow!(error)),
None => Ok(()),
}