mirror of
https://github.com/openai/codex.git
synced 2026-12-03 00:41:03 +00:00
## Why Remote plugin install telemetry needs enough detail to distinguish archive verification failures from other bundle errors and associate those failures with a specific release when its ID is available. ## What changed - Include the archive verification outcome in successful app-server install events. Classify verification failures by reason and attach the `plugin_release_id` when available. Use the catalog plugin ID for bundle events when it is available. - Export `codex.plugins.archive_verification` through the configured OpenTelemetry logger during standalone CLI installs. ## Testing App-server tests check successful and failed install analytics. A CLI integration test checks that an archive verification failure exports the expected event fields and leaves the plugin uninstalled. GitOrigin-RevId: ea6cab1d04467d63f43fbd17e3d0a122fad15435
60 lines
2.1 KiB
Rust
60 lines
2.1 KiB
Rust
use anyhow::Result;
|
|
use std::time::Duration;
|
|
use tokio::time::timeout;
|
|
use wiremock::Mock;
|
|
use wiremock::MockServer;
|
|
use wiremock::ResponseTemplate;
|
|
use wiremock::matchers::method;
|
|
use wiremock::matchers::path;
|
|
|
|
pub async fn start_analytics_events_server() -> Result<MockServer> {
|
|
let server = MockServer::start().await;
|
|
Mock::given(method("POST"))
|
|
.and(path("/codex/analytics-events/events"))
|
|
.respond_with(ResponseTemplate::new(200))
|
|
.mount(&server)
|
|
.await;
|
|
Ok(server)
|
|
}
|
|
|
|
pub async fn mount_backend_analytics_events(server: &MockServer) {
|
|
Mock::given(method("POST"))
|
|
.and(path("/backend-api/codex/analytics-events/events"))
|
|
.respond_with(ResponseTemplate::new(200).set_body_string(r#"{"status":"ok"}"#))
|
|
.mount(server)
|
|
.await;
|
|
}
|
|
|
|
pub async fn wait_for_plugin_analytics_payload(
|
|
server: &MockServer,
|
|
event_type: &str,
|
|
) -> Result<serde_json::Value> {
|
|
timeout(Duration::from_secs(60), async {
|
|
loop {
|
|
let Some(requests) = server.received_requests().await else {
|
|
tokio::time::sleep(Duration::from_millis(25)).await;
|
|
continue;
|
|
};
|
|
for request in requests.iter().filter(|request| {
|
|
request.method == "POST"
|
|
&& request
|
|
.url
|
|
.path()
|
|
.ends_with("/codex/analytics-events/events")
|
|
}) {
|
|
let mut payload: serde_json::Value = serde_json::from_slice(&request.body)
|
|
.map_err(|err| anyhow::anyhow!("invalid analytics payload: {err}"))?;
|
|
let events = payload["events"]
|
|
.as_array_mut()
|
|
.ok_or_else(|| anyhow::anyhow!("analytics payload missing events array"))?;
|
|
events.retain(|event| event["event_type"] == event_type);
|
|
if !events.is_empty() {
|
|
return Ok(payload);
|
|
}
|
|
}
|
|
tokio::time::sleep(Duration::from_millis(25)).await;
|
|
}
|
|
})
|
|
.await?
|
|
}
|