diff --git a/crates/starknet_integration_tests/tests/end_to_end_flow_test.rs b/crates/starknet_integration_tests/tests/end_to_end_flow_test.rs index c65afdee98..f6737ac0e0 100644 --- a/crates/starknet_integration_tests/tests/end_to_end_flow_test.rs +++ b/crates/starknet_integration_tests/tests/end_to_end_flow_test.rs @@ -36,7 +36,7 @@ fn tx_generator() -> MultiAccountTransactionGenerator { #[rstest] #[tokio::test] async fn end_to_end_flow(mut tx_generator: MultiAccountTransactionGenerator) { - configure_tracing(); + configure_tracing().await; const LISTEN_TO_BROADCAST_MESSAGES_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(5); diff --git a/crates/starknet_integration_tests/tests/end_to_end_integration_test.rs b/crates/starknet_integration_tests/tests/end_to_end_integration_test.rs index f699e65bad..fdb2d8f082 100644 --- a/crates/starknet_integration_tests/tests/end_to_end_integration_test.rs +++ b/crates/starknet_integration_tests/tests/end_to_end_integration_test.rs @@ -67,7 +67,7 @@ async fn test_end_to_end_integration(mut tx_generator: MultiAccountTransactionGe const EXPECTED_BLOCK_NUMBER: BlockNumber = BlockNumber(15); - configure_tracing(); + configure_tracing().await; info!("Running integration test setup."); // Creating the storage for the test. diff --git a/crates/starknet_sequencer_infra/src/trace_util.rs b/crates/starknet_sequencer_infra/src/trace_util.rs index 6506402b98..6d01e5fb86 100644 --- a/crates/starknet_sequencer_infra/src/trace_util.rs +++ b/crates/starknet_sequencer_infra/src/trace_util.rs @@ -1,15 +1,24 @@ +use tokio::sync::OnceCell; use tracing::metadata::LevelFilter; use tracing_subscriber::prelude::*; use tracing_subscriber::{fmt, EnvFilter}; const DEFAULT_LEVEL: LevelFilter = LevelFilter::INFO; +// Define a OnceCell to ensure the configuration is initialized only once +static TRACING_INITIALIZED: OnceCell<()> = OnceCell::const_new(); -pub fn configure_tracing() { - let fmt_layer = fmt::layer().compact().with_target(true); - let level_filter_layer = - EnvFilter::builder().with_default_directive(DEFAULT_LEVEL.into()).from_env_lossy(); +pub async fn configure_tracing() { + TRACING_INITIALIZED + .get_or_init(|| async { + let fmt_layer = fmt::layer().compact().with_target(true); + let level_filter_layer = + EnvFilter::builder().with_default_directive(DEFAULT_LEVEL.into()).from_env_lossy(); - // This sets a single subscriber to all of the threads. We may want to implement different - // subscriber for some threads and use set_global_default instead of init. - tracing_subscriber::registry().with(fmt_layer).with(level_filter_layer).init(); + // This sets a single subscriber to all of the threads. We may want to implement + // different subscriber for some threads and use set_global_default instead + // of init. + tracing_subscriber::registry().with(fmt_layer).with(level_filter_layer).init(); + tracing::info!("Tracing has been successfully initialized."); + }) + .await; } diff --git a/crates/starknet_sequencer_node/src/main.rs b/crates/starknet_sequencer_node/src/main.rs index af2e660948..3f01e87c83 100644 --- a/crates/starknet_sequencer_node/src/main.rs +++ b/crates/starknet_sequencer_node/src/main.rs @@ -11,7 +11,7 @@ use tracing::{error, info}; #[tokio::main] async fn main() -> anyhow::Result<()> { - configure_tracing(); + configure_tracing().await; let config = SequencerNodeConfig::load_and_process(args().collect()); if let Err(ConfigError::CommandInput(clap_err)) = config {