diff --git a/agent/src/main.rs b/agent/src/main.rs index d232061..3b9eead 100644 --- a/agent/src/main.rs +++ b/agent/src/main.rs @@ -9,12 +9,15 @@ mod patagia_api; struct Cli { #[arg(long = "telemetry-otlp-endpoint", default_value = "http://localhost:4317", value_name = "OTEL_EXPORTER_OTLP_ENDPOINT")] otlp_endpoint: Option, + + #[arg(long = "log-stderr", short = 'v', default_value = "false", value_name = "LOG_TO_STDERR")] + log_stderr: bool } #[tokio::main] async fn main() -> Result<()> { let args = Cli::parse(); - let _tracing = instrumentation::init_tracing(args.otlp_endpoint.as_ref())?; + let _tracing = instrumentation::init_tracing(args.otlp_endpoint.as_ref(), args.log_stderr)?; tracing::info!("Patagia Agent"); diff --git a/controller/src/bin/patagia-controller.rs b/controller/src/bin/patagia-controller.rs index 640390d..fbc56b8 100644 --- a/controller/src/bin/patagia-controller.rs +++ b/controller/src/bin/patagia-controller.rs @@ -17,12 +17,15 @@ use patagia_controller::context::ControllerContext; struct Cli { #[arg(long = "telemetry-otlp-endpoint", default_value = "http://localhost:4317", value_name = "OTEL_EXPORTER_OTLP_ENDPOINT")] otlp_endpoint: Option, + + #[arg(long = "log-stderr", short = 'v', default_value = "false", value_name = "LOG_TO_STDERR")] + log_stderr: bool } #[tokio::main] async fn main() -> Result<()> { let args = Cli::parse(); - let _tracing = instrumentation::init_tracing(args.otlp_endpoint.as_ref())?; + let _tracing = instrumentation::init_tracing(args.otlp_endpoint.as_ref(), args.log_stderr)?; tracing::info!("Patagia Controller"); diff --git a/instrumentation/src/lib.rs b/instrumentation/src/lib.rs index d6e1df4..62bfa08 100644 --- a/instrumentation/src/lib.rs +++ b/instrumentation/src/lib.rs @@ -74,11 +74,14 @@ fn init_tracer_provider(otel_endpoint: &String) -> Result { } // Initialize tracing-subscriber and return TracingGuard for opentelemetry-related termination processing -pub fn init_tracing(otel_endpoint: Option<&String>) -> Result { +pub fn init_tracing(otel_endpoint: Option<&String>, log_stderr: bool) -> Result { let env_filter = tracing_subscriber::EnvFilter::try_from_default_env() .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("")); - let fmt_layer = tracing_subscriber::fmt::layer().with_writer(std::io::stderr); + let fmt_layer = match log_stderr { + true => Some(tracing_subscriber::fmt::layer().with_writer(std::io::stderr)), + false => None, + }; let meter_provider = match otel_endpoint { Some(endpoint) => Some(init_meter_provider(endpoint)?), diff --git a/justfile b/justfile index deca19a..cf20a06 100644 --- a/justfile +++ b/justfile @@ -6,7 +6,7 @@ default: # Run controller run-controller $RUST_LOG="debug,h2=info,hyper_util=info,tower=info": - cargo run --package patagia-controller + cargo run --package patagia-controller -- --log-stderr # Run controller local development dev-controller: