pub async fn send_telemetry_metrics(
token: &str,
project: &str,
trajectory_id: &str,
trace_id: Option<&str>,
first_latency: std::time::Duration,
total_latency: std::time::Duration,
) -> anyhow::Result<()> {
let client = reqwest::Client::new();
let url = "https://daily-cloudcode-pa.googleapis.com/v1internal:recordCodeAssistMetrics";
let now_str = chrono::Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Nanos, true);
let payload = serde_json::json!({
"project": project,
"requestId": uuid::Uuid::new_v4().to_string(),
"metadata": {
"ideType": "ANTIGRAVITY",
"ideVersion": "1.0.10",
"platform": "LINUX_AMD64"
},
"metrics": [
{
"timestamp": now_str,
"conversationOffered": {
"status": "ACTION_STATUS_NO_ERROR",
"traceId": trace_id.unwrap_or(""),
"streamingLatency": {
"firstMessageLatency": format!("{:.9}s", first_latency.as_secs_f64()),
"totalLatency": format!("{:.9}s", total_latency.as_secs_f64())
},
"isAgentic": true,
"initiationMethod": "AGENT",
"trajectoryId": trajectory_id,
"language": "unspecified"
}
}
]
});
tracing::info!(
"Sending recordCodeAssistMetrics telemetry (trajectory_id: {})...",
trajectory_id
);
let response = client
.post(url)
.header("Authorization", format!("Bearer {}", token))
.header("Content-Type", "application/json")
.header("User-Agent", "antigravity/cli/1.0.10 linux/amd64")
.json(&payload)
.send()
.await?;
let status = response.status();
if !status.is_success() {
let err_text = response.text().await.unwrap_or_default();
anyhow::bail!(
"recordCodeAssistMetrics returned status {}: {}",
status,
err_text
);
}
tracing::info!("Successfully recorded telemetry metrics.");
Ok(())
}