gemini_genai_rs/telemetry/
logging.rs1pub fn log_session_event(session_id: &str, phase: &str, event: &str) {
9 tracing::info!(
10 session_id = session_id,
11 phase = phase,
12 event = event,
13 "Session event"
14 );
15}
16
17pub fn log_tool_call(session_id: &str, function_name: &str, call_count: usize) {
19 tracing::info!(
20 session_id = session_id,
21 event = "tool_call_received",
22 function_name = function_name,
23 function_count = call_count,
24 "Model requested function calls"
25 );
26}
27
28pub fn log_ws_error(session_id: &str, error: &str) {
30 tracing::warn!(
31 session_id = session_id,
32 event = "websocket_error",
33 error = error,
34 "WebSocket error"
35 );
36}
37
38pub fn log_jitter_underrun(session_id: &str, depth_ms: f64) {
40 tracing::warn!(
41 session_id = session_id,
42 event = "jitter_underrun",
43 depth_ms = depth_ms,
44 "Jitter buffer underrun"
45 );
46}
47
48pub fn log_reconnection(session_id: &str, attempt: u32, delay_ms: u64) {
50 tracing::warn!(
51 session_id = session_id,
52 event = "reconnection",
53 attempt = attempt,
54 delay_ms = delay_ms,
55 "Reconnection attempt"
56 );
57}
58
59pub fn log_vad_event(session_id: &str, event: &str) {
61 tracing::debug!(
62 session_id = session_id,
63 event = "vad_state_change",
64 vad_event = event,
65 "VAD event"
66 );
67}
68
69pub fn log_http_request(method: &str, url: &str) {
71 tracing::info!(
72 event = "http_request",
73 http.method = method,
74 http.url = url,
75 "HTTP request"
76 );
77}
78
79pub fn log_http_response(status: u16, duration_ms: f64) {
81 tracing::info!(
82 event = "http_response",
83 http.status = status,
84 duration_ms = duration_ms,
85 "HTTP response"
86 );
87}
88
89pub fn log_http_retry(url: &str, attempt: u32, delay_ms: u64) {
91 tracing::warn!(
92 event = "http_retry",
93 http.url = url,
94 attempt = attempt,
95 delay_ms = delay_ms,
96 "HTTP retry"
97 );
98}
99
100#[cfg(test)]
101mod tests {
102 use super::*;
103
104 #[test]
105 fn noop_log_functions_compile() {
106 log_session_event("sess-1", "greeting", "connected");
108 log_tool_call("sess-1", "get_weather", 1);
109 log_ws_error("sess-1", "connection reset");
110 log_jitter_underrun("sess-1", 50.0);
111 log_reconnection("sess-1", 1, 1000);
112 log_vad_event("sess-1", "speech_start");
113 log_http_request("GET", "https://example.com");
114 log_http_response(200, 42.5);
115 log_http_retry("https://example.com", 2, 2000);
116 }
117}