generated from Patagia/template-nix
feat(instrumentation): Add logging to stderr config
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Some checks failed
ci/woodpecker/push/ci Pipeline failed
This commit is contained in:
parent
706b6787d3
commit
86db3cb3a0
4 changed files with 14 additions and 5 deletions
|
@ -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<String>,
|
||||
|
||||
#[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");
|
||||
|
||||
|
|
|
@ -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<String>,
|
||||
|
||||
#[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");
|
||||
|
||||
|
|
|
@ -74,11 +74,14 @@ fn init_tracer_provider(otel_endpoint: &String) -> Result<TracerProvider> {
|
|||
}
|
||||
|
||||
// Initialize tracing-subscriber and return TracingGuard for opentelemetry-related termination processing
|
||||
pub fn init_tracing(otel_endpoint: Option<&String>) -> Result<TracingGuard> {
|
||||
pub fn init_tracing(otel_endpoint: Option<&String>, log_stderr: bool) -> Result<TracingGuard> {
|
||||
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)?),
|
||||
|
|
2
justfile
2
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:
|
||||
|
|
Loading…
Reference in a new issue