Refactor: Add observability enable flag, improve comments, remove unused config params, and enhance run function error logging. (#689)

* improve code for dns log

* fix

* Improve comments, remove unused parameters in config.rs (opt), add observability enable flag, and enhance error logging in run function execution.
This commit is contained in:
houseme
2025-10-23 13:59:57 +08:00
committed by GitHub
parent f30698ec7f
commit 416d3ad5b7
12 changed files with 190 additions and 126 deletions
+19
View File
@@ -14,6 +14,8 @@
use crate::AppConfig;
use crate::telemetry::{OtelGuard, init_telemetry};
use opentelemetry::metrics::Meter;
use rustfs_config::APP_NAME;
use std::sync::{Arc, Mutex};
use tokio::sync::{OnceCell, SetError};
use tracing::{error, info};
@@ -21,6 +23,23 @@ use tracing::{error, info};
/// Global guard for OpenTelemetry tracing
static GLOBAL_GUARD: OnceCell<Arc<Mutex<OtelGuard>>> = OnceCell::const_new();
/// Flag indicating if observability is enabled
pub(crate) static IS_OBSERVABILITY_ENABLED: OnceCell<bool> = OnceCell::const_new();
/// Name of the observability meter
pub(crate) static OBSERVABILITY_METER_NAME: OnceCell<String> = OnceCell::const_new();
/// Check whether Observability is enabled
pub fn is_observability_enabled() -> bool {
IS_OBSERVABILITY_ENABLED.get().copied().unwrap_or(false)
}
/// Get the global meter for observability
pub fn global_meter() -> Meter {
let meter_name = OBSERVABILITY_METER_NAME.get().map(|s| s.as_str()).unwrap_or(APP_NAME);
opentelemetry::global::meter(meter_name)
}
/// Error type for global guard operations
#[derive(Debug, thiserror::Error)]
pub enum GlobalError {
+3
View File
@@ -13,6 +13,7 @@
// limitations under the License.
use crate::config::OtelConfig;
use crate::global::{IS_OBSERVABILITY_ENABLED, OBSERVABILITY_METER_NAME};
use flexi_logger::{
Age, Cleanup, Criterion, DeferredNow, FileSpec, LogSpecification, Naming, Record, WriteMode,
WriteMode::{AsyncWith, BufferAndFlush},
@@ -302,6 +303,8 @@ pub(crate) fn init_telemetry(config: &OtelConfig) -> OtelGuard {
logger_level,
env::var("RUST_LOG").unwrap_or_else(|_| "Not set".to_string())
);
IS_OBSERVABILITY_ENABLED.set(true).ok();
OBSERVABILITY_METER_NAME.set(service_name.to_string()).ok();
}
}