Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: configure tracing only once #2621

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 16 additions & 7 deletions crates/starknet_sequencer_infra/src/trace_util.rs
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion crates/starknet_sequencer_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading