diff --git a/crates/config/src/constants/app.rs b/crates/config/src/constants/app.rs index be47ba1ac..6460eea8b 100644 --- a/crates/config/src/constants/app.rs +++ b/crates/config/src/constants/app.rs @@ -194,6 +194,24 @@ pub const DEFAULT_LOG_ROTATION_TIME: &str = "hour"; /// Environment variable: RUSTFS_OBS_LOG_KEEP_FILES pub const DEFAULT_LOG_KEEP_FILES: usize = 30; +/// Default trace export enabled +/// It is used to enable or disable exporting traces +/// Default value: true +/// Environment variable: RUSTFS_OBS_TRACES_EXPORT_ENABLED +pub const DEFAULT_OBS_TRACES_EXPORT_ENABLED: bool = true; + +/// Default metrics export enabled +/// It is used to enable or disable exporting metrics +/// Default value: true +/// Environment variable: RUSTFS_OBS_METRICS_EXPORT_ENABLED +pub const DEFAULT_OBS_METRICS_EXPORT_ENABLED: bool = true; + +/// Default logs export enabled +/// It is used to enable or disable exporting logs +/// Default value: true +/// Environment variable: RUSTFS_OBS_LOGS_EXPORT_ENABLED +pub const DEFAULT_OBS_LOGS_EXPORT_ENABLED: bool = true; + /// Default log local logging enabled for rustfs /// This is the default log local logging enabled for rustfs. /// It is used to enable or disable local logging of the application. diff --git a/crates/config/src/observability/mod.rs b/crates/config/src/observability/mod.rs index ad1dc5bb3..bf7c2f8c9 100644 --- a/crates/config/src/observability/mod.rs +++ b/crates/config/src/observability/mod.rs @@ -27,6 +27,12 @@ pub const ENV_OBS_METER_INTERVAL: &str = "RUSTFS_OBS_METER_INTERVAL"; pub const ENV_OBS_SERVICE_NAME: &str = "RUSTFS_OBS_SERVICE_NAME"; pub const ENV_OBS_SERVICE_VERSION: &str = "RUSTFS_OBS_SERVICE_VERSION"; pub const ENV_OBS_ENVIRONMENT: &str = "RUSTFS_OBS_ENVIRONMENT"; + +/// Per-signal enable/disable flags (default: true) +pub const ENV_OBS_TRACES_EXPORT_ENABLED: &str = "RUSTFS_OBS_TRACES_EXPORT_ENABLED"; +pub const ENV_OBS_METRICS_EXPORT_ENABLED: &str = "RUSTFS_OBS_METRICS_EXPORT_ENABLED"; +pub const ENV_OBS_LOGS_EXPORT_ENABLED: &str = "RUSTFS_OBS_LOGS_EXPORT_ENABLED"; + pub const ENV_OBS_LOGGER_LEVEL: &str = "RUSTFS_OBS_LOGGER_LEVEL"; pub const ENV_OBS_LOG_STDOUT_ENABLED: &str = "RUSTFS_OBS_LOG_STDOUT_ENABLED"; pub const ENV_OBS_LOG_DIRECTORY: &str = "RUSTFS_OBS_LOG_DIRECTORY"; @@ -87,6 +93,9 @@ mod tests { assert_eq!(ENV_OBS_LOG_ROTATION_SIZE_MB, "RUSTFS_OBS_LOG_ROTATION_SIZE_MB"); assert_eq!(ENV_OBS_LOG_ROTATION_TIME, "RUSTFS_OBS_LOG_ROTATION_TIME"); assert_eq!(ENV_OBS_LOG_KEEP_FILES, "RUSTFS_OBS_LOG_KEEP_FILES"); + assert_eq!(ENV_OBS_TRACES_EXPORT_ENABLED, "RUSTFS_OBS_TRACES_EXPORT_ENABLED"); + assert_eq!(ENV_OBS_METRICS_EXPORT_ENABLED, "RUSTFS_OBS_METRICS_EXPORT_ENABLED"); + assert_eq!(ENV_OBS_LOGS_EXPORT_ENABLED, "RUSTFS_OBS_LOGS_EXPORT_ENABLED"); } #[test] diff --git a/crates/obs/src/config.rs b/crates/obs/src/config.rs index 5e51b77cd..7eaa4ac3d 100644 --- a/crates/obs/src/config.rs +++ b/crates/obs/src/config.rs @@ -15,13 +15,15 @@ use rustfs_config::observability::{ DEFAULT_OBS_ENVIRONMENT_PRODUCTION, ENV_OBS_ENDPOINT, ENV_OBS_ENVIRONMENT, ENV_OBS_LOG_DIRECTORY, ENV_OBS_LOG_ENDPOINT, ENV_OBS_LOG_FILENAME, ENV_OBS_LOG_KEEP_FILES, ENV_OBS_LOG_ROTATION_SIZE_MB, ENV_OBS_LOG_ROTATION_TIME, - ENV_OBS_LOG_STDOUT_ENABLED, ENV_OBS_LOGGER_LEVEL, ENV_OBS_METER_INTERVAL, ENV_OBS_METRIC_ENDPOINT, ENV_OBS_SAMPLE_RATIO, - ENV_OBS_SERVICE_NAME, ENV_OBS_SERVICE_VERSION, ENV_OBS_TRACE_ENDPOINT, ENV_OBS_USE_STDOUT, + ENV_OBS_LOG_STDOUT_ENABLED, ENV_OBS_LOGGER_LEVEL, ENV_OBS_LOGS_EXPORT_ENABLED, ENV_OBS_METER_INTERVAL, + ENV_OBS_METRIC_ENDPOINT, ENV_OBS_METRICS_EXPORT_ENABLED, ENV_OBS_SAMPLE_RATIO, ENV_OBS_SERVICE_NAME, ENV_OBS_SERVICE_VERSION, + ENV_OBS_TRACE_ENDPOINT, ENV_OBS_TRACES_EXPORT_ENABLED, ENV_OBS_USE_STDOUT, }; use rustfs_config::{ APP_NAME, DEFAULT_LOG_KEEP_FILES, DEFAULT_LOG_LEVEL, DEFAULT_LOG_ROTATION_SIZE_MB, DEFAULT_LOG_ROTATION_TIME, - DEFAULT_OBS_LOG_FILENAME, DEFAULT_OBS_LOG_STDOUT_ENABLED, ENVIRONMENT, METER_INTERVAL, SAMPLE_RATIO, SERVICE_VERSION, - USE_STDOUT, + DEFAULT_OBS_LOG_FILENAME, DEFAULT_OBS_LOG_STDOUT_ENABLED, DEFAULT_OBS_LOGS_EXPORT_ENABLED, + DEFAULT_OBS_METRICS_EXPORT_ENABLED, DEFAULT_OBS_TRACES_EXPORT_ENABLED, ENVIRONMENT, METER_INTERVAL, SAMPLE_RATIO, + SERVICE_VERSION, USE_STDOUT, }; use rustfs_utils::dirs::get_log_directory_to_string; use rustfs_utils::{get_env_bool, get_env_f64, get_env_opt_str, get_env_str, get_env_u64, get_env_usize}; @@ -56,18 +58,21 @@ use std::env; /// ``` #[derive(Debug, Deserialize, Serialize, Clone)] pub struct OtelConfig { - pub endpoint: String, // Endpoint for metric collection - pub trace_endpoint: Option, // Endpoint for trace collection - pub metric_endpoint: Option, // Endpoint for metric collection - pub log_endpoint: Option, // Endpoint for log collection - pub use_stdout: Option, // Output to stdout - pub sample_ratio: Option, // Trace sampling ratio - pub meter_interval: Option, // Metric collection interval - pub service_name: Option, // Service name - pub service_version: Option, // Service version - pub environment: Option, // Environment - pub logger_level: Option, // Logger level - pub log_stdout_enabled: Option, // Stdout logging enabled + pub endpoint: String, // Endpoint for otel collection + pub trace_endpoint: Option, // Endpoint for trace collection + pub metric_endpoint: Option, // Endpoint for metric collection + pub log_endpoint: Option, // Endpoint for log collection + pub traces_export_enabled: Option, // Enable/disable trace export + pub metrics_export_enabled: Option, // Enable/disable metric export + pub logs_export_enabled: Option, // Enable/disable log export + pub use_stdout: Option, // Output to stdout + pub sample_ratio: Option, // Trace sampling ratio + pub meter_interval: Option, // Metric collection interval + pub service_name: Option, // Service name + pub service_version: Option, // Service version + pub environment: Option, // Environment + pub logger_level: Option, // Logger level + pub log_stdout_enabled: Option, // Stdout logging enabled // Added flexi_logger related configurations pub log_directory: Option, // LOG FILE DIRECTORY pub log_filename: Option, // The name of the log file @@ -98,6 +103,9 @@ impl OtelConfig { trace_endpoint: get_env_opt_str(ENV_OBS_TRACE_ENDPOINT), metric_endpoint: get_env_opt_str(ENV_OBS_METRIC_ENDPOINT), log_endpoint: get_env_opt_str(ENV_OBS_LOG_ENDPOINT), + traces_export_enabled: Some(get_env_bool(ENV_OBS_TRACES_EXPORT_ENABLED, DEFAULT_OBS_TRACES_EXPORT_ENABLED)), + metrics_export_enabled: Some(get_env_bool(ENV_OBS_METRICS_EXPORT_ENABLED, DEFAULT_OBS_METRICS_EXPORT_ENABLED)), + logs_export_enabled: Some(get_env_bool(ENV_OBS_LOGS_EXPORT_ENABLED, DEFAULT_OBS_LOGS_EXPORT_ENABLED)), use_stdout: Some(use_stdout), sample_ratio: Some(get_env_f64(ENV_OBS_SAMPLE_RATIO, SAMPLE_RATIO)), meter_interval: Some(get_env_u64(ENV_OBS_METER_INTERVAL, METER_INTERVAL)), diff --git a/crates/obs/src/telemetry.rs b/crates/obs/src/telemetry.rs index af187fcae..6fb278dd3 100644 --- a/crates/obs/src/telemetry.rs +++ b/crates/obs/src/telemetry.rs @@ -33,8 +33,9 @@ use opentelemetry_semantic_conventions::{ attribute::{DEPLOYMENT_ENVIRONMENT_NAME, NETWORK_LOCAL_ADDRESS, SERVICE_VERSION as OTEL_SERVICE_VERSION}, }; use rustfs_config::{ - APP_NAME, DEFAULT_LOG_KEEP_FILES, DEFAULT_LOG_LEVEL, DEFAULT_OBS_LOG_STDOUT_ENABLED, ENVIRONMENT, METER_INTERVAL, - SAMPLE_RATIO, SERVICE_VERSION, + APP_NAME, DEFAULT_LOG_KEEP_FILES, DEFAULT_LOG_LEVEL, DEFAULT_OBS_LOG_STDOUT_ENABLED, DEFAULT_OBS_LOGS_EXPORT_ENABLED, + DEFAULT_OBS_METRICS_EXPORT_ENABLED, DEFAULT_OBS_TRACES_EXPORT_ENABLED, ENVIRONMENT, METER_INTERVAL, SAMPLE_RATIO, + SERVICE_VERSION, observability::{ DEFAULT_OBS_ENVIRONMENT_PRODUCTION, DEFAULT_OBS_LOG_FLUSH_MS, DEFAULT_OBS_LOG_MESSAGE_CAPA, DEFAULT_OBS_LOG_POOL_CAPA, ENV_OBS_LOG_DIRECTORY, ENV_OBS_LOG_FLUSH_MS, ENV_OBS_LOG_MESSAGE_CAPA, ENV_OBS_LOG_POOL_CAPA, @@ -417,7 +418,7 @@ fn init_observability_http(config: &OtelConfig, logger_level: &str, is_productio // Tracer(HTTP) let tracer_provider = { - if trace_ep.is_empty() { + if trace_ep.is_empty() || !config.traces_export_enabled.unwrap_or(DEFAULT_OBS_TRACES_EXPORT_ENABLED) { None } else { let exporter = opentelemetry_otlp::SpanExporter::builder() @@ -447,7 +448,7 @@ fn init_observability_http(config: &OtelConfig, logger_level: &str, is_productio // Meter(HTTP) let meter_provider = { - if metric_ep.is_empty() { + if metric_ep.is_empty() || !config.metrics_export_enabled.unwrap_or(DEFAULT_OBS_METRICS_EXPORT_ENABLED) { None } else { let exporter = opentelemetry_otlp::MetricExporter::builder() @@ -482,7 +483,7 @@ fn init_observability_http(config: &OtelConfig, logger_level: &str, is_productio // Logger(HTTP) let logger_provider = { - if log_ep.is_empty() { + if log_ep.is_empty() || !config.logs_export_enabled.unwrap_or(DEFAULT_OBS_LOGS_EXPORT_ENABLED) { None } else { let exporter = opentelemetry_otlp::LogExporter::builder()