mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-22 04:16:38 +00:00
obs(export): Add env vars to selectivly disable exporting traces/metrics/logs (#1853)
Co-authored-by: houseme <housemecn@gmail.com>
This commit is contained in:
@@ -194,6 +194,24 @@ pub const DEFAULT_LOG_ROTATION_TIME: &str = "hour";
|
|||||||
/// Environment variable: RUSTFS_OBS_LOG_KEEP_FILES
|
/// Environment variable: RUSTFS_OBS_LOG_KEEP_FILES
|
||||||
pub const DEFAULT_LOG_KEEP_FILES: usize = 30;
|
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
|
/// Default log local logging enabled for rustfs
|
||||||
/// This is the 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.
|
/// It is used to enable or disable local logging of the application.
|
||||||
|
|||||||
@@ -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_NAME: &str = "RUSTFS_OBS_SERVICE_NAME";
|
||||||
pub const ENV_OBS_SERVICE_VERSION: &str = "RUSTFS_OBS_SERVICE_VERSION";
|
pub const ENV_OBS_SERVICE_VERSION: &str = "RUSTFS_OBS_SERVICE_VERSION";
|
||||||
pub const ENV_OBS_ENVIRONMENT: &str = "RUSTFS_OBS_ENVIRONMENT";
|
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_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_STDOUT_ENABLED: &str = "RUSTFS_OBS_LOG_STDOUT_ENABLED";
|
||||||
pub const ENV_OBS_LOG_DIRECTORY: &str = "RUSTFS_OBS_LOG_DIRECTORY";
|
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_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_ROTATION_TIME, "RUSTFS_OBS_LOG_ROTATION_TIME");
|
||||||
assert_eq!(ENV_OBS_LOG_KEEP_FILES, "RUSTFS_OBS_LOG_KEEP_FILES");
|
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]
|
#[test]
|
||||||
|
|||||||
+24
-16
@@ -15,13 +15,15 @@
|
|||||||
use rustfs_config::observability::{
|
use rustfs_config::observability::{
|
||||||
DEFAULT_OBS_ENVIRONMENT_PRODUCTION, ENV_OBS_ENDPOINT, ENV_OBS_ENVIRONMENT, ENV_OBS_LOG_DIRECTORY, ENV_OBS_LOG_ENDPOINT,
|
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_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_LOG_STDOUT_ENABLED, ENV_OBS_LOGGER_LEVEL, ENV_OBS_LOGS_EXPORT_ENABLED, ENV_OBS_METER_INTERVAL,
|
||||||
ENV_OBS_SERVICE_NAME, ENV_OBS_SERVICE_VERSION, ENV_OBS_TRACE_ENDPOINT, ENV_OBS_USE_STDOUT,
|
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::{
|
use rustfs_config::{
|
||||||
APP_NAME, DEFAULT_LOG_KEEP_FILES, DEFAULT_LOG_LEVEL, DEFAULT_LOG_ROTATION_SIZE_MB, DEFAULT_LOG_ROTATION_TIME,
|
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,
|
DEFAULT_OBS_LOG_FILENAME, DEFAULT_OBS_LOG_STDOUT_ENABLED, DEFAULT_OBS_LOGS_EXPORT_ENABLED,
|
||||||
USE_STDOUT,
|
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::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};
|
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)]
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct OtelConfig {
|
pub struct OtelConfig {
|
||||||
pub endpoint: String, // Endpoint for metric collection
|
pub endpoint: String, // Endpoint for otel collection
|
||||||
pub trace_endpoint: Option<String>, // Endpoint for trace collection
|
pub trace_endpoint: Option<String>, // Endpoint for trace collection
|
||||||
pub metric_endpoint: Option<String>, // Endpoint for metric collection
|
pub metric_endpoint: Option<String>, // Endpoint for metric collection
|
||||||
pub log_endpoint: Option<String>, // Endpoint for log collection
|
pub log_endpoint: Option<String>, // Endpoint for log collection
|
||||||
pub use_stdout: Option<bool>, // Output to stdout
|
pub traces_export_enabled: Option<bool>, // Enable/disable trace export
|
||||||
pub sample_ratio: Option<f64>, // Trace sampling ratio
|
pub metrics_export_enabled: Option<bool>, // Enable/disable metric export
|
||||||
pub meter_interval: Option<u64>, // Metric collection interval
|
pub logs_export_enabled: Option<bool>, // Enable/disable log export
|
||||||
pub service_name: Option<String>, // Service name
|
pub use_stdout: Option<bool>, // Output to stdout
|
||||||
pub service_version: Option<String>, // Service version
|
pub sample_ratio: Option<f64>, // Trace sampling ratio
|
||||||
pub environment: Option<String>, // Environment
|
pub meter_interval: Option<u64>, // Metric collection interval
|
||||||
pub logger_level: Option<String>, // Logger level
|
pub service_name: Option<String>, // Service name
|
||||||
pub log_stdout_enabled: Option<bool>, // Stdout logging enabled
|
pub service_version: Option<String>, // Service version
|
||||||
|
pub environment: Option<String>, // Environment
|
||||||
|
pub logger_level: Option<String>, // Logger level
|
||||||
|
pub log_stdout_enabled: Option<bool>, // Stdout logging enabled
|
||||||
// Added flexi_logger related configurations
|
// Added flexi_logger related configurations
|
||||||
pub log_directory: Option<String>, // LOG FILE DIRECTORY
|
pub log_directory: Option<String>, // LOG FILE DIRECTORY
|
||||||
pub log_filename: Option<String>, // The name of the log file
|
pub log_filename: Option<String>, // The name of the log file
|
||||||
@@ -98,6 +103,9 @@ impl OtelConfig {
|
|||||||
trace_endpoint: get_env_opt_str(ENV_OBS_TRACE_ENDPOINT),
|
trace_endpoint: get_env_opt_str(ENV_OBS_TRACE_ENDPOINT),
|
||||||
metric_endpoint: get_env_opt_str(ENV_OBS_METRIC_ENDPOINT),
|
metric_endpoint: get_env_opt_str(ENV_OBS_METRIC_ENDPOINT),
|
||||||
log_endpoint: get_env_opt_str(ENV_OBS_LOG_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),
|
use_stdout: Some(use_stdout),
|
||||||
sample_ratio: Some(get_env_f64(ENV_OBS_SAMPLE_RATIO, SAMPLE_RATIO)),
|
sample_ratio: Some(get_env_f64(ENV_OBS_SAMPLE_RATIO, SAMPLE_RATIO)),
|
||||||
meter_interval: Some(get_env_u64(ENV_OBS_METER_INTERVAL, METER_INTERVAL)),
|
meter_interval: Some(get_env_u64(ENV_OBS_METER_INTERVAL, METER_INTERVAL)),
|
||||||
|
|||||||
@@ -33,8 +33,9 @@ use opentelemetry_semantic_conventions::{
|
|||||||
attribute::{DEPLOYMENT_ENVIRONMENT_NAME, NETWORK_LOCAL_ADDRESS, SERVICE_VERSION as OTEL_SERVICE_VERSION},
|
attribute::{DEPLOYMENT_ENVIRONMENT_NAME, NETWORK_LOCAL_ADDRESS, SERVICE_VERSION as OTEL_SERVICE_VERSION},
|
||||||
};
|
};
|
||||||
use rustfs_config::{
|
use rustfs_config::{
|
||||||
APP_NAME, DEFAULT_LOG_KEEP_FILES, DEFAULT_LOG_LEVEL, DEFAULT_OBS_LOG_STDOUT_ENABLED, ENVIRONMENT, METER_INTERVAL,
|
APP_NAME, DEFAULT_LOG_KEEP_FILES, DEFAULT_LOG_LEVEL, DEFAULT_OBS_LOG_STDOUT_ENABLED, DEFAULT_OBS_LOGS_EXPORT_ENABLED,
|
||||||
SAMPLE_RATIO, SERVICE_VERSION,
|
DEFAULT_OBS_METRICS_EXPORT_ENABLED, DEFAULT_OBS_TRACES_EXPORT_ENABLED, ENVIRONMENT, METER_INTERVAL, SAMPLE_RATIO,
|
||||||
|
SERVICE_VERSION,
|
||||||
observability::{
|
observability::{
|
||||||
DEFAULT_OBS_ENVIRONMENT_PRODUCTION, DEFAULT_OBS_LOG_FLUSH_MS, DEFAULT_OBS_LOG_MESSAGE_CAPA, DEFAULT_OBS_LOG_POOL_CAPA,
|
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,
|
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)
|
// Tracer(HTTP)
|
||||||
let tracer_provider = {
|
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
|
None
|
||||||
} else {
|
} else {
|
||||||
let exporter = opentelemetry_otlp::SpanExporter::builder()
|
let exporter = opentelemetry_otlp::SpanExporter::builder()
|
||||||
@@ -447,7 +448,7 @@ fn init_observability_http(config: &OtelConfig, logger_level: &str, is_productio
|
|||||||
|
|
||||||
// Meter(HTTP)
|
// Meter(HTTP)
|
||||||
let meter_provider = {
|
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
|
None
|
||||||
} else {
|
} else {
|
||||||
let exporter = opentelemetry_otlp::MetricExporter::builder()
|
let exporter = opentelemetry_otlp::MetricExporter::builder()
|
||||||
@@ -482,7 +483,7 @@ fn init_observability_http(config: &OtelConfig, logger_level: &str, is_productio
|
|||||||
|
|
||||||
// Logger(HTTP)
|
// Logger(HTTP)
|
||||||
let logger_provider = {
|
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
|
None
|
||||||
} else {
|
} else {
|
||||||
let exporter = opentelemetry_otlp::LogExporter::builder()
|
let exporter = opentelemetry_otlp::LogExporter::builder()
|
||||||
|
|||||||
Reference in New Issue
Block a user