diff --git a/bin/network-monitor/src/deploy/mod.rs b/bin/network-monitor/src/deploy/mod.rs index b0ca119137..34d1696813 100644 --- a/bin/network-monitor/src/deploy/mod.rs +++ b/bin/network-monitor/src/deploy/mod.rs @@ -303,7 +303,7 @@ pub async fn create_genesis_aware_rpc_client( err, target: COMPONENT, "RPC genesis discovery failed; retrying after backoff", - retry.delay_ms = sleep.as_millis() as u64 + retry.delay_ms = sleep ); }) .await diff --git a/bin/network-monitor/src/monitor/tasks.rs b/bin/network-monitor/src/monitor/tasks.rs index 92fc4d2256..bcf72d724c 100644 --- a/bin/network-monitor/src/monitor/tasks.rs +++ b/bin/network-monitor/src/monitor/tasks.rs @@ -241,7 +241,7 @@ async fn run_ntx( err, target: LOG_TARGET, "NTX bootstrap failed; retrying after backoff", - retry.delay_ms = sleep.as_millis() as u64 + retry.delay_ms = sleep ); publish_unhealthy(err); }) diff --git a/bin/ntx-builder/src/actor/execute.rs b/bin/ntx-builder/src/actor/execute.rs index 0d3bce04f7..380f812a1c 100644 --- a/bin/ntx-builder/src/actor/execute.rs +++ b/bin/ntx-builder/src/actor/execute.rs @@ -134,7 +134,7 @@ fn log_transient_retry(operation: &'static str, err: &E, s target: COMPONENT, "ntx transient request failure; retrying after backoff", operation.name = operation, - retry.delay_ms = sleep.as_millis() as u64 + retry.delay_ms = sleep ); } diff --git a/bin/ntx-builder/src/clients/rpc.rs b/bin/ntx-builder/src/clients/rpc.rs index 494c992bb9..ba46955b6d 100644 --- a/bin/ntx-builder/src/clients/rpc.rs +++ b/bin/ntx-builder/src/clients/rpc.rs @@ -228,7 +228,7 @@ impl RpcClient { err, target: COMPONENT, "RPC connection failed while opening block subscription, retrying", - retry.delay_ms = dur.as_millis() as u64 + retry.delay_ms = dur ); }) .await diff --git a/crates/block-producer/src/rpc_sync.rs b/crates/block-producer/src/rpc_sync.rs index 18fdd966fc..29d9440d9a 100644 --- a/crates/block-producer/src/rpc_sync.rs +++ b/crates/block-producer/src/rpc_sync.rs @@ -188,7 +188,7 @@ impl BlockSync { err, target: LOG_TARGET, "Block sync failed, retrying", - retry.delay_ms = RECONNECT_DELAY.as_millis() as u64 + retry.delay_ms = RECONNECT_DELAY ); }); @@ -287,7 +287,7 @@ impl ProofSync { err, target: LOG_TARGET, "Proof sync failed, retrying", - retry.delay_ms = RECONNECT_DELAY.as_millis() as u64 + retry.delay_ms = RECONNECT_DELAY ); }); diff --git a/crates/proto/src/clients/mod.rs b/crates/proto/src/clients/mod.rs index 2578c0b5bb..7a828073ba 100644 --- a/crates/proto/src/clients/mod.rs +++ b/crates/proto/src/clients/mod.rs @@ -589,7 +589,7 @@ impl Builder { "Configured service connection timed out", dependency.name = dependency_name, dependency.endpoint = endpoint.as_str(), - timeout.ms = CONNECT_TIMEOUT.as_millis() as u64 + timeout.ms = CONNECT_TIMEOUT ); }, Ok(Err(err)) => { @@ -605,7 +605,7 @@ impl Builder { "Configured service connection still timing out", dependency.name = dependency_name, dependency.endpoint = endpoint.as_str(), - timeout.ms = CONNECT_TIMEOUT.as_millis() as u64 + timeout.ms = CONNECT_TIMEOUT ); }, } diff --git a/crates/rpc/src/server/api.rs b/crates/rpc/src/server/api.rs index 1fad01cf04..16019cb1a0 100644 --- a/crates/rpc/src/server/api.rs +++ b/crates/rpc/src/server/api.rs @@ -177,7 +177,7 @@ impl RpcService { err, target: LOG_TARGET, "connection failed while fetching genesis header, retrying", - retry.delay_ms = backoff.as_millis() as u64 + retry.delay_ms = backoff ); }) .await?; diff --git a/crates/store/src/state/writer/worker.rs b/crates/store/src/state/writer/worker.rs index 92296de301..4918972da2 100644 --- a/crates/store/src/state/writer/worker.rs +++ b/crates/store/src/state/writer/worker.rs @@ -226,12 +226,12 @@ impl WriteWorker { let snapshot_lag = generations .oldest_pinned .map_or(0, |oldest| block_num.as_u32() - oldest.as_u32()); - let oldest_superseded_for_ms = generations - .oldest_superseded_for - .map_or(0, |superseded| u64::try_from(superseded.as_millis()).unwrap_or(u64::MAX)); + // `unwrap_or_default` keeps the field present with a zero value when the oldest pinned + // generation is not superseded; a `None` value would omit the field from the span. miden_span_record!( snapshots.lag_blocks = snapshot_lag, - snapshots.oldest_superseded_for_ms = oldest_superseded_for_ms + snapshots.oldest_superseded_for_ms = + generations.oldest_superseded_for.unwrap_or_default() ); let prune_tip = generations.prune_tip; let resolved_note_ids = self diff --git a/crates/tracing/src/attribute.rs b/crates/tracing/src/attribute.rs index 03d5ca5ec0..53f49c88fa 100644 --- a/crates/tracing/src/attribute.rs +++ b/crates/tracing/src/attribute.rs @@ -1,5 +1,6 @@ use std::fmt::{self, Display, Formatter}; use std::path::{Path, PathBuf}; +use std::time::Duration; use miden_protocol::Word; use miden_protocol::account::{AccountId, AccountIdPrefix, StorageMapKey, StorageSlotName}; @@ -74,18 +75,14 @@ const NUMBER_FIELD_NAMES: &[&str] = &[ "prover.proof_type.raw", "reference_block.number", "retry.attempt", - "retry.delay_ms", - "shutdown.grace_period_ms", "snapshot.block_num", "snapshots.lag_blocks", "snapshots.live", - "snapshots.oldest_superseded_for_ms", "subscription.idle_ms", "subscription.stall_timeout_ms", "sync.block_gap", "sync.ready_threshold", "sync.upstream_block", - "timeout.ms", "tip.number", "tip.stale_duration_secs", "transaction.expiration_delta", @@ -261,6 +258,22 @@ impl_scalar_attribute!( ); impl_scalar_attribute!(NUMBER_FIELD_NAMES; u32); +/// Durations are recorded as whole milliseconds in a `u64`, saturating at `u64::MAX`. +/// +/// Every allowed field name ends with `ms` so the recorded unit is visible on the query side. +impl RecordAttribute for Duration { + const FIELD_NAMES: &'static [&'static str] = &[ + "retry.delay_ms", + "shutdown.grace_period_ms", + "snapshots.oldest_superseded_for_ms", + "timeout.ms", + ]; + + fn record_attribute(&self) -> impl Value + '_ { + u64::try_from(self.as_millis()).unwrap_or(u64::MAX) + } +} + impl RecordAttribute for str { const FIELD_NAMES: &'static [&'static str] = STRING_FIELD_NAMES; diff --git a/crates/tracing/tests/ui/tracing_macros/invalid_event_attribute.stderr b/crates/tracing/tests/ui/tracing_macros/invalid_event_attribute.stderr index f4afd5017e..69f007a5a1 100644 --- a/crates/tracing/tests/ui/tracing_macros/invalid_event_attribute.stderr +++ b/crates/tracing/tests/ui/tracing_macros/invalid_event_attribute.stderr @@ -11,13 +11,13 @@ help: the trait `RecordAttribute` is not implemented for `UnapprovedAttribute` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: the following other types implement trait `RecordAttribute`: &T + Duration Option Path PathBuf String Vec [T; N] - [T] and $N others note: required by a bound in `main::__miden_assert_field_name` --> tests/ui/tracing_macros/invalid_event_attribute.rs:6:5 diff --git a/crates/tracing/tests/ui/tracing_macros/invalid_instrument_attribute.stderr b/crates/tracing/tests/ui/tracing_macros/invalid_instrument_attribute.stderr index 9c1ba8a286..a38e7caf29 100644 --- a/crates/tracing/tests/ui/tracing_macros/invalid_instrument_attribute.stderr +++ b/crates/tracing/tests/ui/tracing_macros/invalid_instrument_attribute.stderr @@ -11,13 +11,13 @@ help: the trait `RecordAttribute` is not implemented for `UnapprovedAttribute` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: the following other types implement trait `RecordAttribute`: &T + Duration Option Path PathBuf String Vec [T; N] - [T] and $N others note: required by a bound in `records_unapproved_attribute::__miden_assert_field_name` --> tests/ui/tracing_macros/invalid_instrument_attribute.rs:5:1 diff --git a/crates/tracing/tests/ui/tracing_macros/invalid_nonstandard_attribute.stderr b/crates/tracing/tests/ui/tracing_macros/invalid_nonstandard_attribute.stderr index 710b74c85f..077ae990e1 100644 --- a/crates/tracing/tests/ui/tracing_macros/invalid_nonstandard_attribute.stderr +++ b/crates/tracing/tests/ui/tracing_macros/invalid_nonstandard_attribute.stderr @@ -11,13 +11,13 @@ help: the trait `RecordAttribute` is not implemented for `UnapprovedAttribute` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: the following other types implement trait `RecordAttribute`: &T + Duration Option Path PathBuf String Vec [T; N] - [T] and $N others note: required by a bound in `miden_node_tracing::record_attribute` --> src/attribute.rs diff --git a/crates/tracing/tests/ui/tracing_macros/invalid_record_attribute.stderr b/crates/tracing/tests/ui/tracing_macros/invalid_record_attribute.stderr index 1037be95a3..0c5cdac15f 100644 --- a/crates/tracing/tests/ui/tracing_macros/invalid_record_attribute.stderr +++ b/crates/tracing/tests/ui/tracing_macros/invalid_record_attribute.stderr @@ -11,13 +11,13 @@ help: the trait `RecordAttribute` is not implemented for `UnapprovedAttribute` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: the following other types implement trait `RecordAttribute`: &T + Duration Option Path PathBuf String Vec [T; N] - [T] and $N others note: required by a bound in `__miden_assert_field_name` --> tests/ui/tracing_macros/invalid_record_attribute.rs:7:5 diff --git a/crates/utils/src/retry.rs b/crates/utils/src/retry.rs index bd573d700b..58ca098a62 100644 --- a/crates/utils/src/retry.rs +++ b/crates/utils/src/retry.rs @@ -15,7 +15,7 @@ //! warn!( //! err, //! "retrying", -//! retry.delay_ms = dur.as_millis() as u64 +//! retry.delay_ms = dur //! ); //! }) //! .await?; diff --git a/crates/utils/src/shutdown.rs b/crates/utils/src/shutdown.rs index 0edbb0021d..ecec350407 100644 --- a/crates/utils/src/shutdown.rs +++ b/crates/utils/src/shutdown.rs @@ -69,7 +69,7 @@ where anyhow::anyhow!("graceful shutdown timed out"), "Graceful shutdown timed out; exiting process", service.name = service_name, - shutdown.grace_period_ms = GRACE_PERIOD.as_millis() as u64 + shutdown.grace_period_ms = GRACE_PERIOD ); std::process::exit(1); };