Skip to content

Commit d0cd74a

Browse files
committed
feat(logging): instrument spawned task with current span
1 parent 0128218 commit d0cd74a

File tree

15 files changed

+39
-25
lines changed

15 files changed

+39
-25
lines changed

ant-networking/src/cmd.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use std::{
3535
time::Duration,
3636
};
3737
use tokio::sync::oneshot;
38+
use tracing::Instrument;
3839
use xor_name::XorName;
3940

4041
const MAX_CONTINUOUS_HDD_WRITE_ERROR: usize = 5;
@@ -975,7 +976,7 @@ impl SwarmDriver {
975976
error!("Failed to get response from one shot channel for Cmd::PeerConsideredAsBad : {err:?}");
976977
}
977978
}
978-
});
979+
}.instrument(tracing::Span::current()));
979980

980981
// request
981982
let request = Request::Cmd(Cmd::PeerConsideredAsBad {

ant-networking/src/driver.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use std::{
4848
};
4949
use tokio::sync::{mpsc, oneshot, watch};
5050
use tokio::time::Duration;
51+
use tracing::Instrument;
5152
use tracing::warn;
5253

5354
/// 10 is the max number of issues per node we track to avoid mem leaks
@@ -366,7 +367,7 @@ impl SwarmDriver {
366367
if let Err(err) = old_cache.sync_and_flush_to_disk() {
367368
error!("Failed to save bootstrap cache: {err}");
368369
}
369-
});
370+
}.instrument(tracing::Span::current()));
370371

371372
if current_interval.period() >= bootstrap_cache.config().max_cache_save_duration {
372373
continue;
@@ -412,7 +413,7 @@ impl SwarmDriver {
412413
if let Err(error) = event_sender.send(event).await {
413414
error!("SwarmDriver failed to send event: {}", error);
414415
}
415-
});
416+
}.instrument(tracing::Span::current()));
416417
}
417418

418419
/// Sends an event after pushing it off thread so as to be non-blocking
@@ -432,7 +433,7 @@ impl SwarmDriver {
432433
if let Err(error) = event_sender.send(event).await {
433434
error!("SwarmDriver failed to send event: {}", error);
434435
}
435-
});
436+
}.instrument(tracing::Span::current()));
436437
}
437438

438439
/// Get K closest peers to self, from our local RoutingTable.

ant-networking/src/event/kad.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::{
1212
};
1313
use libp2p::kad::{self, GetClosestPeersError, InboundRequest, QueryResult, K_VALUE};
1414
use std::collections::hash_map::Entry;
15+
use tracing::Instrument;
1516

1617
impl SwarmDriver {
1718
pub(super) fn handle_kad_event(&mut self, kad_event: libp2p::kad::Event) -> Result<()> {
@@ -104,7 +105,7 @@ impl SwarmDriver {
104105
PendingGetClosestType::FunctionCall(sender) => {
105106
tokio::spawn(async move {
106107
let _ = sender.send(vec![]);
107-
});
108+
}.instrument(tracing::Span::current()));
108109
}
109110
}
110111
}

ant-networking/src/event/swarm.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use libp2p::{
2424
Multiaddr, TransportError,
2525
};
2626
use tokio::time::Duration;
27+
use tracing::Instrument;
2728

2829
impl SwarmDriver {
2930
/// Handle `SwarmEvents`
@@ -192,7 +193,7 @@ impl SwarmDriver {
192193
if let Err(err) = old_cache.sync_and_flush_to_disk() {
193194
error!("Failed to save bootstrap cache: {err}");
194195
}
195-
});
196+
}.instrument(tracing::Span::current()));
196197
}
197198
}
198199
} else if let Some(external_add_manager) =

ant-networking/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ use tokio::sync::{
7171
mpsc::{self, Sender},
7272
oneshot,
7373
};
74+
use tracing::Instrument;
7475

7576
/// Majority of a given group (i.e. > 1/2).
7677
#[inline]
@@ -694,7 +695,7 @@ pub(crate) fn send_local_swarm_cmd(swarm_cmd_sender: Sender<LocalSwarmCmd>, cmd:
694695
if let Err(error) = swarm_cmd_sender.send(cmd).await {
695696
error!("Failed to send SwarmCmd: {}", error);
696697
}
697-
});
698+
}.instrument(tracing::Span::current()));
698699
}
699700

700701
pub(crate) fn send_network_swarm_cmd(
@@ -715,5 +716,5 @@ pub(crate) fn send_network_swarm_cmd(
715716
if let Err(error) = swarm_cmd_sender.send(cmd).await {
716717
error!("Failed to send SwarmCmd: {}", error);
717718
}
718-
});
719+
}.instrument(tracing::Span::current()));
719720
}

