Skip to content

Commit 97531ec

Browse files
chore: improve tracing in network monitor
1 parent 53fa369 commit 97531ec

File tree

7 files changed

+201
-30
lines changed

7 files changed

+201
-30
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v0.12.3 (TBD)
4+
5+
- Improved tracing in `miden-network-monitor` binary ([#1366](https://github.com/0xMiden/miden-node/pull/1366)).
6+
37
## v0.12.2 (2025-11-12)
48

59
- Fixed `PoW` challenge solving in `miden-network-monitor` binary ([#1363](https://github.com/0xMiden/miden-node/pull/1363)).

bin/network-monitor/src/commands/start.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
use anyhow::Result;
66
use miden_node_utils::logging::OpenTelemetry;
7-
use tracing::{info, instrument, warn};
7+
use tracing::{debug, info, instrument, warn};
88

99
use crate::COMPONENT;
1010
use crate::config::MonitorConfig;
@@ -15,7 +15,16 @@ use crate::monitor::tasks::Tasks;
1515
///
1616
/// This function initializes all monitoring tasks including RPC status checking,
1717
/// remote prover testing, faucet testing, and the web frontend.
18-
#[instrument(target = COMPONENT, name = "start-monitor", skip_all, fields(port = %config.port))]
18+
#[instrument(
19+
parent = None,
20+
target = COMPONENT,
21+
name = "network_monitor.start_monitor",
22+
skip_all,
23+
level = "info",
24+
fields(port = %config.port),
25+
ret(level = "debug"),
26+
err
27+
)]
1928
pub async fn start_monitor(config: MonitorConfig) -> Result<()> {
2029
// Load configuration from command-line arguments and environment variables
2130
info!("Loaded configuration: {:?}", config);
@@ -27,19 +36,24 @@ pub async fn start_monitor(config: MonitorConfig) -> Result<()> {
2736
};
2837

2938
let mut tasks = Tasks::new();
39+
debug!(target: COMPONENT, "Initializing monitoring tasks");
3040

3141
// Initialize the RPC Status endpoint checker task.
42+
debug!(target: COMPONENT, "Initializing RPC status checker");
3243
let rpc_rx = tasks.spawn_rpc_checker(&config).await?;
3344

3445
// Initialize the prover checkers & tests tasks, only if URLs were provided.
3546
let prover_rxs = if config.remote_prover_urls.is_empty() {
47+
debug!(target: COMPONENT, "No remote prover URLs configured, skipping prover tasks");
3648
Vec::new()
3749
} else {
50+
debug!(target: COMPONENT, "Initializing prover checkers and tests");
3851
tasks.spawn_prover_tasks(&config).await?
3952
};
4053

4154
// Initialize the faucet testing task.
4255
let faucet_rx = if config.faucet_url.is_some() {
56+
debug!(target: COMPONENT, "Initializing faucet testing task");
4357
Some(tasks.spawn_faucet(&config))
4458
} else {
4559
warn!("Faucet URL not configured, skipping faucet testing");
@@ -48,12 +62,15 @@ pub async fn start_monitor(config: MonitorConfig) -> Result<()> {
4862

4963
// Initialize the counter increment task only if enabled.
5064
let ntx_service_rx = if config.disable_ntx_service {
65+
debug!(target: COMPONENT, "NTX service disabled, skipping counter increment task");
5166
None
5267
} else {
68+
debug!(target: COMPONENT, "Initializing counter increment task");
5369
Some(tasks.spawn_ntx_service(&config).await?)
5470
};
5571

5672
// Initialize HTTP server.
73+
debug!(target: COMPONENT, "Initializing HTTP server");
5774
let server_state = ServerState {
5875
rpc: rpc_rx,
5976
provers: prover_rxs,

bin/network-monitor/src/counter.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,15 @@ async fn setup_counter_increment(
241241
/// # Returns
242242
///
243243
/// This function runs indefinitely, only returning on error.
244-
#[instrument(target = COMPONENT, name = "run-ntx-service-task", skip_all, ret(level = "debug"))]
244+
#[instrument(
245+
parent = None,
246+
target = COMPONENT,
247+
name = "network_monitor.counter.run_ntx_service_task",
248+
skip_all,
249+
level = "info",
250+
ret(level = "debug"),
251+
err
252+
)]
245253
pub async fn run_ntx_service_task(
246254
config: MonitorConfig,
247255
tx: watch::Sender<ServiceStatus>,
@@ -388,7 +396,15 @@ fn load_counter_account(file_path: &Path) -> Result<Account> {
388396

389397
/// Create and submit a network note that targets the counter account.
390398
#[allow(clippy::too_many_arguments)]
391-
#[instrument(target = COMPONENT, name = "create-and-submit-network-note", skip_all, ret)]
399+
#[instrument(
400+
parent = None,
401+
target = COMPONENT,
402+
name = "network_monitor.counter.create_and_submit_network_note",
403+
skip_all,
404+
level = "info",
405+
ret(level = "debug"),
406+
err
407+
)]
392408
async fn create_and_submit_network_note(
393409
wallet_account: &Account,
394410
counter_account: &Account,

bin/network-monitor/src/faucet.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@ struct GetTokensResponse {
7575
/// # Returns
7676
///
7777
/// `Ok(())` if the task completes successfully, or an error if the task fails.
78-
#[instrument(target = COMPONENT, name = "faucet-test-task", skip_all)]
78+
#[instrument(
79+
parent = None,
80+
target = COMPONENT,
81+
name = "network_monitor.faucet.run_faucet_test_task",
82+
skip_all,
83+
level = "info",
84+
ret(level = "debug")
85+
)]
7986
pub async fn run_faucet_test_task(
8087
faucet_url: Url,
8188
status_sender: watch::Sender<ServiceStatus>,
@@ -150,6 +157,15 @@ pub async fn run_faucet_test_task(
150157
/// # Returns
151158
///
152159
/// The response from the faucet if successful, or an error if the test fails.
160+
#[instrument(
161+
parent = None,
162+
target = COMPONENT,
163+
name = "network_monitor.faucet.perform_faucet_test",
164+
skip_all,
165+
level = "info",
166+
ret(level = "debug"),
167+
err
168+
)]
153169
async fn perform_faucet_test(
154170
client: &Client,
155171
faucet_url: &Url,
@@ -221,7 +237,15 @@ async fn perform_faucet_test(
221237
///
222238
/// The nonce that solves the challenge, or an error if no solution is found within reasonable
223239
/// bounds.
224-
#[instrument(target = COMPONENT, name = "solve-pow-challenge", skip_all, ret(level = "debug"))]
240+
#[instrument(
241+
parent = None,
242+
target = COMPONENT,
243+
name = "network_monitor.faucet.solve_pow_challenge",
244+
skip_all,
245+
level = "info",
246+
ret(level = "debug"),
247+
err
248+
)]
225249
fn solve_pow_challenge(challenge: &str, target: u64) -> anyhow::Result<u64> {
226250
let challenge_bytes = hex::decode(challenge).context("Failed to decode challenge from hex")?;
227251

bin/network-monitor/src/monitor/tasks.rs

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,21 @@ impl Tasks {
4242
}
4343

4444
/// Spawn the RPC status checker task.
45-
#[instrument(target = COMPONENT, name = "tasks.spawn-rpc-checker", skip_all)]
45+
#[instrument(
46+
parent = None,
47+
target = COMPONENT,
48+
name = "network_monitor.tasks.spawn_rpc_checker",
49+
skip_all,
50+
level = "info",
51+
ret(level = "debug"),
52+
err
53+
)]
4654
pub async fn spawn_rpc_checker(
4755
&mut self,
4856
config: &MonitorConfig,
4957
) -> Result<Receiver<ServiceStatus>> {
58+
debug!(target: COMPONENT, rpc_url = %config.rpc_url, "Spawning RPC status checker task");
59+
5060
// Create initial status for RPC service
5161
let mut rpc = ClientBuilder::new(config.rpc_url.clone())
5262
.with_tls()
@@ -71,15 +81,25 @@ impl Tasks {
7181
.id();
7282
self.names.insert(id, "rpc-checker".to_string());
7383

84+
debug!(target: COMPONENT, "RPC status checker task spawned successfully");
7485
Ok(rpc_rx)
7586
}
7687

7788
/// Spawn prover status and test tasks for all configured provers.
78-
#[instrument(target = COMPONENT, name = "tasks.spawn-prover-tasks", skip_all)]
89+
#[instrument(
90+
parent = None,
91+
target = COMPONENT,
92+
name = "network_monitor.tasks.spawn_prover_tasks",
93+
skip_all,
94+
level = "info",
95+
ret(level = "debug"),
96+
err
97+
)]
7998
pub async fn spawn_prover_tasks(
8099
&mut self,
81100
config: &MonitorConfig,
82101
) -> Result<Vec<(watch::Receiver<ServiceStatus>, watch::Receiver<ServiceStatus>)>> {
102+
debug!(target: COMPONENT, prover_count = config.remote_prover_urls.len(), "Spawning prover tasks");
83103
let mut prover_rxs = Vec::new();
84104

85105
for (i, prover_url) in config.remote_prover_urls.iter().enumerate() {
@@ -181,11 +201,19 @@ impl Tasks {
181201
prover_rxs.push((prover_status_rx, prover_test_rx));
182202
}
183203

204+
debug!(target: COMPONENT, spawned_provers = prover_rxs.len(), "All prover tasks spawned successfully");
184205
Ok(prover_rxs)
185206
}
186207

187208
/// Spawn the faucet testing task.
188-
#[instrument(target = COMPONENT, name = "tasks.spawn-faucet", skip_all)]
209+
#[instrument(
210+
parent = None,
211+
target = COMPONENT,
212+
name = "network_monitor.tasks.spawn_faucet",
213+
skip_all,
214+
level = "info",
215+
ret(level = "debug")
216+
)]
189217
pub fn spawn_faucet(&mut self, config: &MonitorConfig) -> Receiver<ServiceStatus> {
190218
let current_time = current_unix_timestamp_secs();
191219

@@ -221,7 +249,15 @@ impl Tasks {
221249
}
222250

223251
/// Spawn the network transaction service checker task.
224-
#[instrument(target = COMPONENT, name = "tasks.spawn-ntx-service", skip_all)]
252+
#[instrument(
253+
parent = None,
254+
target = COMPONENT,
255+
name = "network_monitor.tasks.spawn_ntx_service",
256+
skip_all,
257+
level = "info",
258+
ret(level = "debug"),
259+
err
260+
)]
225261
pub async fn spawn_ntx_service(
226262
&mut self,
227263
config: &MonitorConfig,
@@ -265,7 +301,14 @@ impl Tasks {
265301
}
266302

267303
/// Spawn the HTTP frontend server.
268-
#[instrument(target = COMPONENT, name = "tasks.spawn-frontend", skip_all)]
304+
#[instrument(
305+
parent = None,
306+
target = COMPONENT,
307+
name = "network_monitor.tasks.spawn_http_server",
308+
skip_all,
309+
level = "info",
310+
ret(level = "debug")
311+
)]
269312
pub fn spawn_http_server(&mut self, server_state: ServerState, config: &MonitorConfig) {
270313
let config = config.clone();
271314
let id = self.handles.spawn(async move { serve(server_state, config).await }).id();

bin/network-monitor/src/remote_prover.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,14 @@ pub struct ProverTestDetails {
8787
/// # Returns
8888
///
8989
/// `Ok(())` if the task completes successfully, or an error if the task fails.
90-
#[instrument(target = COMPONENT, name = "remote-prover-test-task", skip_all)]
90+
#[instrument(
91+
parent = None,
92+
target = COMPONENT,
93+
name = "network_monitor.remote_prover.run_remote_prover_test_task",
94+
skip_all,
95+
level = "info",
96+
ret(level = "debug")
97+
)]
9198
pub async fn run_remote_prover_test_task(
9299
prover_url: Url,
93100
name: &str,
@@ -151,7 +158,14 @@ pub async fn run_remote_prover_test_task(
151158
/// # Returns
152159
///
153160
/// A `ServiceStatus` containing the results of the proof test.
154-
#[instrument(target = COMPONENT, name = "test-remote-prover", skip_all, ret(level = "info"))]
161+
#[instrument(
162+
parent = None,
163+
target = COMPONENT,
164+
name = "network_monitor.remote_prover.test_remote_prover",
165+
skip_all,
166+
level = "info",
167+
ret(level = "debug")
168+
)]
155169
async fn test_remote_prover(
156170
client: &mut miden_node_proto::clients::RemoteProverClient,
157171
name: &str,
@@ -254,6 +268,15 @@ fn tonic_status_to_json(status: &tonic::Status) -> String {
254268
/// This function creates a mock transaction using `MockChainBuilder` similar to what's done
255269
/// in the remote prover tests. The transaction is generated once and can be reused for
256270
/// multiple proof test calls.
271+
#[instrument(
272+
parent = None,
273+
target = COMPONENT,
274+
name = "network_monitor.remote_prover.generate_mock_transaction",
275+
skip_all,
276+
level = "info",
277+
ret(level = "debug"),
278+
err
279+
)]
257280
pub async fn generate_mock_transaction() -> anyhow::Result<TransactionInputs> {
258281
let mut mock_chain_builder = MockChainBuilder::new();
259282

@@ -301,6 +324,14 @@ pub async fn generate_mock_transaction() -> anyhow::Result<TransactionInputs> {
301324
// GENERATE TEST REQUEST PAYLOAD
302325
// ================================================================================================
303326

327+
#[instrument(
328+
parent = None,
329+
target = COMPONENT,
330+
name = "network_monitor.remote_prover.generate_prover_test_payload",
331+
skip_all,
332+
level = "info",
333+
ret(level = "debug")
334+
)]
304335
pub(crate) async fn generate_prover_test_payload() -> proto::remote_prover::ProofRequest {
305336
proto::remote_prover::ProofRequest {
306337
proof_type: proto::remote_prover::ProofType::Transaction.into(),

0 commit comments

Comments
 (0)