From 82085b4b1140be412607243773c7b669c73d1d31 Mon Sep 17 00:00:00 2001 From: Sonic Build Admin Date: Wed, 4 Feb 2026 01:58:27 +0000 Subject: [PATCH] [countersyncd] fix otel actor log level **What I did** - Wrapping with log::log_enabled!(log::Level::Debug) avoids the cost of building log output unless Debug is enabled. - Changing print_otel_metrics() to Debug level prevents noisy logs in normal operation; it only shows up when debugging. - Removing print_to_console simplifies config and relies solely on log levels to control output. **Why I did it** Avoids the cost of building log output unless Debug is enabled. **How I verified it** Verified in internal setup. **Details if related** --- crates/countersyncd/src/actor/otel.rs | 28 ++++++++++++--------------- crates/countersyncd/src/main.rs | 10 ---------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/crates/countersyncd/src/actor/otel.rs b/crates/countersyncd/src/actor/otel.rs index 1d316586..3da7bd3c 100644 --- a/crates/countersyncd/src/actor/otel.rs +++ b/crates/countersyncd/src/actor/otel.rs @@ -43,8 +43,6 @@ const MAX_EXPORT_RETRIES: u64 = 30; /// Configuration for the OtelActor #[derive(Debug, Clone)] pub struct OtelActorConfig { - /// Whether to print statistics to console - pub print_to_console: bool, /// OpenTelemetry collector endpoint pub collector_endpoint: String, /// Max counters to accumulate before forcing an export @@ -56,7 +54,6 @@ pub struct OtelActorConfig { impl Default for OtelActorConfig { fn default() -> Self { Self { - print_to_console: true, collector_endpoint: "http://localhost:4317".to_string(), max_counters_per_export: 10_000, flush_timeout: Duration::from_secs(1), @@ -139,8 +136,7 @@ impl OtelActor { }; info!( - "OtelActor initialized - console: {}, endpoint: {}", - config.print_to_console, + "OtelActor initialized - endpoint: {}", config.collector_endpoint ); @@ -221,7 +217,7 @@ impl OtelActor { let otel_metrics = OtelMetrics::from_sai_stats(&stats); let counters_in_message = stats.stats.len(); - if self.config.print_to_console { + if log::log_enabled!(log::Level::Debug) { self.print_otel_metrics(&otel_metrics).await; } @@ -245,7 +241,7 @@ impl OtelActor { async fn print_otel_metrics(&mut self, otel_metrics: &OtelMetrics) { self.console_reports += 1; - info!( + debug!( "[OTel Report #{}] Service: {}, Scope: {} v{}, Total Gauges: {}, Messages Received: {}, Exports: {} (Failures: {})", self.console_reports, otel_metrics.service_name, @@ -258,24 +254,24 @@ impl OtelActor { ); if !otel_metrics.is_empty() { - info!("Gauge Metrics:"); + debug!("Gauge Metrics:"); for (index, gauge) in otel_metrics.gauges.iter().enumerate() { let data_point = &gauge.data_points[0]; - info!("[{:3}] Gauge: {}", index + 1, gauge.name); - info!("Value: {}", data_point.value); - info!("Unit: {}", gauge.unit); - info!("Time: {}ns", data_point.time_unix_nano); - info!("Description: {}", gauge.description); + debug!("[{:3}] Gauge: {}", index + 1, gauge.name); + debug!("Value: {}", data_point.value); + debug!("Unit: {}", gauge.unit); + debug!("Time: {}ns", data_point.time_unix_nano); + debug!("Description: {}", gauge.description); if !data_point.attributes.is_empty() { - info!("Attributes:"); + debug!("Attributes:"); for attr in &data_point.attributes { - info!(" - {}={}", attr.key, attr.value); + debug!(" - {}={}", attr.key, attr.value); } } - info!("Raw Gauge: {:#?}", gauge); + debug!("Raw Gauge: {:#?}", gauge); } } } diff --git a/crates/countersyncd/src/main.rs b/crates/countersyncd/src/main.rs index 53b6a60f..ceac2c01 100644 --- a/crates/countersyncd/src/main.rs +++ b/crates/countersyncd/src/main.rs @@ -176,14 +176,6 @@ struct Args { )] otel_endpoint: String, - /// Enable OpenTelemetry console output - #[arg( - long, - default_value = "true", - help = "Print OpenTelemetry metrics to console" - )] - otel_console: bool, - /// Channel capacity for otel communication #[arg( long, @@ -234,7 +226,6 @@ async fn main() -> Result<(), Box> { info!("OpenTelemetry export enabled: {}", args.enable_otel); if args.enable_otel { info!("OpenTelemetry endpoint: {}", args.otel_endpoint); - info!("OpenTelemetry console output: {}", args.otel_console); info!( "OpenTelemetry batching: max_counters_per_export={}, flush_timeout_ms={}", args.otel_max_counters_per_export, args.otel_flush_timeout_ms @@ -331,7 +322,6 @@ async fn main() -> Result<(), Box> { // Configure OpenTelemetry export with settings from command line arguments let otel_actor = if args.enable_otel { let otel_config = OtelActorConfig { - print_to_console: args.otel_console, collector_endpoint: args.otel_endpoint.clone(), max_counters_per_export: args.otel_max_counters_per_export, flush_timeout: std::time::Duration::from_millis(args.otel_flush_timeout_ms),