diff --git a/control-plane/agents/src/bin/core/main.rs b/control-plane/agents/src/bin/core/main.rs index aea9b85c3..cde718775 100644 --- a/control-plane/agents/src/bin/core/main.rs +++ b/control-plane/agents/src/bin/core/main.rs @@ -116,7 +116,7 @@ pub(crate) struct CliArgs { pub(crate) etcd_page_limit: u32, /// Formatting style to be used while logging. - #[clap(global = true, default_value = FmtStyle::Pretty.as_ref(), short, long)] + #[clap(default_value = FmtStyle::Pretty.as_ref(), short, long)] fmt_style: FmtStyle, /// Use ANSI colors for the logs. @@ -164,10 +164,10 @@ async fn main() -> anyhow::Result<()> { let cli_args = CliArgs::args(); utils::print_package_info!(); println!("Using options: {cli_args:?}"); - let fmt_style = cli_args.fmt_style.clone(); + // let fmt_style = cli_args.fmt_style.clone(); utils::tracing_telemetry::TracingTelemetry::builder() .with_writer(FmtLayer::Stdout) - .with_style(fmt_style) + .with_style(cli_args.fmt_style) .with_colors(cli_args.ansi_colors) .init( "agent-core", diff --git a/control-plane/agents/src/bin/ha/cluster/main.rs b/control-plane/agents/src/bin/ha/cluster/main.rs index 6f3a08a8b..025d9666f 100644 --- a/control-plane/agents/src/bin/ha/cluster/main.rs +++ b/control-plane/agents/src/bin/ha/cluster/main.rs @@ -52,7 +52,7 @@ struct Cli { events_url: Option, /// Formatting style to be used while logging. - #[clap(global = true, default_value = FmtStyle::Pretty.as_ref(), short, long)] + #[clap(default_value = FmtStyle::Pretty.as_ref(), short, long)] fmt_style: FmtStyle, /// If set, configures the output to be in ansi color format. @@ -77,10 +77,9 @@ pub(crate) fn core_grpc<'a>() -> &'a CoreClient { } fn initialize_tracing(args: &Cli) { - let fmt_style = &args.fmt_style; utils::tracing_telemetry::TracingTelemetry::builder() .with_writer(FmtLayer::Stdout) - .with_style(fmt_style.clone()) + .with_style(args.fmt_style) .with_colors(args.ansi_colors) .init( "agent-ha-cluster", diff --git a/control-plane/agents/src/bin/ha/node/main.rs b/control-plane/agents/src/bin/ha/node/main.rs index 0ee7d5df9..39c262f06 100644 --- a/control-plane/agents/src/bin/ha/node/main.rs +++ b/control-plane/agents/src/bin/ha/node/main.rs @@ -80,7 +80,7 @@ struct Cli { events_url: Option, /// Formatting style to be used while logging. - #[clap(global = true, default_value = FmtStyle::Pretty.as_ref(), short, long)] + #[clap(default_value = FmtStyle::Pretty.as_ref(), short, long)] fmt_style: FmtStyle, /// Enable ansi colors for logs. @@ -116,11 +116,9 @@ async fn main() -> anyhow::Result<()> { utils::print_package_info!(); - let fmt_style = cli_args.fmt_style.clone(); - utils::tracing_telemetry::TracingTelemetry::builder() .with_writer(FmtLayer::Stdout) - .with_style(fmt_style) + .with_style(cli_args.fmt_style) .with_colors(cli_args.ansi_colors) .init( "agent-ha-node", diff --git a/control-plane/csi-driver/src/bin/controller/main.rs b/control-plane/csi-driver/src/bin/controller/main.rs index 04d8dc51d..efbb958cb 100644 --- a/control-plane/csi-driver/src/bin/controller/main.rs +++ b/control-plane/csi-driver/src/bin/controller/main.rs @@ -126,7 +126,7 @@ async fn main() -> anyhow::Result<()> { let ansi_colors = args.get_flag("ansi-colors"); utils::tracing_telemetry::TracingTelemetry::builder() .with_writer(FmtLayer::Stdout) - .with_style(fmt_style.clone()) + .with_style(*fmt_style) .with_colors(ansi_colors) .init( "csi-controller", diff --git a/control-plane/csi-driver/src/bin/node/main_.rs b/control-plane/csi-driver/src/bin/node/main_.rs index b26571c2d..89cae9801 100644 --- a/control-plane/csi-driver/src/bin/node/main_.rs +++ b/control-plane/csi-driver/src/bin/node/main_.rs @@ -265,7 +265,7 @@ pub(super) async fn main() -> anyhow::Result<()> { let colors = matches.get_flag("ansi-colors"); utils::tracing_telemetry::TracingTelemetry::builder() .with_writer(FmtLayer::Stdout) - .with_style(fmt_style.clone()) + .with_style(*fmt_style) .with_colors(colors) .init("csi-node", tags, None, None); diff --git a/control-plane/rest/service/src/main.rs b/control-plane/rest/service/src/main.rs index 26d756626..d83846e5a 100644 --- a/control-plane/rest/service/src/main.rs +++ b/control-plane/rest/service/src/main.rs @@ -78,7 +78,7 @@ pub(crate) struct CliArgs { max_workers: usize, /// Formatting style to be used while logging. - #[clap(global = true, default_value = FmtStyle::Pretty.as_ref(), short, long)] + #[clap(default_value = FmtStyle::Pretty.as_ref(), short, long)] fmt_style: FmtStyle, /// Use ANSI colors for logs. @@ -214,11 +214,9 @@ async fn main() -> anyhow::Result<()> { let cli_args = CliArgs::args(); println!("Using options: {:?}", &cli_args); - let fmt_style = cli_args.fmt_style.clone(); - utils::tracing_telemetry::TracingTelemetry::builder() .with_writer(FmtLayer::Stdout) - .with_style(fmt_style) + .with_style(cli_args.fmt_style) .with_colors(cli_args.ansi_colors) .init( "rest-server", diff --git a/k8s/operators/src/pool/main.rs b/k8s/operators/src/pool/main.rs index dee0e0622..330bc4d0e 100644 --- a/k8s/operators/src/pool/main.rs +++ b/k8s/operators/src/pool/main.rs @@ -261,7 +261,7 @@ async fn main() -> anyhow::Result<()> { let ansi_colors = matches.get_flag("ansi-colors"); utils::tracing_telemetry::TracingTelemetry::builder() .with_writer(FmtLayer::Stdout) - .with_style(fmt_style.clone()) + .with_style(*fmt_style) .with_colors(ansi_colors) .init( "agent-ha-node", diff --git a/utils/dependencies b/utils/dependencies index e95cf1bed..d96035c16 160000 --- a/utils/dependencies +++ b/utils/dependencies @@ -1 +1 @@ -Subproject commit e95cf1bed516570e78b4d5e1cf9ae546d79286ba +Subproject commit d96035c16bc92d121db0fd1c06ab921fb3531847 diff --git a/utils/utils-lib/src/tracing_telemetry.rs b/utils/utils-lib/src/tracing_telemetry.rs index fb5dd6fc8..56400160b 100644 --- a/utils/utils-lib/src/tracing_telemetry.rs +++ b/utils/utils-lib/src/tracing_telemetry.rs @@ -3,7 +3,7 @@ pub use opentelemetry::{global, trace, Context, KeyValue}; use event_publisher::event_handler::EventHandle; use opentelemetry::sdk::{propagation::TraceContextPropagator, trace::Tracer, Resource}; -use tracing::{error, Level}; +use tracing::Level; use tracing_subscriber::{filter, layer::SubscriberExt, util::SubscriberInitExt, Layer, Registry}; /// Parse KeyValues from structopt's cmdline arguments @@ -51,12 +51,12 @@ pub enum FmtLayer { } /// Tracing telemetry style. -#[derive(Debug, Clone, strum_macros::EnumString, strum_macros::AsRefStr)] +#[derive(Debug, Clone, Copy, strum_macros::EnumString, strum_macros::AsRefStr)] #[strum(serialize_all = "lowercase")] pub enum FmtStyle { /// Compact style. Compact, - /// Pretty Style + /// Pretty Style. Pretty, /// JSON Style. Json, @@ -105,49 +105,41 @@ impl TracingTelemetry { let stderr = tracing_subscriber::fmt::layer() .with_writer(std::io::stderr) .with_ansi(self.colors); - let init_jaeger: bool; - let tracer: Option = match jaeger { - Some(val) => { - init_jaeger = true; - let tracing_tags = - tracing_tags - .into_iter() - .fold(Vec::::new(), |mut acc, kv| { - if !acc.iter().any(|acc| acc.key == kv.key) { - acc.push(kv); - } - acc - }); - set_jaeger_env(); - global::set_text_map_propagator(TraceContextPropagator::new()); - let pipeline = opentelemetry_jaeger::new_agent_pipeline() - .with_endpoint(val) - .with_service_name("service_name") - .with_trace_config( - opentelemetry::sdk::trace::Config::default() - .with_resource(Resource::new(tracing_tags)), - ); - match pipeline.install_batch(opentelemetry::runtime::TokioCurrentThread) { - Ok(tracer) => Some(tracer), - Err(err) => { - panic!("Failed to install OpenTelemetry pipeline: {}", err); - } + let tracer: Option = if let Some(val) = jaeger { + let tracing_tags = + tracing_tags + .into_iter() + .fold(Vec::::new(), |mut acc, kv| { + if !acc.iter().any(|acc| acc.key == kv.key) { + acc.push(kv); + } + acc + }); + set_jaeger_env(); + global::set_text_map_propagator(TraceContextPropagator::new()); + let pipeline = opentelemetry_jaeger::new_agent_pipeline() + .with_endpoint(val) + .with_service_name("service_name") + .with_trace_config( + opentelemetry::sdk::trace::Config::default() + .with_resource(Resource::new(tracing_tags)), + ); + match pipeline.install_batch(opentelemetry::runtime::TokioCurrentThread) { + Ok(tracer) => Some(tracer), + Err(err) => { + panic!("Failed to install OpenTelemetry pipeline: {}", err); } } - None => { - init_jaeger = false; - error!("Jaeger endpoint not configured"); - None - } + } else { + None }; // Get the optional eventing layer. - let events_layer = match events_url { - Some(url) => { - let target = filter::Targets::new().with_target(EVENT_BUS, Level::INFO); - Some(EventHandle::init(url.to_string(), service_name).with_filter(target)) - } - None => None, + let events_layer = if let Some(url) = events_url { + let target = filter::Targets::new().with_target(EVENT_BUS, Level::INFO); + Some(EventHandle::init(url.to_string(), service_name).with_filter(target)) + } else { + None }; let subscriber = Registry::default() @@ -156,48 +148,48 @@ impl TracingTelemetry { match (self.writer, self.style) { (FmtLayer::Stderr, FmtStyle::Compact) => { - if init_jaeger { - let telemetry = tracing_opentelemetry::layer().with_tracer(tracer.unwrap()); + if let Some(tracer) = tracer { + let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); subscriber.with(stderr.compact()).with(telemetry).init(); } else { subscriber.with(stderr.compact()).init(); } } (FmtLayer::Stdout, FmtStyle::Compact) => { - if init_jaeger { - let telemetry = tracing_opentelemetry::layer().with_tracer(tracer.unwrap()); + if let Some(tracer) = tracer { + let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); subscriber.with(stdout.compact()).with(telemetry).init(); } else { subscriber.with(stdout.compact()).init(); } } (FmtLayer::Stderr, FmtStyle::Pretty) => { - if init_jaeger { - let telemetry = tracing_opentelemetry::layer().with_tracer(tracer.unwrap()); + if let Some(tracer) = tracer { + let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); subscriber.with(stderr.pretty()).with(telemetry).init(); } else { subscriber.with(stderr.pretty()).init(); } } (FmtLayer::Stdout, FmtStyle::Pretty) => { - if init_jaeger { - let telemetry = tracing_opentelemetry::layer().with_tracer(tracer.unwrap()); + if let Some(tracer) = tracer { + let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); subscriber.with(stdout.pretty()).with(telemetry).init(); } else { subscriber.with(stdout.pretty()).init(); } } (FmtLayer::Stdout, FmtStyle::Json) => { - if init_jaeger { - let telemetry = tracing_opentelemetry::layer().with_tracer(tracer.unwrap()); + if let Some(tracer) = tracer { + let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); subscriber.with(stdout.json()).with(telemetry).init(); } else { subscriber.with(stdout.json()).init(); } } (FmtLayer::Stderr, FmtStyle::Json) => { - if init_jaeger { - let telemetry = tracing_opentelemetry::layer().with_tracer(tracer.unwrap()); + if let Some(tracer) = tracer { + let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); subscriber.with(stderr.json()).with(telemetry).init(); } else { subscriber.with(stderr.json()).init(); @@ -205,8 +197,8 @@ impl TracingTelemetry { } (FmtLayer::None, _) => { let subscriber = Registry::default().with(tracing_filter::rust_log_filter()); - if init_jaeger { - let telemetry = tracing_opentelemetry::layer().with_tracer(tracer.unwrap()); + if let Some(tracer) = tracer { + let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); subscriber.with(telemetry).init(); } else { subscriber.init()