gemini_adk_rs/telemetry/
metrics.rs1#[cfg(feature = "metrics")]
7pub fn record_agent_started(agent_name: &str) {
8 metrics::counter!("gemini_agent_started_total", "agent" => agent_name.to_string()).increment(1);
9}
10
11#[cfg(feature = "metrics")]
13pub fn record_agent_completed(agent_name: &str, duration_ms: f64) {
14 metrics::counter!("gemini_agent_completed_total", "agent" => agent_name.to_string())
15 .increment(1);
16 metrics::histogram!("gemini_agent_duration_ms", "agent" => agent_name.to_string())
17 .record(duration_ms);
18}
19
20#[cfg(feature = "metrics")]
22pub fn record_agent_error(agent_name: &str, error_type: &str) {
23 metrics::counter!("gemini_agent_errors_total", "agent" => agent_name.to_string(), "error_type" => error_type.to_string())
24 .increment(1);
25}
26
27#[cfg(feature = "metrics")]
29pub fn record_agent_tool_dispatched(agent_name: &str, tool_name: &str) {
30 metrics::counter!("gemini_agent_tool_dispatched_total", "agent" => agent_name.to_string(), "tool" => tool_name.to_string())
31 .increment(1);
32}
33
34#[cfg(feature = "metrics")]
36pub fn record_agent_tool_duration(agent_name: &str, tool_name: &str, duration_ms: f64) {
37 metrics::histogram!("gemini_agent_tool_duration_ms", "agent" => agent_name.to_string(), "tool" => tool_name.to_string())
38 .record(duration_ms);
39}
40
41#[cfg(feature = "metrics")]
43pub fn record_agent_transfer(from: &str, to: &str) {
44 metrics::counter!("gemini_agent_transfers_total", "from" => from.to_string(), "to" => to.to_string())
45 .increment(1);
46}
47
48#[cfg(feature = "metrics")]
50pub fn record_agent_tool_dispatch(parent_agent: &str, child_agent: &str, duration_ms: f64) {
51 metrics::counter!("gemini_agent_tool_dispatch_total", "parent" => parent_agent.to_string(), "child" => child_agent.to_string())
52 .increment(1);
53 metrics::histogram!("gemini_agent_tool_dispatch_duration_ms", "parent" => parent_agent.to_string(), "child" => child_agent.to_string())
54 .record(duration_ms);
55}
56
57#[cfg(feature = "metrics")]
59pub fn record_event_loop_lag(agent_name: &str, skipped: u64) {
60 metrics::counter!("gemini_agent_event_loop_lag_total", "agent" => agent_name.to_string())
61 .increment(skipped);
62}
63
64#[cfg(not(feature = "metrics"))]
67pub fn record_agent_started(_: &str) {}
68#[cfg(not(feature = "metrics"))]
70pub fn record_agent_completed(_: &str, _: f64) {}
71#[cfg(not(feature = "metrics"))]
73pub fn record_agent_error(_: &str, _: &str) {}
74#[cfg(not(feature = "metrics"))]
76pub fn record_agent_tool_dispatched(_: &str, _: &str) {}
77#[cfg(not(feature = "metrics"))]
79pub fn record_agent_tool_duration(_: &str, _: &str, _: f64) {}
80#[cfg(not(feature = "metrics"))]
82pub fn record_agent_transfer(_: &str, _: &str) {}
83#[cfg(not(feature = "metrics"))]
85pub fn record_agent_tool_dispatch(_: &str, _: &str, _: f64) {}
86#[cfg(not(feature = "metrics"))]
88pub fn record_event_loop_lag(_: &str, _: u64) {}
89
90#[cfg(feature = "metrics")]
92pub fn record_llm_call(
93 model_id: &str,
94 agent_name: &str,
95 duration_ms: f64,
96 prompt_tokens: u32,
97 completion_tokens: u32,
98) {
99 metrics::counter!("gemini_llm_calls_total", "model" => model_id.to_string(), "agent" => agent_name.to_string())
100 .increment(1);
101 metrics::histogram!("gemini_llm_call_duration_ms", "model" => model_id.to_string(), "agent" => agent_name.to_string())
102 .record(duration_ms);
103 metrics::counter!("gemini_llm_prompt_tokens_total", "model" => model_id.to_string(), "agent" => agent_name.to_string())
104 .increment(prompt_tokens as u64);
105 metrics::counter!("gemini_llm_completion_tokens_total", "model" => model_id.to_string(), "agent" => agent_name.to_string())
106 .increment(completion_tokens as u64);
107}
108
109#[cfg(feature = "metrics")]
111pub fn record_token_usage(model_id: &str, prompt_tokens: u32, completion_tokens: u32) {
112 metrics::counter!("gemini_token_usage_prompt_total", "model" => model_id.to_string())
113 .increment(prompt_tokens as u64);
114 metrics::counter!("gemini_token_usage_completion_total", "model" => model_id.to_string())
115 .increment(completion_tokens as u64);
116}
117
118#[cfg(feature = "metrics")]
120pub fn record_phase_transition(from: &str, to: &str) {
121 metrics::counter!("gemini_phase_transitions_total", "from" => from.to_string(), "to" => to.to_string())
122 .increment(1);
123}
124
125#[cfg(feature = "metrics")]
127pub fn record_extraction_duration(extractor: &str, duration_ms: f64) {
128 metrics::histogram!("gemini_extraction_duration_ms", "extractor" => extractor.to_string())
129 .record(duration_ms);
130}
131
132#[cfg(feature = "metrics")]
134pub fn record_persistence_duration(backend: &str, duration_ms: f64) {
135 metrics::histogram!("gemini_persistence_duration_ms", "backend" => backend.to_string())
136 .record(duration_ms);
137}
138
139#[cfg(not(feature = "metrics"))]
142pub fn record_llm_call(_: &str, _: &str, _: f64, _: u32, _: u32) {}
143#[cfg(not(feature = "metrics"))]
145pub fn record_token_usage(_: &str, _: u32, _: u32) {}
146#[cfg(not(feature = "metrics"))]
148pub fn record_phase_transition(_: &str, _: &str) {}
149#[cfg(not(feature = "metrics"))]
151pub fn record_extraction_duration(_: &str, _: f64) {}
152#[cfg(not(feature = "metrics"))]
154pub fn record_persistence_duration(_: &str, _: f64) {}