diff --git a/docker/Dockerfile.importer_online_postgres b/docker/Dockerfile.importer_online_postgres index 9e52fb96d..d587a6b2b 100644 --- a/docker/Dockerfile.importer_online_postgres +++ b/docker/Dockerfile.importer_online_postgres @@ -13,6 +13,7 @@ RUN apt update RUN apt-get install -y libclang-dev cmake ENV CARGO_PROFILE_RELEASE_DEBUG=1 +ENV JSON_LOGS=1 RUN cargo build --release --bin importer-online --features metrics # Runtime diff --git a/docker/Dockerfile.run_stratus b/docker/Dockerfile.run_stratus index 177522df6..54fc976b1 100644 --- a/docker/Dockerfile.run_stratus +++ b/docker/Dockerfile.run_stratus @@ -13,6 +13,7 @@ RUN apt update RUN apt-get install -y libclang-dev cmake ENV CARGO_PROFILE_RELEASE_DEBUG=1 +ENV JSON_LOGS=1 RUN cargo build --release --features metrics # Runtime diff --git a/docker/Dockerfile.run_with_importer b/docker/Dockerfile.run_with_importer index d269d5703..c55c635a5 100644 --- a/docker/Dockerfile.run_with_importer +++ b/docker/Dockerfile.run_with_importer @@ -13,6 +13,7 @@ RUN apt update RUN apt-get install -y libclang-dev cmake ENV CARGO_PROFILE_RELEASE_DEBUG=1 +ENV JSON_LOGS=1 RUN cargo build --release --bin run-with-importer --features metrics,rocks # Runtime diff --git a/docker/Dockerfile.run_with_importer_postgres b/docker/Dockerfile.run_with_importer_postgres index 2130d20c7..db8c48f97 100644 --- a/docker/Dockerfile.run_with_importer_postgres +++ b/docker/Dockerfile.run_with_importer_postgres @@ -13,6 +13,7 @@ RUN apt update RUN apt-get install -y libclang-dev cmake ENV CARGO_PROFILE_RELEASE_DEBUG=1 +ENV JSON_LOGS=1 RUN cargo build --release --bin run-with-importer --features metrics # Runtime diff --git a/src/infra/tracing.rs b/src/infra/tracing.rs index 73d772873..e2d8cf548 100644 --- a/src/infra/tracing.rs +++ b/src/infra/tracing.rs @@ -1,5 +1,7 @@ //! Tracing services. +use std::env; + use opentelemetry::KeyValue; use opentelemetry_otlp::WithExportConfig; use opentelemetry_sdk::runtime; @@ -24,19 +26,23 @@ pub fn init_tracing(url: Option<&String>) { fn init_stdout_tracing() { // if tracing level not configured, set default - if std::env::var("RUST_LOG").is_err() { - std::env::set_var("RUST_LOG", "stratus=debug"); + if env::var("RUST_LOG").is_err() { + env::set_var("RUST_LOG", "stratus=debug"); } - tracing_subscriber::fmt() - .compact() + let subscriber = tracing_subscriber::fmt() .with_target(false) .with_thread_ids(true) .with_thread_names(true) .with_ansi(false) - .with_env_filter(EnvFilter::from_default_env()) - .try_init() - .expect("failed to start tracing"); + .with_env_filter(EnvFilter::from_default_env()); + + let json_logs = env::var_os("JSON_LOGS").is_some(); + if json_logs { + subscriber.json().init(); + } else { + subscriber.compact().init(); + } } // Only works if run inside the tokio runtime