rs_zero/observability/
redis.rs1use std::time::Duration;
2
3use crate::observability::{
4 MetricsRegistry, RedisDegradationLabels, RedisEventLabels, RedisMetricLabels,
5};
6
7pub fn record_redis_command(
9 metrics: Option<&MetricsRegistry>,
10 command: &str,
11 shard: &str,
12 result: &str,
13 duration: Duration,
14) {
15 if let Some(metrics) = metrics {
16 metrics.record_redis_command(RedisMetricLabels::new(command, shard, result), duration);
17 }
18 let span = tracing::debug_span!(
19 "rs_zero.redis.command",
20 command = command,
21 shard = shard,
22 result = result,
23 duration_ms = duration.as_millis()
24 );
25 let _entered = span.enter();
26 tracing::debug!("redis command recorded");
27}
28
29pub fn record_redis_event(
31 metrics: Option<&MetricsRegistry>,
32 event: &str,
33 shard: &str,
34 result: &str,
35) {
36 if let Some(metrics) = metrics {
37 metrics.record_redis_event(RedisEventLabels::new(event, shard, result));
38 }
39 tracing::debug!(event, shard, result, "redis event recorded");
40}
41
42pub fn record_redis_degradation(
44 metrics: Option<&MetricsRegistry>,
45 operation: &str,
46 action: &str,
47 shard: &str,
48) {
49 if let Some(metrics) = metrics {
50 metrics.record_redis_degradation(RedisDegradationLabels::new(operation, action, shard));
51 }
52 tracing::debug!(operation, action, shard, "redis degradation recorded");
53}