ant-networking/src/metrics/bad_node.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use std::{
1818
time::{Duration, Instant},
1919
};
2020
use strum::IntoEnumIterator;
21+
use tracing::Instrument;
2122

2223
const UPDATE_INTERVAL: Duration = Duration::from_secs(20);
2324

@@ -158,7 +159,7 @@ impl BadNodeMetrics {
158159
}
159160
}
160161
}
161-
});
162+
}.instrument(tracing::Span::current()));
162163
tx
163164
}
164165
}

ant-networking/src/metrics/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use std::collections::HashMap;
2727
use std::sync::atomic::AtomicU64;
2828
use sysinfo::{Pid, ProcessRefreshKind, System};
2929
use tokio::time::Duration;
30+
use tracing::Instrument;
3031

3132
const UPDATE_INTERVAL: Duration = Duration::from_secs(60);
3233
const TO_MB: u64 = 1_000_000;
@@ -319,7 +320,7 @@ impl NetworkMetricsRecorder {
319320
}
320321
sleep(UPDATE_INTERVAL).await;
321322
}
322-
});
323+
}.instrument(tracing::Span::current()));
323324
}
324325

325326
// Records the metric
@@ -339,7 +340,7 @@ impl NetworkMetricsRecorder {
339340
{
340341
error!("Failed to send shunned report via notifier: {err:?}");
341342
}
342-
});
343+
}.instrument(tracing::Span::current()));
343344
}
344345
Marker::QuotingMetrics { quoting_metrics } => {
345346
let _ = self.relevant_records.set(
@@ -370,7 +371,7 @@ impl NetworkMetricsRecorder {
370371
{
371372
error!("Failed to send shunned report via notifier: {err:?}");
372373
}
373-
});
374+
}.instrument(tracing::Span::current()));
374375
}
375376

376377
pub(crate) fn update_node_versions(&self, versions: &HashMap<PeerId, String>) {

ant-networking/src/metrics/service.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::{
1515
sync::{Arc, Mutex},
1616
task::{Context, Poll},
1717
};
18+
use tracing::Instrument;
1819

1920
/// The types of metrics that are exposed via the various endpoints.
2021
#[derive(Default, Debug)]
@@ -41,7 +42,7 @@ pub(crate) fn run_metrics_server(registries: MetricsRegistries, port: u16) {
4142
if let Err(e) = server.await {
4243
error!("server error: {}", e);
4344
}
44-
});
45+
}.instrument(tracing::Span::current()));
4546
}
4647

4748
type SharedRegistry = Arc<Mutex<Registry>>;

ant-networking/src/record_store.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use std::{
4444
vec,
4545
};
4646
use tokio::{sync::mpsc, time::Duration};
47+
use tracing::Instrument;
4748
use walkdir::{DirEntry, WalkDir};
4849
use xor_name::XorName;
4950

@@ -358,7 +359,7 @@ impl NodeRecordStore {
358359
let mut serialiser = rmp_serde::encode::Serializer::new(&mut file);
359360
let _ = historic_quoting_metrics.serialize(&mut serialiser);
360361
}
361-
});
362+
}.instrument(tracing::Span::current()));
362363
}
363364

364365
/// Creates a new `DiskBackedStore` with the given configuration.
@@ -750,7 +751,7 @@ impl NodeRecordStore {
750751

751752
send_local_swarm_cmd(cloned_cmd_sender, cmd);
752753
}
753-
});
754+
}.instrument(tracing::Span::current()));
754755

755756
Ok(())
756757
}
@@ -925,7 +926,7 @@ impl RecordStore for NodeRecordStore {
925926
{
926927
error!("SwarmDriver failed to send event: {}", error);
927928
}
928-
});
929+
}.instrument(tracing::Span::current()));
929930

930931
Ok(())
931932
}
@@ -962,7 +963,7 @@ impl RecordStore for NodeRecordStore {
962963
error!("Error while removing file. filename: {filename}, error: {err:?}");
963964
}
964965
}
965-
});
966+
}.instrument(tracing::Span::current()));
966967
}
967968

968969
fn records(&self) -> Self::RecordsIter<'_> {

ant-networking/src/replication_fetcher.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use libp2p::{
1919
};
2020
use std::collections::{hash_map::Entry, BTreeMap, HashMap, HashSet, VecDeque};
2121
use tokio::{sync::mpsc, time::Duration};
22+
use tracing::Instrument;
2223

2324
// Max parallel fetches that can be undertaken at the same time.
2425
const MAX_PARALLEL_FETCH: usize = 5;
@@ -589,7 +590,7 @@ impl ReplicationFetcher {
589590
if let Err(error) = event_sender.send(event).await {
590591
error!("ReplicationFetcher failed to send event: {}", error);
591592
}
592-
});
593+
}.instrument(tracing::Span::current()));
593594
}
594595
}
595596

0 commit comments

Comments
 (0)