A high-performance inference engine for AI models
update telemetry body
eugene904453fbff1c
diff --git a/Cargo.lock b/Cargo.lockindex 188a804ec..7b58e0fe2 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -3808,6 +3808,7 @@ dependencies = ["tracing","tsify","uniffi",+ "uuid","wasm-bindgen","wasm-bindgen-futures",]diff --git a/crates/nagare/Cargo.toml b/crates/nagare/Cargo.tomlindex 3d4b871d5..72291db47 100644--- a/crates/nagare/Cargo.toml+++ b/crates/nagare/Cargo.toml@@ -77,6 +77,9 @@ serde-wasm-bindgen = { workspace = true, optional = true }wasm-bindgen-futures = { workspace = true, optional = true }tsify = { workspace = true, optional = true }+[target.'cfg(not(target_family = "wasm"))'.dependencies]+uuid.workspace = true+[build-dependencies]napi-build = { workspace = true, optional = true }pyo3-build-config = { workspace = true, optional = true }diff --git a/crates/nagare/src/telemetry/context.rs b/crates/nagare/src/telemetry/context.rsnew file mode 100644index 000000000..3eb6f036f--- /dev/null+++ b/crates/nagare/src/telemetry/context.rs@@ -0,0 +1,34 @@+use serde::Serialize;++#[derive(Debug, Clone, Serialize)]+pub struct TelemetryDevice {+ pub os_name: Option<String>,+ pub cpu_name: Option<String>,+ pub memory_total: i64,+ pub is_environment_sandboxed: bool,+}++#[derive(Debug, Clone, Serialize)]+pub struct TelemetryContext {+ pub engine_session_id: String,+ pub uzu_version: String,+ pub toolchain_version: String,+ pub device: TelemetryDevice,+}++// The constructor lives only in non-wasm code so `uuid` is never referenced on wasm.+#[cfg(not(target_family = "wasm"))]+impl TelemetryContext {+ pub fn new(+ uzu_version: String,+ toolchain_version: String,+ device: TelemetryDevice,+ ) -> Self {+ Self {+ engine_session_id: uuid::Uuid::new_v4().to_string(),+ uzu_version,+ toolchain_version,+ device,+ }+ }+}diff --git a/crates/nagare/src/telemetry/endpoint.rs b/crates/nagare/src/telemetry/endpoint.rsindex b8210b971..caa831102 100644--- a/crates/nagare/src/telemetry/endpoint.rs+++ b/crates/nagare/src/telemetry/endpoint.rs@@ -2,7 +2,7 @@ use indexmap::IndexMap;use reqwest::{Method, header::CONTENT_TYPE};use serde_json::Value;-use super::record::TelemetryRecord;+use super::{TelemetryContext, record::TelemetryRecord};use crate::api::{Config, Endpoint, Payload};pub(super) struct TelemetryEndpoint {@@ -13,7 +13,7 @@ pub(super) struct TelemetryEndpoint {impl TelemetryEndpoint {pub(super) fn new(path: String,- context: &Value,+ context: &TelemetryContext,record: &TelemetryRecord,) -> Self {Self {@@ -48,13 +48,17 @@ impl Endpoint for TelemetryEndpoint {}fn build_body(- context: &Value,+ context: &TelemetryContext,record: &TelemetryRecord,) -> Value {let mut body = serde_json::to_value(&record.event).unwrap_or_else(|_| Value::Object(Default::default()));if let Value::Object(map) = &mut body {+ if let Ok(Value::Object(context)) = serde_json::to_value(context) {+ for (key, value) in context {+ map.insert(key, value);+ }+ }map.insert("event_time".to_string(), Value::String(record.event_time.clone()));- map.insert("device".to_string(), context.clone());}body}@@ -63,12 +67,28 @@ fn build_body(mod tests {use serde_json::json;- use super::{super::record::TelemetryRecord, build_body};+ use super::{+ super::{TelemetryContext, TelemetryDevice, record::TelemetryRecord},+ build_body,+ };use crate::telemetry::TelemetryEvent;+ fn context() -> TelemetryContext {+ TelemetryContext {+ engine_session_id: "session-1".to_string(),+ uzu_version: "0.5.7".to_string(),+ toolchain_version: "0.12.1".to_string(),+ device: TelemetryDevice {+ os_name: Some("macOS".to_string()),+ cpu_name: None,+ memory_total: 0,+ is_environment_sandboxed: false,+ },+ }+ }+#[test]fn build_body_nests_event_time_device_and_payload() {- let device = json!({ "os_name": "macOS" });let record = TelemetryRecord {event_time: "2026-06-04T16:24:29Z".to_string(),event: TelemetryEvent::ModelInferenceFinished {@@ -76,9 +96,12 @@ mod tests {stats: Default::default(),},};- let body = build_body(&device, &record);+ let body = build_body(&context(), &record);assert_eq!(body["event_name"], json!("model_inference_finished"));assert_eq!(body["event_time"], json!("2026-06-04T16:24:29Z"));+ assert_eq!(body["engine_session_id"], json!("session-1"));+ assert_eq!(body["uzu_version"], json!("0.5.7"));+ assert_eq!(body["toolchain_version"], json!("0.12.1"));assert_eq!(body["device"]["os_name"], json!("macOS"));assert_eq!(body["payload"]["model_id"], json!("model-1"));assert!(body["payload"]["stats"].is_object());@@ -92,7 +115,7 @@ mod tests {error: json!({ "message": "boom" }),},};- let body = build_body(&json!({}), &record);+ let body = build_body(&context(), &record);assert_eq!(body["event_name"], json!("model_inference_failed"));assert_eq!(body["payload"]["error"]["message"], json!("boom"));}diff --git a/crates/nagare/src/telemetry/mod.rs b/crates/nagare/src/telemetry/mod.rsindex 16a46f2c9..18b557577 100644--- a/crates/nagare/src/telemetry/mod.rs+++ b/crates/nagare/src/telemetry/mod.rs@@ -1,3 +1,4 @@+mod context;#[cfg(not(target_family = "wasm"))]mod endpoint;mod event;@@ -6,5 +7,6 @@ mod telemetry;#[cfg(not(target_family = "wasm"))]mod worker;+pub use context::{TelemetryContext, TelemetryDevice};pub use event::TelemetryEvent;pub use telemetry::Telemetry;diff --git a/crates/nagare/src/telemetry/telemetry.rs b/crates/nagare/src/telemetry/telemetry.rsindex 5cdca68b5..0ca37237c 100644--- a/crates/nagare/src/telemetry/telemetry.rs+++ b/crates/nagare/src/telemetry/telemetry.rs@@ -1,9 +1,8 @@-use serde_json::Value;use tokio::sync::mpsc;#[cfg(not(target_family = "wasm"))]use tokio::sync::mpsc::channel as TokioMpscChannel;-use super::{TelemetryEvent, record::TelemetryRecord};+use super::{TelemetryContext, TelemetryEvent, record::TelemetryRecord};#[cfg(not(target_family = "wasm"))]use crate::api::Client;use crate::api::Config;@@ -27,7 +26,7 @@ impl Telemetry {pub fn new(client_config: Config,path: String,- context: Value,+ context: TelemetryContext,) -> Self {let client = match Client::new(client_config) {Ok(client) => client,@@ -47,7 +46,7 @@ impl Telemetry {pub fn new(_client_config: Config,_path: String,- _context: Value,+ _context: TelemetryContext,) -> Self {Self::disabled()}diff --git a/crates/nagare/src/telemetry/worker.rs b/crates/nagare/src/telemetry/worker.rsindex eb0405dd3..7cdc662eb 100644--- a/crates/nagare/src/telemetry/worker.rs+++ b/crates/nagare/src/telemetry/worker.rs@@ -1,7 +1,6 @@-use serde_json::Value;use tokio::sync::mpsc;-use super::{endpoint::TelemetryEndpoint, record::TelemetryRecord};+use super::{TelemetryContext, endpoint::TelemetryEndpoint, record::TelemetryRecord};use crate::api::{Client, Error};const MAX_RETRIES: u32 = 4;@@ -11,7 +10,7 @@ const MAX_BACKOFF_MS: u64 = 16_000;pub(super) async fn run(client: Client,path: String,- context: Value,+ context: TelemetryContext,mut receiver: mpsc::Receiver<TelemetryRecord>,) {while let Some(record) = receiver.recv().await {@@ -28,7 +27,7 @@ enum Disposition {async fn send_with_retry(client: &Client,path: &str,- context: &Value,+ context: &TelemetryContext,record: &TelemetryRecord,) {let endpoint = TelemetryEndpoint::new(path.to_string(), context, record);diff --git a/crates/uzu/src/engine/mod.rs b/crates/uzu/src/engine/mod.rsindex d2a7520ac..d14ac4f71 100644--- a/crates/uzu/src/engine/mod.rs+++ b/crates/uzu/src/engine/mod.rs@@ -18,7 +18,7 @@ use nagare::{api::Config as ClientConfig,chat::ChatSession,classification::ClassificationSession,- telemetry::{Telemetry, TelemetryEvent},+ telemetry::{Telemetry, TelemetryContext, TelemetryDevice, TelemetryEvent},text_to_speech::TextToSpeechSession,};use shoji::{@@ -79,16 +79,20 @@ impl Engine {let telemetry = SharedAccess::new({let client_config = ClientConfig::new(- "https://sdk.trymirai.com/api/v1".to_string(),+ "https://sdk.trymirai.com/api/v2".to_string(),Duration::from_secs(10),IndexMap::new(),);- let context = serde_json::json!({- "os_name": device.os_name,- "cpu_name": device.cpu_name,- "memory_total": device.memory_total,- "is_environment_sandboxed": crate::device::is_environment_sandboxed(),- });+ let context = TelemetryContext::new(+ env!("CARGO_PKG_VERSION").to_string(),+ backend_uzu::TOOLCHAIN_VERSION.to_string(),+ TelemetryDevice {+ os_name: device.os_name.clone(),+ cpu_name: device.cpu_name.clone(),+ memory_total: device.memory_total,+ is_environment_sandboxed: crate::device::is_environment_sandboxed(),+ },+ );Telemetry::new(client_config, "telemetry/events".to_string(), context)});