From a3a0e03c85e33820fb1252d4656da1c624790a95 Mon Sep 17 00:00:00 2001 From: ANAVHEOBA Date: Sun, 21 Dec 2025 08:41:50 -0500 Subject: [PATCH] feat: adopt tracing for structured logging (#123) Replace all uses of the log crate with the tracing ecosystem across: - pallets/validator-set - pallets/relayer-set - runtime/ - runtimes/bulletin-polkadot This aligns with upstream Polkadot SDK initiatives for improved observability and debuggability. --- Cargo.lock | 8 ++++---- pallets/relayer-set/Cargo.toml | 4 ++-- pallets/relayer-set/src/lib.rs | 4 ++-- pallets/validator-set/Cargo.toml | 4 ++-- pallets/validator-set/src/lib.rs | 4 ++-- runtime/Cargo.toml | 4 ++-- runtime/src/bridge_config.rs | 10 +++++----- runtime/src/xcm_config.rs | 8 ++++---- runtimes/bulletin-polkadot/Cargo.toml | 4 ++-- .../bulletin-polkadot/src/polkadot_bridge_config.rs | 10 +++++----- runtimes/bulletin-polkadot/src/xcm_config.rs | 4 ++-- runtimes/bulletin-polkadot/tests/tests.rs | 4 ++-- 12 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d73180c9d..2139f658c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1373,7 +1373,6 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex", - "log", "pallet-authorship", "pallet-babe", "pallet-bridge-grandpa", @@ -1424,6 +1423,7 @@ dependencies = [ "staging-xcm-executor", "static_assertions", "substrate-wasm-builder", + "tracing", ] [[package]] @@ -7118,10 +7118,10 @@ dependencies = [ name = "pallet-relayer-set" version = "1.0.0" dependencies = [ - "log", "parity-scale-codec", "polkadot-sdk-frame", "scale-info", + "tracing", ] [[package]] @@ -7289,7 +7289,6 @@ dependencies = [ name = "pallet-validator-set" version = "1.0.0" dependencies = [ - "log", "pallet-session", "pallets-common", "parity-scale-codec", @@ -7297,6 +7296,7 @@ dependencies = [ "scale-info", "serde", "sp-staking", + "tracing", ] [[package]] @@ -7827,7 +7827,6 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex", - "log", "pallet-authorship", "pallet-babe", "pallet-bridge-grandpa", @@ -7876,6 +7875,7 @@ dependencies = [ "staging-xcm-executor", "static_assertions", "substrate-wasm-builder", + "tracing", ] [[package]] diff --git a/pallets/relayer-set/Cargo.toml b/pallets/relayer-set/Cargo.toml index 1b2bb6f1b..644cce1c4 100644 --- a/pallets/relayer-set/Cargo.toml +++ b/pallets/relayer-set/Cargo.toml @@ -12,7 +12,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { workspace = true } -log = { workspace = true, default-features = true } +tracing = { workspace = true, default-features = true } scale-info = { features = ["derive"], workspace = true } polkadot-sdk-frame = { workspace = true, default-features = false, features = [ @@ -26,7 +26,7 @@ runtime-benchmarks = [ ] std = [ "codec/std", - "log/std", + "tracing/std", "polkadot-sdk-frame/std", "scale-info/std", ] diff --git a/pallets/relayer-set/src/lib.rs b/pallets/relayer-set/src/lib.rs index 150c3b312..e660c5b72 100644 --- a/pallets/relayer-set/src/lib.rs +++ b/pallets/relayer-set/src/lib.rs @@ -156,7 +156,7 @@ impl Pallet { // Decrement who's provider reference count if let Err(err) = frame_system::Pallet::::dec_providers(who) { - log::warn!( + tracing::warn!( target: LOG_TARGET, "Failed to decrement provider reference count for relayer {who:?}, \ leaking reference: {err:?}" @@ -185,7 +185,7 @@ impl Pallet { Some(relayer) => relayer.min_bridge_tx_block = frame_system::Pallet::::block_number() .saturating_add(T::BridgeTxFailCooldownBlocks::get()), - None => log::warn!( + None => tracing::warn!( target: LOG_TARGET, "Could not find signer {who:?} of failed bridge transaction in relayer set" ), diff --git a/pallets/validator-set/Cargo.toml b/pallets/validator-set/Cargo.toml index 3d6da76b5..725ddb94e 100644 --- a/pallets/validator-set/Cargo.toml +++ b/pallets/validator-set/Cargo.toml @@ -8,7 +8,7 @@ license = 'Apache-2.0' [dependencies] codec = { workspace = true, features = ["derive"] } -log = { workspace = true, default-features = true } +tracing = { workspace = true, default-features = true } scale-info = { features = ["derive"], workspace = true } polkadot-sdk-frame = { workspace = true, default-features = false, features = [ @@ -32,7 +32,7 @@ runtime-benchmarks = [ "sp-staking/runtime-benchmarks", ] std = [ - "log/std", + "tracing/std", "pallets-common/std", "sp-staking/std", 'codec/std', diff --git a/pallets/validator-set/src/lib.rs b/pallets/validator-set/src/lib.rs index e3e91c6f8..47918c653 100644 --- a/pallets/validator-set/src/lib.rs +++ b/pallets/validator-set/src/lib.rs @@ -238,13 +238,13 @@ impl Pallet { if let Err(err) = pallet_session::Pallet::::purge_keys(RawOrigin::Signed(who.clone()).into()) { - log::trace!( + tracing::trace!( target: LOG_TARGET, "Failed to purge session keys for validator {who:?}: {err:?}" ); } if let Err(err) = frame_system::Pallet::::dec_providers(who) { - log::warn!( + tracing::warn!( target: LOG_TARGET, "Failed to decrement provider reference count for validator {who:?}, \ leaking reference: {err:?}" diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 1e8da75fd..1e61fc000 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -13,7 +13,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { workspace = true, features = ["derive"] } -log = { workspace = true } +tracing = { workspace = true } scale-info = { features = ["derive"], workspace = true } serde_json = { features = ["alloc"], workspace = true } frame-executive = { workspace = true } @@ -104,7 +104,7 @@ static_assertions = { workspace = true } default = ["std"] std = [ "codec/std", - "log/std", + "tracing/std", "scale-info/std", "serde_json/std", diff --git a/runtime/src/bridge_config.rs b/runtime/src/bridge_config.rs index a419fad16..e270b633c 100644 --- a/runtime/src/bridge_config.rs +++ b/runtime/src/bridge_config.rs @@ -153,7 +153,7 @@ impl payload, Err(e) => { - log::error!( + tracing::error!( target: LOG_TARGET_BRIDGE_DISPATCH, "dispatch - payload error: {e:?} for lane_id: {:?} and message_nonce: {:?}", message.key.lane_id, @@ -167,7 +167,7 @@ impl { - log::debug!( + tracing::debug!( target: LOG_TARGET_BRIDGE_DISPATCH, "dispatch - `DispatchBlob::dispatch_blob` was ok for lane_id: {:?} and message_nonce: {:?}", message.key.lane_id, @@ -176,7 +176,7 @@ impl { - log::error!( + tracing::error!( target: LOG_TARGET_BRIDGE_DISPATCH, "dispatch - `DispatchBlob::dispatch_blob` failed with error: {e:?} for lane_id: {:?} and message_nonce: {:?}", message.key.lane_id, @@ -279,7 +279,7 @@ where XCM_LANE, &blob, ) .map_err(|e| { - log::error!( + tracing::error!( target: LOG_TARGET_BRIDGE_DISPATCH, "haul_blob result - error: {e:?} on lane: {XCM_LANE:?}", ); @@ -288,7 +288,7 @@ where let artifacts = pallet_bridge_messages::Pallet::::send_message( send_message_args, ); - log::info!( + tracing::info!( target: LOG_TARGET_BRIDGE_DISPATCH, "haul_blob result - ok: {:?} on lane: {:?}. Enqueued messages: {}", artifacts.nonce, diff --git a/runtime/src/xcm_config.rs b/runtime/src/xcm_config.rs index 589226d44..f2e816a0b 100644 --- a/runtime/src/xcm_config.rs +++ b/runtime/src/xcm_config.rs @@ -99,7 +99,7 @@ impl ConvertOrigin for KawabungaParachainAsRoot { kind: OriginKind, ) -> Result { let origin = origin.into(); - log::trace!( + tracing::trace!( target: "xcm::origin_conversion", "KawabungaParachainAsRoot origin: {origin:?}, kind: {kind:?}", ); @@ -148,7 +148,7 @@ impl> ShouldExecute max_weight: Weight, _properties: &mut xcm_executor::traits::Properties, ) -> Result<(), ProcessMessageError> { - log::trace!( + tracing::trace!( target: "xcm::barriers", "AllowUnpaidTransactsFrom origin: {origin:?}, instructions: {instructions:?}, max_weight: {max_weight:?}, properties: {_properties:?}", @@ -247,7 +247,7 @@ impl DispatchBlob for ImmediateXcmDispatcher { let message: Xcm = message.try_into().map_err(|_| DispatchBlobError::UnsupportedXcmVersion)?; - log::trace!( + tracing::trace!( target: "runtime::xcm", "Going to dispatch XCM message from {:?}: {:?}", KawabungaLocation::get(), @@ -270,7 +270,7 @@ impl DispatchBlob for ImmediateXcmDispatcher { ) .ensure_complete() .map_err(|e| { - log::trace!( + tracing::trace!( target: "runtime::xcm", "XCM message from {:?} was dispatched with an error: {:?}", KawabungaLocation::get(), diff --git a/runtimes/bulletin-polkadot/Cargo.toml b/runtimes/bulletin-polkadot/Cargo.toml index 59afd3860..503bce8d2 100644 --- a/runtimes/bulletin-polkadot/Cargo.toml +++ b/runtimes/bulletin-polkadot/Cargo.toml @@ -13,7 +13,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { workspace = true, features = ["derive"] } -log = { workspace = true } +tracing = { workspace = true } scale-info = { features = ["derive"], workspace = true } serde_json = { features = ["alloc"], workspace = true } frame-executive = { workspace = true } @@ -105,7 +105,7 @@ sp-tracing = { workspace = true } default = ["std"] std = [ "codec/std", - "log/std", + "tracing/std", "scale-info/std", "serde_json/std", diff --git a/runtimes/bulletin-polkadot/src/polkadot_bridge_config.rs b/runtimes/bulletin-polkadot/src/polkadot_bridge_config.rs index 91dc0362c..0424d0fe5 100644 --- a/runtimes/bulletin-polkadot/src/polkadot_bridge_config.rs +++ b/runtimes/bulletin-polkadot/src/polkadot_bridge_config.rs @@ -262,7 +262,7 @@ impl payload, Err(e) => { - log::error!( + tracing::error!( target: LOG_TARGET_BRIDGE_DISPATCH, "dispatch - payload error: {e:?} for lane_id: {:?} and message_nonce: {:?}", message.key.lane_id, @@ -276,7 +276,7 @@ impl { - log::debug!( + tracing::debug!( target: LOG_TARGET_BRIDGE_DISPATCH, "dispatch - `DispatchBlob::dispatch_blob` was ok for lane_id: {:?} and message_nonce: {:?}", message.key.lane_id, @@ -285,7 +285,7 @@ impl { - log::error!( + tracing::error!( target: LOG_TARGET_BRIDGE_DISPATCH, "dispatch - `DispatchBlob::dispatch_blob` failed with error: {e:?} for lane_id: {:?} and message_nonce: {:?}", message.key.lane_id, @@ -401,7 +401,7 @@ where XCM_LANE, &blob, ) .map_err(|e| { - log::error!( + tracing::error!( target: LOG_TARGET_BRIDGE_DISPATCH, "haul_blob result - error: {e:?} on lane: {XCM_LANE:?}", ); @@ -410,7 +410,7 @@ where let artifacts = pallet_bridge_messages::Pallet::::send_message( send_message_args, ); - log::info!( + tracing::info!( target: LOG_TARGET_BRIDGE_DISPATCH, "haul_blob result - ok: {:?} on lane: {:?}. Enqueued messages: {}", artifacts.nonce, diff --git a/runtimes/bulletin-polkadot/src/xcm_config.rs b/runtimes/bulletin-polkadot/src/xcm_config.rs index 0d0e6f2c1..517488232 100644 --- a/runtimes/bulletin-polkadot/src/xcm_config.rs +++ b/runtimes/bulletin-polkadot/src/xcm_config.rs @@ -159,7 +159,7 @@ impl, Call, AsOrigin: Get> SendXcm Ok((Xcm::::from(msg), Assets::new())) }, _ => { - log::trace!( + tracing::trace!( target: "xcm::execute::validate", "ImmediateExecutingXcmRouter unsupported destination: {dest:?}", ); @@ -186,7 +186,7 @@ impl, Call, AsOrigin: Get> SendXcm .ensure_complete() .map(|_| message_hash) .map_err(|e| { - log::trace!( + tracing::trace!( target: "xcm::execute::deliver", "XCM message from {:?} was dispatched with an error: {:?}", AsOrigin::get(), diff --git a/runtimes/bulletin-polkadot/tests/tests.rs b/runtimes/bulletin-polkadot/tests/tests.rs index 1d2606c19..81580a4fc 100644 --- a/runtimes/bulletin-polkadot/tests/tests.rs +++ b/runtimes/bulletin-polkadot/tests/tests.rs @@ -298,7 +298,7 @@ fn construct_and_apply_extrinsic( let dispatch_info = call.get_dispatch_info(); let xt = construct_extrinsic(account, call)?; let xt_len = xt.encode().len(); - log::info!( + tracing::info!( "Applying extrinsic: class={:?} pays_fee={:?} weight={:?} encoded_len={} bytes", dispatch_info.class, dispatch_info.pays_fee, @@ -344,7 +344,7 @@ fn transaction_storage_runtime_sizes() { // store data for (index, size) in sizes.into_iter().enumerate() { - log::info!("Storing data with size: {size} and index: {index}"); + tracing::info!("Storing data with size: {size} and index: {index}"); advance_block(); let res = construct_and_apply_extrinsic( account.pair(),