From 393ae2f94dabd9e653ad4620e20ab13d4d1fd1dc Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Tue, 1 Aug 2023 22:29:53 +0300 Subject: [PATCH 001/105] feaat:tracing --- Cargo.lock | 18 ++++++++++++++++++ examples/dcutr/src/main.rs | 4 ++-- examples/ping-example/Cargo.toml | 2 ++ examples/ping-example/src/main.rs | 9 +++++++++ protocols/ping/Cargo.toml | 1 + protocols/ping/src/handler.rs | 8 ++++---- swarm/Cargo.toml | 2 ++ swarm/src/connection.rs | 6 ++++++ swarm/src/connection/pool.rs | 6 ++++++ 9 files changed, 50 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b2fb6e87074..2810815e8db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2996,6 +2996,7 @@ dependencies = [ "log", "quickcheck-ext", "rand 0.8.5", + "tracing", "void", ] @@ -3176,6 +3177,8 @@ dependencies = [ "rand 0.8.5", "smallvec", "tokio", + "tracing", + "tracing-subscriber", "trybuild", "void", "wasm-bindgen-futures", @@ -4062,6 +4065,8 @@ dependencies = [ "async-trait", "futures", "libp2p", + "tracing", + "tracing-subscriber", ] [[package]] @@ -5755,6 +5760,16 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-serde" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" +dependencies = [ + "serde", + "tracing-core", +] + [[package]] name = "tracing-subscriber" version = "0.3.17" @@ -5765,12 +5780,15 @@ dependencies = [ "nu-ansi-term", "once_cell", "regex", + "serde", + "serde_json", "sharded-slab", "smallvec", "thread_local", "tracing", "tracing-core", "tracing-log", + "tracing-serde", ] [[package]] diff --git a/examples/dcutr/src/main.rs b/examples/dcutr/src/main.rs index 8359bb1902a..5537346eecf 100644 --- a/examples/dcutr/src/main.rs +++ b/examples/dcutr/src/main.rs @@ -172,10 +172,10 @@ fn main() -> Result<(), Box> { .build(); swarm - .listen_on("/ip4/0.0.0.0/udp/0/quic-v1".parse().unwrap()) + .listen_on("/ip4/0.0.0.0/udp/4001/quic-v1".parse().unwrap()) .unwrap(); swarm - .listen_on("/ip4/0.0.0.0/tcp/0".parse().unwrap()) + .listen_on("/ip6/::/udp/4001/quic-v1".parse().unwrap()) .unwrap(); // Wait to listen on all interfaces. diff --git a/examples/ping-example/Cargo.toml b/examples/ping-example/Cargo.toml index f1022b2dcd3..e72391f65da 100644 --- a/examples/ping-example/Cargo.toml +++ b/examples/ping-example/Cargo.toml @@ -10,3 +10,5 @@ async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "macros", "noise", "ping", "tcp", "websocket", "yamux"] } +tracing = { version = "0.1.37", features = ["log"] } +tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] } \ No newline at end of file diff --git a/examples/ping-example/src/main.rs b/examples/ping-example/src/main.rs index 6b993bcb6e3..c72d837cc6e 100644 --- a/examples/ping-example/src/main.rs +++ b/examples/ping-example/src/main.rs @@ -27,10 +27,19 @@ use libp2p::{ swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent}, tcp, yamux, Multiaddr, PeerId, Transport, }; +use tracing::level_filters::LevelFilter; +use tracing_subscriber::EnvFilter; use std::error::Error; #[async_std::main] async fn main() -> Result<(), Box> { + + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::DEBUG.into()) + .from_env_lossy(); + + tracing_subscriber::fmt().with_env_filter(env_filter).init(); + let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); println!("Local peer id: {local_peer_id:?}"); diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index aebc473512b..87e1e150b01 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -21,6 +21,7 @@ libp2p-identity = { workspace = true } log = "0.4.19" rand = "0.8" void = "1.0" +tracing = "0.1.37" [dev-dependencies] async-std = "1.6.2" diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index 0cf5c6e5f07..e1ec97b015c 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -258,11 +258,11 @@ impl ConnectionHandler for Handler { match fut.poll_unpin(cx) { Poll::Pending => {} Poll::Ready(Err(e)) => { - log::debug!("Inbound ping error: {:?}", e); + tracing::debug!("Inbound ping error: {:?}", e); self.inbound = None; } Poll::Ready(Ok(stream)) => { - log::trace!("answered inbound ping from {}", self.peer); + tracing::trace!("answered inbound ping from {}", self.peer); // A ping from a remote peer has been answered, wait for the next. self.inbound = Some(protocol::recv_ping(stream).boxed()); @@ -273,7 +273,7 @@ impl ConnectionHandler for Handler { loop { // Check for outbound ping failures. if let Some(error) = self.pending_errors.pop_back() { - log::debug!("Ping failure: {:?}", error); + tracing::debug!("Ping failure: {:?}", error); self.failures += 1; @@ -295,7 +295,7 @@ impl ConnectionHandler for Handler { break; } Poll::Ready(Ok((stream, rtt))) => { - log::debug!("latency to {} is {}ms", self.peer, rtt.as_millis()); + tracing::debug!("latency to {} is {}ms", self.peer, rtt.as_millis()); self.failures = 0; self.interval.reset(self.config.interval); diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 752491cda7e..340cb56f713 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -31,6 +31,8 @@ multistream-select = { workspace = true } [target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies] async-std = { version = "1.6.2", optional = true } tokio = { version = "1.29", features = ["rt"], optional = true } +tracing = "0.1.37" +tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] } [features] macros = ["dep:libp2p-swarm-derive"] diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 6646967f590..6fcdf457f5c 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -82,6 +82,12 @@ impl ConnectionId { } } +impl fmt::Display for ConnectionId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.0) + } +} + /// Information about a successfully established connection. #[derive(Debug, Clone, PartialEq, Eq)] pub(crate) struct Connected { diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index e9f7504f529..4ca043e949f 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -307,6 +307,8 @@ where { /// Creates a new empty `Pool`. pub(crate) fn new(local_id: PeerId, config: PoolConfig) -> Self { + let span = tracing::error_span!("peer id:", %local_id, connection_id = tracing::field::Empty); + let _guard = span.enter(); let (pending_connection_events_tx, pending_connection_events_rx) = mpsc::channel(0); let executor = match config.executor { Some(exec) => ExecSwitch::Executor(exec), @@ -495,6 +497,10 @@ where ) { let connection = connection.extract(); + let span = tracing::error_span!("peer id:", %obtained_peer_id, connection_id = tracing::field::Empty); + let _guard = span.enter(); + span.record("connection id", tracing::field::display(id)); + let conns = self.established.entry(obtained_peer_id).or_default(); self.counters.inc_established(endpoint); From b3f055a7f8a1839f72d2f1f77556b2be12aa18cd Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 3 Aug 2023 20:03:06 +0300 Subject: [PATCH 002/105] move error span --- examples/dcutr/src/main.rs | 4 ++-- examples/ping-example/src/main.rs | 3 +-- protocols/ping/src/handler.rs | 7 +++---- swarm/src/connection.rs | 16 ++++++++++++++-- swarm/src/connection/pool.rs | 11 +++-------- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/examples/dcutr/src/main.rs b/examples/dcutr/src/main.rs index 5537346eecf..8359bb1902a 100644 --- a/examples/dcutr/src/main.rs +++ b/examples/dcutr/src/main.rs @@ -172,10 +172,10 @@ fn main() -> Result<(), Box> { .build(); swarm - .listen_on("/ip4/0.0.0.0/udp/4001/quic-v1".parse().unwrap()) + .listen_on("/ip4/0.0.0.0/udp/0/quic-v1".parse().unwrap()) .unwrap(); swarm - .listen_on("/ip6/::/udp/4001/quic-v1".parse().unwrap()) + .listen_on("/ip4/0.0.0.0/tcp/0".parse().unwrap()) .unwrap(); // Wait to listen on all interfaces. diff --git a/examples/ping-example/src/main.rs b/examples/ping-example/src/main.rs index c72d837cc6e..f484bf646b9 100644 --- a/examples/ping-example/src/main.rs +++ b/examples/ping-example/src/main.rs @@ -27,13 +27,12 @@ use libp2p::{ swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent}, tcp, yamux, Multiaddr, PeerId, Transport, }; +use std::error::Error; use tracing::level_filters::LevelFilter; use tracing_subscriber::EnvFilter; -use std::error::Error; #[async_std::main] async fn main() -> Result<(), Box> { - let env_filter = EnvFilter::builder() .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index e1ec97b015c..896c9a6b891 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -258,7 +258,7 @@ impl ConnectionHandler for Handler { match fut.poll_unpin(cx) { Poll::Pending => {} Poll::Ready(Err(e)) => { - tracing::debug!("Inbound ping error: {:?}", e); + tracing::error!("Inbound ping error: {:?}", e); self.inbound = None; } Poll::Ready(Ok(stream)) => { @@ -273,7 +273,7 @@ impl ConnectionHandler for Handler { loop { // Check for outbound ping failures. if let Some(error) = self.pending_errors.pop_back() { - tracing::debug!("Ping failure: {:?}", error); + tracing::error!("Ping failure: {:?}", error); self.failures += 1; @@ -295,8 +295,7 @@ impl ConnectionHandler for Handler { break; } Poll::Ready(Ok((stream, rtt))) => { - tracing::debug!("latency to {} is {}ms", self.peer, rtt.as_millis()); - + tracing::event!(tracing::Level::TRACE, peer = %self.peer, ms = rtt.as_millis()); self.failures = 0; self.interval.reset(self.config.interval); self.outbound = Some(OutboundState::Idle(stream)); diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 6fcdf457f5c..1451a4f9389 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -28,6 +28,7 @@ pub(crate) use error::{ PendingConnectionError, PendingInboundConnectionError, PendingOutboundConnectionError, }; pub use supported_protocols::SupportedProtocols; +use tracing::Span; use crate::handler::{ AddressChange, ConnectionEvent, ConnectionHandler, DialUpgradeError, FullyNegotiatedInbound, @@ -155,6 +156,7 @@ where local_supported_protocols: HashSet, remote_supported_protocols: HashSet, + error_span: Span, } impl fmt::Debug for Connection @@ -182,6 +184,7 @@ where mut handler: THandler, substream_upgrade_protocol_override: Option, max_negotiating_inbound_streams: usize, + error_span: Span, ) -> Self { let initial_protocols = gather_supported_protocols(&handler); @@ -190,7 +193,6 @@ where ProtocolsChange::Added(ProtocolsAdded::from_set(&initial_protocols)), )); } - Connection { muxing: muxer, handler, @@ -202,6 +204,7 @@ where requested_substreams: Default::default(), local_supported_protocols: initial_protocols, remote_supported_protocols: Default::default(), + error_span, } } @@ -233,8 +236,10 @@ where substream_upgrade_protocol_override, local_supported_protocols: supported_protocols, remote_supported_protocols, + error_span, } = self.get_mut(); + let _guard = error_span.enter(); loop { match requested_substreams.poll_next_unpin(cx) { Poll::Ready(Some(Ok(()))) => continue, @@ -711,7 +716,7 @@ mod tests { let max_negotiating_inbound_streams: usize = max_negotiating_inbound_streams.into(); let alive_substream_counter = Arc::new(()); - + let span = tracing::error_span!("test"); let mut connection = Connection::new( StreamMuxerBox::new(DummyStreamMuxer { counter: alive_substream_counter.clone(), @@ -719,6 +724,7 @@ mod tests { keep_alive::ConnectionHandler, None, max_negotiating_inbound_streams, + span, ); let result = connection.poll_noop_waker(); @@ -736,12 +742,14 @@ mod tests { #[test] fn outbound_stream_timeout_starts_on_request() { + let span = tracing::error_span!("test"); let upgrade_timeout = Duration::from_secs(1); let mut connection = Connection::new( StreamMuxerBox::new(PendingStreamMuxer), MockConnectionHandler::new(upgrade_timeout), None, 2, + span, ); connection.handler.open_new_outbound(); @@ -759,11 +767,13 @@ mod tests { #[test] fn propagates_changes_to_supported_inbound_protocols() { + let span = tracing::error_span!("test"); let mut connection = Connection::new( StreamMuxerBox::new(PendingStreamMuxer), ConfigurableProtocolConnectionHandler::default(), None, 0, + span, ); // First, start listening on a single protocol. @@ -797,11 +807,13 @@ mod tests { #[test] fn only_propagtes_actual_changes_to_remote_protocols_to_handler() { + let span = tracing::error_span!("test"); let mut connection = Connection::new( StreamMuxerBox::new(PendingStreamMuxer), ConfigurableProtocolConnectionHandler::default(), None, 0, + span, ); // First, remote supports a single protocol. diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index 4ca043e949f..bebde2d6f4d 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -307,8 +307,6 @@ where { /// Creates a new empty `Pool`. pub(crate) fn new(local_id: PeerId, config: PoolConfig) -> Self { - let span = tracing::error_span!("peer id:", %local_id, connection_id = tracing::field::Empty); - let _guard = span.enter(); let (pending_connection_events_tx, pending_connection_events_rx) = mpsc::channel(0); let executor = match config.executor { Some(exec) => ExecSwitch::Executor(exec), @@ -496,11 +494,6 @@ where handler: THandler, ) { let connection = connection.extract(); - - let span = tracing::error_span!("peer id:", %obtained_peer_id, connection_id = tracing::field::Empty); - let _guard = span.enter(); - span.record("connection id", tracing::field::display(id)); - let conns = self.established.entry(obtained_peer_id).or_default(); self.counters.inc_established(endpoint); @@ -519,11 +512,13 @@ where waker.wake(); } - let connection = Connection::new( + let span = tracing::error_span!("connection", connection_id = %id, peer_id = %obtained_peer_id, peer_address = ?endpoint); + let connection: Connection = Connection::new( connection, handler, self.substream_upgrade_protocol_override, self.max_negotiating_inbound_streams, + span, ); self.executor.spawn(task::new_for_established_connection( From 9780a079ed693ca8c9de84fdd74fbe658a64f84e Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 4 Aug 2023 18:51:18 +0300 Subject: [PATCH 003/105] remove tracing-subscriber from library crate --- Cargo.lock | 1 - swarm/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2810815e8db..9e56a4d5e0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3178,7 +3178,6 @@ dependencies = [ "smallvec", "tokio", "tracing", - "tracing-subscriber", "trybuild", "void", "wasm-bindgen-futures", diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 340cb56f713..bea05ebd930 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -32,7 +32,6 @@ multistream-select = { workspace = true } async-std = { version = "1.6.2", optional = true } tokio = { version = "1.29", features = ["rt"], optional = true } tracing = "0.1.37" -tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] } [features] macros = ["dep:libp2p-swarm-derive"] From c9e4a3b531ff8883abd5a7c4d3ae70880b646c6d Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 10 Aug 2023 15:26:16 +0300 Subject: [PATCH 004/105] update logging --- Cargo.lock | 13 ------------- examples/ping-example/Cargo.toml | 2 +- examples/ping-example/src/main.rs | 9 +++++---- protocols/ping/src/handler.rs | 2 +- swarm/src/connection.rs | 18 +++++++++--------- swarm/src/connection/pool.rs | 2 +- 6 files changed, 17 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9e56a4d5e0c..8653403c79f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5759,16 +5759,6 @@ dependencies = [ "tracing-core", ] -[[package]] -name = "tracing-serde" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" -dependencies = [ - "serde", - "tracing-core", -] - [[package]] name = "tracing-subscriber" version = "0.3.17" @@ -5779,15 +5769,12 @@ dependencies = [ "nu-ansi-term", "once_cell", "regex", - "serde", - "serde_json", "sharded-slab", "smallvec", "thread_local", "tracing", "tracing-core", "tracing-log", - "tracing-serde", ] [[package]] diff --git a/examples/ping-example/Cargo.toml b/examples/ping-example/Cargo.toml index e72391f65da..6c39aab3738 100644 --- a/examples/ping-example/Cargo.toml +++ b/examples/ping-example/Cargo.toml @@ -11,4 +11,4 @@ async-trait = "0.1" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "macros", "noise", "ping", "tcp", "websocket", "yamux"] } tracing = { version = "0.1.37", features = ["log"] } -tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] } \ No newline at end of file +tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file diff --git a/examples/ping-example/src/main.rs b/examples/ping-example/src/main.rs index f484bf646b9..68bf883f37b 100644 --- a/examples/ping-example/src/main.rs +++ b/examples/ping-example/src/main.rs @@ -27,6 +27,7 @@ use libp2p::{ swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent}, tcp, yamux, Multiaddr, PeerId, Transport, }; +use tracing::log; use std::error::Error; use tracing::level_filters::LevelFilter; use tracing_subscriber::EnvFilter; @@ -41,7 +42,7 @@ async fn main() -> Result<(), Box> { let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); - println!("Local peer id: {local_peer_id:?}"); + log::info!("Local peer id: {:?}", local_peer_id); let transport = tcp::async_io::Transport::default() .upgrade(Version::V1Lazy) @@ -62,13 +63,13 @@ async fn main() -> Result<(), Box> { if let Some(addr) = std::env::args().nth(1) { let remote: Multiaddr = addr.parse()?; swarm.dial(remote)?; - println!("Dialed {addr}") + log::info!("Dialed {}", addr); } loop { match swarm.select_next_some().await { - SwarmEvent::NewListenAddr { address, .. } => println!("Listening on {address:?}"), - SwarmEvent::Behaviour(event) => println!("{event:?}"), + SwarmEvent::NewListenAddr { address, .. } => log::info!("Listening on {}", address), + SwarmEvent::Behaviour(event) => log::info!("{:?}", event), _ => {} } } diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index 896c9a6b891..9619eae4f1b 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -295,7 +295,7 @@ impl ConnectionHandler for Handler { break; } Poll::Ready(Ok((stream, rtt))) => { - tracing::event!(tracing::Level::TRACE, peer = %self.peer, ms = rtt.as_millis()); + tracing::event!(tracing::Level::TRACE, peer = %self.peer, ?rtt); self.failures = 0; self.interval.reset(self.config.interval); self.outbound = Some(OutboundState::Idle(stream)); diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 1451a4f9389..14a8a4ff9ce 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -156,7 +156,7 @@ where local_supported_protocols: HashSet, remote_supported_protocols: HashSet, - error_span: Span, + span: Span, } impl fmt::Debug for Connection @@ -184,7 +184,7 @@ where mut handler: THandler, substream_upgrade_protocol_override: Option, max_negotiating_inbound_streams: usize, - error_span: Span, + span: Span, ) -> Self { let initial_protocols = gather_supported_protocols(&handler); @@ -204,7 +204,7 @@ where requested_substreams: Default::default(), local_supported_protocols: initial_protocols, remote_supported_protocols: Default::default(), - error_span, + span, } } @@ -236,10 +236,10 @@ where substream_upgrade_protocol_override, local_supported_protocols: supported_protocols, remote_supported_protocols, - error_span, + span, } = self.get_mut(); - let _guard = error_span.enter(); + let _guard = span.enter(); loop { match requested_substreams.poll_next_unpin(cx) { Poll::Ready(Some(Ok(()))) => continue, @@ -716,7 +716,7 @@ mod tests { let max_negotiating_inbound_streams: usize = max_negotiating_inbound_streams.into(); let alive_substream_counter = Arc::new(()); - let span = tracing::error_span!("test"); + let span = tracing::Span::none(); let mut connection = Connection::new( StreamMuxerBox::new(DummyStreamMuxer { counter: alive_substream_counter.clone(), @@ -742,7 +742,7 @@ mod tests { #[test] fn outbound_stream_timeout_starts_on_request() { - let span = tracing::error_span!("test"); + let span = tracing::Span::none(); let upgrade_timeout = Duration::from_secs(1); let mut connection = Connection::new( StreamMuxerBox::new(PendingStreamMuxer), @@ -767,7 +767,7 @@ mod tests { #[test] fn propagates_changes_to_supported_inbound_protocols() { - let span = tracing::error_span!("test"); + let span = tracing::Span::none(); let mut connection = Connection::new( StreamMuxerBox::new(PendingStreamMuxer), ConfigurableProtocolConnectionHandler::default(), @@ -807,7 +807,7 @@ mod tests { #[test] fn only_propagtes_actual_changes_to_remote_protocols_to_handler() { - let span = tracing::error_span!("test"); + let span = tracing::Span::none(); let mut connection = Connection::new( StreamMuxerBox::new(PendingStreamMuxer), ConfigurableProtocolConnectionHandler::default(), diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index bebde2d6f4d..8d858d229f9 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -512,7 +512,7 @@ where waker.wake(); } - let span = tracing::error_span!("connection", connection_id = %id, peer_id = %obtained_peer_id, peer_address = ?endpoint); + let span = tracing::error_span!("connection", id = %id, peer = %obtained_peer_id, peer_address = %endpoint.get_remote_address()); let connection: Connection = Connection::new( connection, handler, From bf2fa39bfc8f97f1a84999b80aca980cfcfe60c3 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 10 Aug 2023 15:40:56 +0300 Subject: [PATCH 005/105] remove reduncdant logs --- examples/ping-example/src/main.rs | 9 ++++----- protocols/ping/src/handler.rs | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/examples/ping-example/src/main.rs b/examples/ping-example/src/main.rs index 68bf883f37b..f484bf646b9 100644 --- a/examples/ping-example/src/main.rs +++ b/examples/ping-example/src/main.rs @@ -27,7 +27,6 @@ use libp2p::{ swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent}, tcp, yamux, Multiaddr, PeerId, Transport, }; -use tracing::log; use std::error::Error; use tracing::level_filters::LevelFilter; use tracing_subscriber::EnvFilter; @@ -42,7 +41,7 @@ async fn main() -> Result<(), Box> { let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); - log::info!("Local peer id: {:?}", local_peer_id); + println!("Local peer id: {local_peer_id:?}"); let transport = tcp::async_io::Transport::default() .upgrade(Version::V1Lazy) @@ -63,13 +62,13 @@ async fn main() -> Result<(), Box> { if let Some(addr) = std::env::args().nth(1) { let remote: Multiaddr = addr.parse()?; swarm.dial(remote)?; - log::info!("Dialed {}", addr); + println!("Dialed {addr}") } loop { match swarm.select_next_some().await { - SwarmEvent::NewListenAddr { address, .. } => log::info!("Listening on {}", address), - SwarmEvent::Behaviour(event) => log::info!("{:?}", event), + SwarmEvent::NewListenAddr { address, .. } => println!("Listening on {address:?}"), + SwarmEvent::Behaviour(event) => println!("{event:?}"), _ => {} } } diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index 9619eae4f1b..c4546be20a3 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -148,7 +148,7 @@ pub struct Handler { /// Tracks the state of our handler. state: State, /// The peer we are connected to. - peer: PeerId, + _peer: PeerId, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -168,7 +168,7 @@ impl Handler { /// Builds a new [`Handler`] with the given configuration. pub fn new(config: Config, peer: PeerId) -> Self { Handler { - peer, + _peer: peer, config, interval: Delay::new(Duration::new(0, 0)), pending_errors: VecDeque::with_capacity(2), @@ -262,7 +262,7 @@ impl ConnectionHandler for Handler { self.inbound = None; } Poll::Ready(Ok(stream)) => { - tracing::trace!("answered inbound ping from {}", self.peer); + tracing::trace!("answered inbound ping from peer"); // A ping from a remote peer has been answered, wait for the next. self.inbound = Some(protocol::recv_ping(stream).boxed()); @@ -295,7 +295,7 @@ impl ConnectionHandler for Handler { break; } Poll::Ready(Ok((stream, rtt))) => { - tracing::event!(tracing::Level::TRACE, peer = %self.peer, ?rtt); + tracing::event!(tracing::Level::TRACE, ?rtt); self.failures = 0; self.interval.reset(self.config.interval); self.outbound = Some(OutboundState::Idle(stream)); From 6c125899e02ab9b2de238edbf50626920164467a Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 30 Aug 2023 17:18:19 +0300 Subject: [PATCH 006/105] autonat tracing --- Cargo.lock | 3 +++ examples/autonat/Cargo.toml | 2 ++ examples/autonat/src/bin/autonat_client.rs | 8 +++++++- examples/autonat/src/bin/autonat_server.rs | 8 +++++++- protocols/autonat/Cargo.toml | 3 ++- protocols/autonat/src/behaviour/as_client.rs | 12 ++++++------ protocols/autonat/src/protocol.rs | 8 ++++---- 7 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 95bcfe01687..913b2d0ce2b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -527,6 +527,8 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p", + "tracing", + "tracing-subscriber", ] [[package]] @@ -2590,6 +2592,7 @@ dependencies = [ "log", "quick-protobuf", "rand 0.8.5", + "tracing", ] [[package]] diff --git a/examples/autonat/Cargo.toml b/examples/autonat/Cargo.toml index 9f40dbbc3f3..85497dd94b4 100644 --- a/examples/autonat/Cargo.toml +++ b/examples/autonat/Cargo.toml @@ -11,3 +11,5 @@ clap = { version = "4.3.12", features = ["derive"] } env_logger = "0.10.0" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "tcp", "noise", "yamux", "autonat", "identify", "macros"] } +tracing = { version = "0.1.37", features = ["log"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file diff --git a/examples/autonat/src/bin/autonat_client.rs b/examples/autonat/src/bin/autonat_client.rs index 40db305feef..651b457275e 100644 --- a/examples/autonat/src/bin/autonat_client.rs +++ b/examples/autonat/src/bin/autonat_client.rs @@ -29,6 +29,8 @@ use libp2p::{autonat, identify, identity, noise, tcp, yamux, PeerId}; use std::error::Error; use std::net::Ipv4Addr; use std::time::Duration; +use tracing::level_filters::LevelFilter; +use tracing_subscriber::EnvFilter; #[derive(Debug, Parser)] #[clap(name = "libp2p autonat")] @@ -45,7 +47,11 @@ struct Opt { #[async_std::main] async fn main() -> Result<(), Box> { - env_logger::init(); + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::DEBUG.into()) + .from_env_lossy(); + + tracing_subscriber::fmt().with_env_filter(env_filter).init(); let opt = Opt::parse(); diff --git a/examples/autonat/src/bin/autonat_server.rs b/examples/autonat/src/bin/autonat_server.rs index e0d6ad2f315..ec0c39c8618 100644 --- a/examples/autonat/src/bin/autonat_server.rs +++ b/examples/autonat/src/bin/autonat_server.rs @@ -27,6 +27,8 @@ use libp2p::swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent}; use libp2p::{autonat, identify, identity, noise, tcp, yamux, PeerId}; use std::error::Error; use std::net::Ipv4Addr; +use tracing::level_filters::LevelFilter; +use tracing_subscriber::EnvFilter; #[derive(Debug, Parser)] #[clap(name = "libp2p autonat")] @@ -37,7 +39,11 @@ struct Opt { #[async_std::main] async fn main() -> Result<(), Box> { - env_logger::init(); + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::DEBUG.into()) + .from_env_lossy(); + + tracing_subscriber::fmt().with_env_filter(env_filter).init(); let opt = Opt::parse(); diff --git a/protocols/autonat/Cargo.toml b/protocols/autonat/Cargo.toml index 4a8c9fe71d6..423cce8eab9 100644 --- a/protocols/autonat/Cargo.toml +++ b/protocols/autonat/Cargo.toml @@ -20,8 +20,9 @@ libp2p-swarm = { workspace = true } libp2p-request-response = { workspace = true } libp2p-identity = { workspace = true } log = "0.4" -rand = "0.8" quick-protobuf = "0.8" +rand = "0.8" +tracing = "0.1.37" [dev-dependencies] async-std = { version = "1.10", features = ["attributes"] } diff --git a/protocols/autonat/src/behaviour/as_client.rs b/protocols/autonat/src/behaviour/as_client.rs index e57523afaf8..1e0717cc20a 100644 --- a/protocols/autonat/src/behaviour/as_client.rs +++ b/protocols/autonat/src/behaviour/as_client.rs @@ -113,7 +113,7 @@ impl<'a> HandleInnerEvent for AsClient<'a> { response, }, } => { - log::debug!("Outbound dial-back request returned {:?}.", response); + tracing::debug!("Outbound dial-back request returned {:?}.", response); let probe_id = self .ongoing_outbound @@ -155,7 +155,7 @@ impl<'a> HandleInnerEvent for AsClient<'a> { error, request_id, } => { - log::debug!( + tracing::debug!( "Outbound Failure {} when on dial-back request to peer {}.", error, peer @@ -276,13 +276,13 @@ impl<'a> AsClient<'a> { ) -> Result { let _ = self.last_probe.insert(Instant::now()); if addresses.is_empty() { - log::debug!("Outbound dial-back request aborted: No dial-back addresses."); + tracing::debug!("Outbound dial-back request aborted: No dial-back addresses."); return Err(OutboundProbeError::NoAddresses); } let server = match self.random_server() { Some(s) => s, None => { - log::debug!("Outbound dial-back request aborted: No qualified server."); + tracing::debug!("Outbound dial-back request aborted: No qualified server."); return Err(OutboundProbeError::NoServer); } }; @@ -294,7 +294,7 @@ impl<'a> AsClient<'a> { }, ); self.throttled_servers.push((server, Instant::now())); - log::debug!("Send dial-back request to peer {}.", server); + tracing::debug!("Send dial-back request to peer {}.", server); self.ongoing_outbound.insert(request_id, probe_id); Ok(server) } @@ -345,7 +345,7 @@ impl<'a> AsClient<'a> { return None; } - log::debug!( + tracing::debug!( "Flipped assumed NAT status from {:?} to {:?}", self.nat_status, reported_status diff --git a/protocols/autonat/src/protocol.rs b/protocols/autonat/src/protocol.rs index a63fd8cdf4d..46defef19cd 100644 --- a/protocols/autonat/src/protocol.rs +++ b/protocols/autonat/src/protocol.rs @@ -115,7 +115,7 @@ impl DialRequest { { (peer_id, addrs) } else { - log::debug!("Received malformed dial message."); + tracing::debug!("Received malformed dial message."); return Err(io::Error::new( io::ErrorKind::InvalidData, "invalid dial message", @@ -132,7 +132,7 @@ impl DialRequest { .filter_map(|a| match Multiaddr::try_from(a.to_vec()) { Ok(a) => Some(a), Err(e) => { - log::debug!("Unable to parse multiaddr: {e}"); + tracing::debug!("Unable to parse multiaddr: {e}"); None } }) @@ -200,7 +200,7 @@ impl TryFrom for ResponseError { proto::ResponseStatus::E_BAD_REQUEST => Ok(ResponseError::BadRequest), proto::ResponseStatus::E_INTERNAL_ERROR => Ok(ResponseError::InternalError), proto::ResponseStatus::OK => { - log::debug!("Received response with status code OK but expected error."); + tracing::debug!("Received response with status code OK but expected error."); Err(io::Error::new( io::ErrorKind::InvalidData, "invalid response error type", @@ -249,7 +249,7 @@ impl DialResponse { result: Err(ResponseError::try_from(status)?), }, _ => { - log::debug!("Received malformed response message."); + tracing::debug!("Received malformed response message."); return Err(io::Error::new( io::ErrorKind::InvalidData, "invalid dial response message", From ae55e8bd97884bcbe58cd389276d500a367d2838 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 30 Aug 2023 17:36:32 +0300 Subject: [PATCH 007/105] dcutr changes --- Cargo.lock | 3 +++ examples/dcutr/Cargo.toml | 2 ++ examples/dcutr/src/main.rs | 8 +++++++- protocols/dcutr/Cargo.toml | 1 + protocols/dcutr/src/handler/relayed.rs | 2 +- protocols/dcutr/src/protocol/inbound.rs | 4 ++-- protocols/dcutr/src/protocol/outbound.rs | 4 ++-- 7 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 913b2d0ce2b..25fc5bfdeea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1313,6 +1313,8 @@ dependencies = [ "libp2p", "libp2p-quic", "log", + "tracing", + "tracing-subscriber", ] [[package]] @@ -2672,6 +2674,7 @@ dependencies = [ "quick-protobuf-codec", "rand 0.8.5", "thiserror", + "tracing", "void", ] diff --git a/examples/dcutr/Cargo.toml b/examples/dcutr/Cargo.toml index 5a6389f00c0..bd177723bea 100644 --- a/examples/dcutr/Cargo.toml +++ b/examples/dcutr/Cargo.toml @@ -13,3 +13,5 @@ futures-timer = "3.0" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "dcutr", "identify", "macros", "noise", "ping", "relay", "rendezvous", "tcp", "tokio", "yamux"] } libp2p-quic = { path = "../../transports/quic", features = ["async-std"] } log = "0.4" +tracing = { version = "0.1.37", features = ["log"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/dcutr/src/main.rs b/examples/dcutr/src/main.rs index 8359bb1902a..b5529f97d7d 100644 --- a/examples/dcutr/src/main.rs +++ b/examples/dcutr/src/main.rs @@ -43,6 +43,8 @@ use libp2p_quic as quic; use log::info; use std::error::Error; use std::str::FromStr; +use tracing::level_filters::LevelFilter; +use tracing_subscriber::EnvFilter; #[derive(Debug, Parser)] #[clap(name = "libp2p DCUtR client")] @@ -82,7 +84,11 @@ impl FromStr for Mode { } fn main() -> Result<(), Box> { - env_logger::init(); + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::DEBUG.into()) + .from_env_lossy(); + + tracing_subscriber::fmt().with_env_filter(env_filter).init(); let opts = Opts::parse(); diff --git a/protocols/dcutr/Cargo.toml b/protocols/dcutr/Cargo.toml index 5ef81f0dcf3..0639ce902a6 100644 --- a/protocols/dcutr/Cargo.toml +++ b/protocols/dcutr/Cargo.toml @@ -23,6 +23,7 @@ log = "0.4" quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } thiserror = "1.0" +tracing = "0.1.37" void = "1" [dev-dependencies] diff --git a/protocols/dcutr/src/handler/relayed.rs b/protocols/dcutr/src/handler/relayed.rs index ff22f2b18e1..86bcbfbcf05 100644 --- a/protocols/dcutr/src/handler/relayed.rs +++ b/protocols/dcutr/src/handler/relayed.rs @@ -119,7 +119,7 @@ impl Handler { ) .is_some() { - log::warn!( + tracing::warn!( "New inbound connect stream while still upgrading previous one. \ Replacing previous with new.", ); diff --git a/protocols/dcutr/src/protocol/inbound.rs b/protocols/dcutr/src/protocol/inbound.rs index d38b6f4559a..9c28c05a85a 100644 --- a/protocols/dcutr/src/protocol/inbound.rs +++ b/protocols/dcutr/src/protocol/inbound.rs @@ -61,14 +61,14 @@ impl upgrade::InboundUpgrade for Upgrade { .filter_map(|a| match Multiaddr::try_from(a.to_vec()) { Ok(a) => Some(a), Err(e) => { - log::debug!("Unable to parse multiaddr: {e}"); + tracing::debug!("Unable to parse multiaddr: {e}"); None } }) // Filter out relayed addresses. .filter(|a| { if a.iter().any(|p| p == Protocol::P2pCircuit) { - log::debug!("Dropping relayed address {a}"); + tracing::debug!("Dropping relayed address {a}"); false } else { true diff --git a/protocols/dcutr/src/protocol/outbound.rs b/protocols/dcutr/src/protocol/outbound.rs index 960d98cbe66..f415739661c 100644 --- a/protocols/dcutr/src/protocol/outbound.rs +++ b/protocols/dcutr/src/protocol/outbound.rs @@ -87,14 +87,14 @@ impl upgrade::OutboundUpgrade for Upgrade { .filter_map(|a| match Multiaddr::try_from(a.to_vec()) { Ok(a) => Some(a), Err(e) => { - log::debug!("Unable to parse multiaddr: {e}"); + tracing::debug!("Unable to parse multiaddr: {e}"); None } }) // Filter out relayed addresses. .filter(|a| { if a.iter().any(|p| p == Protocol::P2pCircuit) { - log::debug!("Dropping relayed address {a}"); + tracing::debug!("Dropping relayed address {a}"); false } else { true From 3ce8b027c1e3d2b64ec1bd12d43fb10c7d0c5e64 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 30 Aug 2023 17:51:00 +0300 Subject: [PATCH 008/105] relay server --- Cargo.lock | 3 +++ examples/relay-server/Cargo.toml | 2 ++ examples/relay-server/src/main.rs | 8 +++++++- protocols/relay/Cargo.toml | 1 + protocols/relay/src/behaviour/handler.rs | 4 ++-- protocols/relay/src/priv_client/handler.rs | 11 +++++------ protocols/relay/src/protocol/inbound_hop.rs | 2 +- 7 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 25fc5bfdeea..97ea4b6557b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3115,6 +3115,7 @@ dependencies = [ "rand 0.8.5", "static_assertions", "thiserror", + "tracing", "void", ] @@ -4621,6 +4622,8 @@ dependencies = [ "futures", "libp2p", "libp2p-quic", + "tracing", + "tracing-subscriber", ] [[package]] diff --git a/examples/relay-server/Cargo.toml b/examples/relay-server/Cargo.toml index 263a25b34ba..9855d7f95b2 100644 --- a/examples/relay-server/Cargo.toml +++ b/examples/relay-server/Cargo.toml @@ -13,3 +13,5 @@ env_logger = "0.10.0" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "noise", "macros", "ping", "tcp", "identify", "yamux", "relay"] } libp2p-quic = { path = "../../transports/quic", features = ["async-std"] } +tracing = { version = "0.1.37", features = ["log"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/relay-server/src/main.rs b/examples/relay-server/src/main.rs index 6a1d956b5a5..6372260c77b 100644 --- a/examples/relay-server/src/main.rs +++ b/examples/relay-server/src/main.rs @@ -38,9 +38,15 @@ use libp2p::{ use libp2p_quic as quic; use std::error::Error; use std::net::{Ipv4Addr, Ipv6Addr}; +use tracing::level_filters::LevelFilter; +use tracing_subscriber::EnvFilter; fn main() -> Result<(), Box> { - env_logger::init(); + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::DEBUG.into()) + .from_env_lossy(); + + tracing_subscriber::fmt().with_env_filter(env_filter).init(); let opt = Opt::parse(); println!("opt: {opt:?}"); diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index 31f6cc16d1e..d68d2ccdac6 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -26,6 +26,7 @@ quick-protobuf-codec = { workspace = true } rand = "0.8.4" static_assertions = "1" thiserror = "1.0" +tracing = "0.1.37" void = "1" [dev-dependencies] diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index 9c1b8524ec3..243761269db 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -584,7 +584,7 @@ impl ConnectionHandler for Handler { )) .is_some() { - log::warn!("Dropping existing deny/accept future in favor of new one.") + tracing::warn!("Dropping existing deny/accept future in favor of new one.") } } In::DenyReservationReq { @@ -598,7 +598,7 @@ impl ConnectionHandler for Handler { )) .is_some() { - log::warn!("Dropping existing deny/accept future in favor of new one.") + tracing::warn!("Dropping existing deny/accept future in favor of new one.") } } In::NegotiateOutboundConnect { diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs index 9613d7d6b3e..cdd9f2aa081 100644 --- a/protocols/relay/src/priv_client/handler.rs +++ b/protocols/relay/src/priv_client/handler.rs @@ -38,7 +38,6 @@ use libp2p_swarm::handler::{ use libp2p_swarm::{ ConnectionHandler, ConnectionHandlerEvent, KeepAlive, StreamUpgradeError, SubstreamProtocol, }; -use log::debug; use std::collections::{HashMap, VecDeque}; use std::fmt; use std::task::{Context, Poll}; @@ -205,7 +204,7 @@ impl Handler { if self.circuit_deny_futs.len() == MAX_NUMBER_DENYING_CIRCUIT && !self.circuit_deny_futs.contains_key(&src_peer_id) { - log::warn!( + tracing::warn!( "Dropping inbound circuit request to be denied from {:?} due to exceeding limit.", src_peer_id, ); @@ -217,7 +216,7 @@ impl Handler { ) .is_some() { - log::warn!( + tracing::warn!( "Dropping existing inbound circuit request to be denied from {:?} in favor of new one.", src_peer_id ) @@ -278,7 +277,7 @@ impl Handler { Event::OutboundCircuitEstablished { limit }, )); } - Err(_) => debug!( + Err(_) => tracing::debug!( "Oneshot to `client::transport::Dial` future dropped. \ Dropping established relayed connection to {:?}.", self.remote_peer_id, @@ -631,12 +630,12 @@ impl Reservation { if let Err(e) = to_listener .start_send(pending_msgs.pop_front().expect("Called !is_empty().")) { - debug!("Failed to sent pending message to listener: {:?}", e); + tracing::debug!("Failed to sent pending message to listener: {:?}", e); *self = Reservation::None; } } Poll::Ready(Err(e)) => { - debug!("Channel to listener failed: {:?}", e); + tracing::debug!("Channel to listener failed: {:?}", e); *self = Reservation::None; } Poll::Pending => {} diff --git a/protocols/relay/src/protocol/inbound_hop.rs b/protocols/relay/src/protocol/inbound_hop.rs index 27f2572a636..f551d6a8fa1 100644 --- a/protocols/relay/src/protocol/inbound_hop.rs +++ b/protocols/relay/src/protocol/inbound_hop.rs @@ -135,7 +135,7 @@ pub struct ReservationReq { impl ReservationReq { pub async fn accept(self, addrs: Vec) -> Result<(), UpgradeError> { if addrs.is_empty() { - log::debug!( + tracing::debug!( "Accepting relay reservation without providing external addresses of local node. \ Thus the remote node might not be able to advertise its relayed address." ) From ccdf58970aeb09e87058650e8e7d3f8df9d03ab7 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 30 Aug 2023 17:52:56 +0300 Subject: [PATCH 009/105] floodsub --- Cargo.lock | 1 + protocols/floodsub/Cargo.toml | 1 + protocols/floodsub/src/layer.rs | 5 ++--- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 97ea4b6557b..f1fc02b64be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2726,6 +2726,7 @@ dependencies = [ "rand 0.8.5", "smallvec", "thiserror", + "tracing", ] [[package]] diff --git a/protocols/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml index d79ae5bc719..85901f2369f 100644 --- a/protocols/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -24,6 +24,7 @@ quick-protobuf-codec = { workspace = true } rand = "0.8" smallvec = "1.11.0" thiserror = "1.0.44" +tracing = "0.1.37" # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/protocols/floodsub/src/layer.rs b/protocols/floodsub/src/layer.rs index 29fe8ba250f..f0b3527257e 100644 --- a/protocols/floodsub/src/layer.rs +++ b/protocols/floodsub/src/layer.rs @@ -33,7 +33,6 @@ use libp2p_swarm::{ dial_opts::DialOpts, ConnectionDenied, ConnectionId, NetworkBehaviour, NotifyHandler, OneShotHandler, PollParameters, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, }; -use log::warn; use smallvec::SmallVec; use std::collections::hash_map::{DefaultHasher, HashMap}; use std::task::{Context, Poll}; @@ -223,7 +222,7 @@ impl Floodsub { .any(|t| message.topics.iter().any(|u| t == u)); if self_subscribed { if let Err(e @ CuckooError::NotEnoughSpace) = self.received.add(&message) { - warn!( + tracing::warn!( "Message was added to 'received' Cuckoofilter but some \ other message was removed as a consequence: {}", e, @@ -406,7 +405,7 @@ impl NetworkBehaviour for Floodsub { Ok(false) => continue, // Message already existed. Err(e @ CuckooError::NotEnoughSpace) => { // Message added, but some other removed. - warn!( + tracing::warn!( "Message was added to 'received' Cuckoofilter but some \ other message was removed as a consequence: {}", e, From d23d9a12ce9e18665930bb8e6ae19c7603f5aa75 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 30 Aug 2023 17:57:06 +0300 Subject: [PATCH 010/105] gossipsub --- Cargo.lock | 1 + protocols/gossipsub/Cargo.toml | 1 + protocols/gossipsub/src/behaviour.rs | 2 +- protocols/gossipsub/src/gossip_promises.rs | 3 +-- protocols/gossipsub/src/handler.rs | 27 ++++++++++--------- protocols/gossipsub/src/mcache.rs | 2 +- protocols/gossipsub/src/peer_score.rs | 2 +- protocols/gossipsub/src/protocol.rs | 2 +- .../gossipsub/src/subscription_filter.rs | 2 +- 9 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f1fc02b64be..33f18e16a5a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2763,6 +2763,7 @@ dependencies = [ "serde", "sha2 0.10.7", "smallvec", + "tracing", "unsigned-varint", "void", ] diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index a9cf8b2a2fe..77d31f32eda 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -36,6 +36,7 @@ regex = "1.9.3" serde = { version = "1", optional = true, features = ["derive"] } sha2 = "0.10.7" smallvec = "1.11.0" +tracing = "0.1.37" unsigned-varint = { version = "0.7.0", features = ["asynchronous_codec"] } void = "1.0.2" diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 7ca9f6df9da..92566e992ba 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -31,7 +31,7 @@ use std::{ use futures::StreamExt; use futures_ticker::Ticker; -use log::{debug, error, trace, warn}; +use tracing::{debug, error, trace, warn}; use prometheus_client::registry::Registry; use rand::{seq::SliceRandom, thread_rng}; diff --git a/protocols/gossipsub/src/gossip_promises.rs b/protocols/gossipsub/src/gossip_promises.rs index e1418032903..5089e18bcc1 100644 --- a/protocols/gossipsub/src/gossip_promises.rs +++ b/protocols/gossipsub/src/gossip_promises.rs @@ -23,7 +23,6 @@ use crate::MessageId; use crate::ValidationError; use instant::Instant; use libp2p_identity::PeerId; -use log::debug; use std::collections::HashMap; /// Tracks recently sent `IWANT` messages and checks if peers respond to them. @@ -85,7 +84,7 @@ impl GossipPromises { if *expires < now { let count = result.entry(*peer_id).or_insert(0); *count += 1; - debug!( + tracing::debug!( "[Penalty] The peer {} broke the promise to deliver message {} in time!", peer_id, msg ); diff --git a/protocols/gossipsub/src/handler.rs b/protocols/gossipsub/src/handler.rs index 8508e026cee..8ccc3b88737 100644 --- a/protocols/gossipsub/src/handler.rs +++ b/protocols/gossipsub/src/handler.rs @@ -40,6 +40,7 @@ use std::{ task::{Context, Poll}, time::Duration, }; +use tracing::{debug, trace, warn}; use void::Void; /// The event emitted by the Handler. This informs the behaviour of various events created @@ -193,7 +194,7 @@ impl EnabledHandler { } // new inbound substream. Replace the current one, if it exists. - log::trace!("New inbound substream request"); + trace!("New inbound substream request"); self.inbound_substream = Some(InboundSubstreamState::WaitingInput(substream)); } @@ -264,7 +265,7 @@ impl EnabledHandler { return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour(message)); } Poll::Ready(Some(Err(error))) => { - log::debug!("Failed to read from inbound stream: {error}"); + debug!("Failed to read from inbound stream: {error}"); // Close this side of the stream. If the // peer is still around, they will re-establish their // outbound stream i.e. our inbound stream. @@ -273,7 +274,7 @@ impl EnabledHandler { } // peer closed the stream Poll::Ready(None) => { - log::debug!("Inbound stream closed by remote"); + debug!("Inbound stream closed by remote"); self.inbound_substream = Some(InboundSubstreamState::Closing(substream)); } @@ -291,7 +292,7 @@ impl EnabledHandler { // Don't close the connection but just drop the inbound substream. // In case the remote has more to send, they will open up a new // substream. - log::debug!("Inbound substream error while closing: {e}"); + debug!("Inbound substream error while closing: {e}"); } self.inbound_substream = None; break; @@ -341,14 +342,14 @@ impl EnabledHandler { Some(OutboundSubstreamState::PendingFlush(substream)) } Err(e) => { - log::debug!("Failed to send message on outbound stream: {e}"); + debug!("Failed to send message on outbound stream: {e}"); self.outbound_substream = None; break; } } } Poll::Ready(Err(e)) => { - log::debug!("Failed to send message on outbound stream: {e}"); + debug!("Failed to send message on outbound stream: {e}"); self.outbound_substream = None; break; } @@ -367,7 +368,7 @@ impl EnabledHandler { Some(OutboundSubstreamState::WaitingOutput(substream)) } Poll::Ready(Err(e)) => { - log::debug!("Failed to flush outbound stream: {e}"); + debug!("Failed to flush outbound stream: {e}"); self.outbound_substream = None; break; } @@ -424,7 +425,7 @@ impl ConnectionHandler for Handler { } }, Handler::Disabled(_) => { - log::debug!("Handler is disabled. Dropping message {:?}", message); + debug!("Handler is disabled. Dropping message {:?}", message); } } } @@ -492,7 +493,7 @@ impl ConnectionHandler for Handler { handler.inbound_substream_attempts += 1; if handler.inbound_substream_attempts == MAX_SUBSTREAM_ATTEMPTS { - log::warn!( + warn!( "The maximum number of inbound substreams attempts has been exceeded" ); *self = Handler::Disabled(DisabledHandler::MaxSubstreamAttempts); @@ -506,7 +507,7 @@ impl ConnectionHandler for Handler { handler.outbound_substream_attempts += 1; if handler.outbound_substream_attempts == MAX_SUBSTREAM_ATTEMPTS { - log::warn!( + warn!( "The maximum number of outbound substream attempts has been exceeded" ); *self = Handler::Disabled(DisabledHandler::MaxSubstreamAttempts); @@ -529,7 +530,7 @@ impl ConnectionHandler for Handler { error: StreamUpgradeError::Timeout, .. }) => { - log::debug!("Dial upgrade error: Protocol negotiation timeout"); + debug!("Dial upgrade error: Protocol negotiation timeout"); } ConnectionEvent::DialUpgradeError(DialUpgradeError { error: StreamUpgradeError::Apply(e), @@ -540,7 +541,7 @@ impl ConnectionHandler for Handler { .. }) => { // The protocol is not supported - log::debug!( + debug!( "The remote peer does not support gossipsub on this connection" ); *self = Handler::Disabled(DisabledHandler::ProtocolUnsupported { @@ -551,7 +552,7 @@ impl ConnectionHandler for Handler { error: StreamUpgradeError::Io(e), .. }) => { - log::debug!("Protocol negotiation failed: {e}") + debug!("Protocol negotiation failed: {e}") } ConnectionEvent::AddressChange(_) | ConnectionEvent::ListenUpgradeError(_) diff --git a/protocols/gossipsub/src/mcache.rs b/protocols/gossipsub/src/mcache.rs index e85a5bf9c6a..be4e37bdd21 100644 --- a/protocols/gossipsub/src/mcache.rs +++ b/protocols/gossipsub/src/mcache.rs @@ -21,7 +21,7 @@ use crate::topic::TopicHash; use crate::types::{MessageId, RawMessage}; use libp2p_identity::PeerId; -use log::{debug, trace}; +use tracing::{debug, trace}; use std::collections::hash_map::Entry; use std::fmt::Debug; use std::{ diff --git a/protocols/gossipsub/src/peer_score.rs b/protocols/gossipsub/src/peer_score.rs index ab92d536aba..100a0c35663 100644 --- a/protocols/gossipsub/src/peer_score.rs +++ b/protocols/gossipsub/src/peer_score.rs @@ -26,7 +26,7 @@ use crate::time_cache::TimeCache; use crate::{MessageId, TopicHash}; use instant::Instant; use libp2p_identity::PeerId; -use log::{debug, trace, warn}; +use tracing::{debug, trace, warn}; use std::collections::{hash_map, HashMap, HashSet}; use std::net::IpAddr; use std::time::Duration; diff --git a/protocols/gossipsub/src/protocol.rs b/protocols/gossipsub/src/protocol.rs index 15d2f59755a..95b1a450217 100644 --- a/protocols/gossipsub/src/protocol.rs +++ b/protocols/gossipsub/src/protocol.rs @@ -34,7 +34,7 @@ use futures::prelude::*; use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; use libp2p_identity::{PeerId, PublicKey}; use libp2p_swarm::StreamProtocol; -use log::{debug, warn}; +use tracing::{debug, warn}; use quick_protobuf::Writer; use std::pin::Pin; use unsigned_varint::codec; diff --git a/protocols/gossipsub/src/subscription_filter.rs b/protocols/gossipsub/src/subscription_filter.rs index 9f883f12a1b..cf68cb7f0f3 100644 --- a/protocols/gossipsub/src/subscription_filter.rs +++ b/protocols/gossipsub/src/subscription_filter.rs @@ -20,7 +20,7 @@ use crate::types::Subscription; use crate::TopicHash; -use log::debug; +use tracing::debug; use std::collections::{BTreeSet, HashMap, HashSet}; pub trait TopicSubscriptionFilter { From dce4a612ff03a1ce1df0776f8987f757b6d2e1dc Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 30 Aug 2023 18:03:49 +0300 Subject: [PATCH 011/105] identity --- Cargo.lock | 1 + protocols/identify/Cargo.toml | 1 + protocols/identify/src/behaviour.rs | 2 +- protocols/identify/src/handler.rs | 8 ++++---- protocols/identify/src/protocol.rs | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 33f18e16a5a..5ed2c1702c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2788,6 +2788,7 @@ dependencies = [ "quick-protobuf-codec", "smallvec", "thiserror", + "tracing", "void", ] diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index 61d38ede934..9489e98f967 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -23,6 +23,7 @@ quick-protobuf-codec = { workspace = true } quick-protobuf = "0.8" smallvec = "1.11.0" thiserror = "1.0" +tracing = "0.1.37" void = "1.0" either = "1.9.0" diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index f572b937d38..7cea27a9e65 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -183,7 +183,7 @@ impl Behaviour { { for p in peers { if !self.connected.contains_key(&p) { - log::debug!("Not pushing to {p} because we are not connected"); + tracing::debug!("Not pushing to {p} because we are not connected"); continue; } diff --git a/protocols/identify/src/handler.rs b/protocols/identify/src/handler.rs index 5a1712e8c3d..08c75e1227b 100644 --- a/protocols/identify/src/handler.rs +++ b/protocols/identify/src/handler.rs @@ -36,7 +36,7 @@ use libp2p_swarm::{ ConnectionHandler, ConnectionHandlerEvent, KeepAlive, StreamProtocol, StreamUpgradeError, SubstreamProtocol, SupportedProtocols, }; -use log::{warn, Level}; +use tracing::{warn, Level}; use smallvec::SmallVec; use std::collections::HashSet; use std::{io, task::Context, task::Poll, time::Duration}; @@ -362,16 +362,16 @@ impl ConnectionHandler for Handler { | ConnectionEvent::ListenUpgradeError(_) | ConnectionEvent::RemoteProtocolsChange(_) => {} ConnectionEvent::LocalProtocolsChange(change) => { - let before = log::log_enabled!(Level::Debug) + let before = tracing::enabled!(Level::DEBUG) .then(|| self.local_protocols_to_string()) .unwrap_or_default(); let protocols_changed = self.local_supported_protocols.on_protocols_change(change); - let after = log::log_enabled!(Level::Debug) + let after = tracing::enabled!(Level::DEBUG) .then(|| self.local_protocols_to_string()) .unwrap_or_default(); if protocols_changed && self.exchanged_one_periodic_identify { - log::debug!( + tracing::debug!( "Supported listen protocols changed from [{before}] to [{after}], pushing to {}", self.remote_peer_id ); diff --git a/protocols/identify/src/protocol.rs b/protocols/identify/src/protocol.rs index a508591b106..68ac0377ac6 100644 --- a/protocols/identify/src/protocol.rs +++ b/protocols/identify/src/protocol.rs @@ -29,7 +29,7 @@ use libp2p_core::{ use libp2p_identity as identity; use libp2p_identity::PublicKey; use libp2p_swarm::StreamProtocol; -use log::{debug, trace}; +use tracing::{debug, trace}; use std::convert::TryFrom; use std::{io, iter, pin::Pin}; use thiserror::Error; From 60c4c2353d03867821cf89aa1d705894af4e00be Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 30 Aug 2023 18:11:39 +0300 Subject: [PATCH 012/105] kad --- Cargo.lock | 1 + protocols/kad/Cargo.toml | 1 + protocols/kad/src/behaviour.rs | 22 +++++++++++----------- protocols/kad/src/handler.rs | 20 ++++++++++---------- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e122ae0c824..36960ac6637 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2845,6 +2845,7 @@ dependencies = [ "sha2 0.10.7", "smallvec", "thiserror", + "tracing", "uint", "unsigned-varint", "void", diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index fa937033908..62df01fd716 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -32,6 +32,7 @@ futures-timer = "3.0.2" instant = "0.1.12" serde = { version = "1.0", optional = true, features = ["derive"] } thiserror = "1" +tracing = "0.1.37" [dev-dependencies] async-std = { version = "1.12.0", features = ["attributes"] } diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index 340fefb276a..da3cc21d1c5 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -47,7 +47,7 @@ use libp2p_swarm::{ NetworkBehaviour, NotifyHandler, PollParameters, StreamProtocol, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, }; -use log::{debug, info, warn}; +use tracing::{debug, info, warn, trace, Level}; use smallvec::SmallVec; use std::collections::{BTreeMap, HashMap, HashSet, VecDeque}; use std::fmt; @@ -1027,7 +1027,7 @@ where let num_connections = self.connections.len(); - log::debug!( + debug!( "Re-configuring {} established connection{}", num_connections, if num_connections > 1 { "s" } else { "" } @@ -1050,7 +1050,7 @@ where fn determine_mode_from_external_addresses(&mut self) { self.mode = match (self.external_addresses.as_slice(), self.mode) { ([], Mode::Server) => { - log::debug!("Switching to client-mode because we no longer have any confirmed external addresses"); + debug!("Switching to client-mode because we no longer have any confirmed external addresses"); Mode::Client } @@ -1060,11 +1060,11 @@ where Mode::Client } (confirmed_external_addresses, Mode::Client) => { - if log::log_enabled!(log::Level::Debug) { + if tracing::enabled!(Level::DEBUG) { let confirmed_external_addresses = to_comma_separated_list(confirmed_external_addresses); - log::debug!("Switching to server-mode assuming that one of [{confirmed_external_addresses}] is externally reachable"); + debug!("Switching to server-mode assuming that one of [{confirmed_external_addresses}] is externally reachable"); } Mode::Server @@ -1092,9 +1092,9 @@ where let local_id = self.kbuckets.local_key().preimage(); let others_iter = peers.filter(|p| &p.node_id != local_id); if let Some(query) = self.queries.get_mut(query_id) { - log::trace!("Request to {:?} in query {:?} succeeded.", source, query_id); + trace!("Request to {:?} in query {:?} succeeded.", source, query_id); for peer in others_iter.clone() { - log::trace!( + trace!( "Peer {:?} reported by {:?} in query {:?}.", peer, source, @@ -1324,7 +1324,7 @@ where /// Handles a finished (i.e. successful) query. fn query_finished(&mut self, q: Query) -> Option { let query_id = q.id(); - log::trace!("Query {:?} finished.", query_id); + trace!("Query {:?} finished.", query_id); let result = q.into_result(); match result.inner.info { QueryInfo::Bootstrap { @@ -1562,7 +1562,7 @@ where /// Handles a query that timed out. fn query_timeout(&mut self, query: Query) -> Option { let query_id = query.id(); - log::trace!("Query {:?} timed out.", query_id); + trace!("Query {:?} timed out.", query_id); let result = query.into_result(); match result.inner.info { QueryInfo::Bootstrap { @@ -2261,7 +2261,7 @@ where } KademliaHandlerEvent::QueryError { query_id, error } => { - log::debug!( + debug!( "Request to {:?} in query {:?} failed with {:?}", source, query_id, @@ -2353,7 +2353,7 @@ where *step = step.next(); } else { - log::trace!("Record with key {:?} not found at {}", key, source); + trace!("Record with key {:?} not found at {}", key, source); if let KademliaCaching::Enabled { max_peers } = self.caching { let source_key = kbucket::Key::from(source); let target_key = kbucket::Key::from(key.clone()); diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index d695420ec2b..84c86ba7f81 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -38,7 +38,7 @@ use libp2p_swarm::{ ConnectionHandler, ConnectionHandlerEvent, ConnectionId, KeepAlive, Stream, StreamUpgradeError, SubstreamProtocol, SupportedProtocols, }; -use log::trace; +use tracing::{trace, debug, warn}; use std::collections::VecDeque; use std::task::Waker; use std::{ @@ -481,12 +481,12 @@ impl KademliaHandler { ) -> Self { match &endpoint { ConnectedPoint::Dialer { .. } => { - log::debug!( + debug!( "Operating in {mode}-mode on new outbound connection to {remote_peer_id}" ); } ConnectedPoint::Listener { .. } => { - log::debug!( + debug!( "Operating in {mode}-mode on new inbound connection to {remote_peer_id}" ); } @@ -566,13 +566,13 @@ impl KademliaHandler { ) }) { *s = InboundSubstreamState::Cancelled; - log::debug!( + debug!( "New inbound substream to {:?} exceeds inbound substream limit. \ Removed older substream waiting to be reused.", self.remote_peer_id, ) } else { - log::warn!( + warn!( "New inbound substream to {:?} exceeds inbound substream limit. \ No older substream waiting to be reused. Dropping new substream.", self.remote_peer_id, @@ -704,12 +704,12 @@ impl ConnectionHandler for KademliaHandler { match &self.endpoint { ConnectedPoint::Dialer { .. } => { - log::debug!( + debug!( "Now operating in {new_mode}-mode on outbound connection with {peer}" ) } ConnectedPoint::Listener { local_addr, .. } => { - log::debug!("Now operating in {new_mode}-mode on inbound connection with {peer} assuming that one of our external addresses routes to {local_addr}") + debug!("Now operating in {new_mode}-mode on inbound connection with {peer} assuming that one of our external addresses routes to {local_addr}") } } @@ -808,7 +808,7 @@ impl ConnectionHandler for KademliaHandler { match (remote_supports_our_kademlia_protocols, self.protocol_status) { (true, ProtocolStatus::Confirmed | ProtocolStatus::Reported) => {} (true, _) => { - log::debug!( + debug!( "Remote {} now supports our kademlia protocol on connection {}", self.remote_peer_id, self.connection_id, @@ -817,7 +817,7 @@ impl ConnectionHandler for KademliaHandler { self.protocol_status = ProtocolStatus::Confirmed; } (false, ProtocolStatus::Confirmed | ProtocolStatus::Reported) => { - log::debug!( + debug!( "Remote {} no longer supports our kademlia protocol on connection {}", self.remote_peer_id, self.connection_id, @@ -1005,7 +1005,7 @@ impl futures::Stream for InboundSubstreamState { mut substream, } => match substream.poll_next_unpin(cx) { Poll::Ready(Some(Ok(KadRequestMsg::Ping))) => { - log::warn!("Kademlia PING messages are unsupported"); + warn!("Kademlia PING messages are unsupported"); *this = InboundSubstreamState::Closing(substream); } From 1344b7f13d8e330c84c87832c4d2310e9f1f5347 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 30 Aug 2023 18:14:24 +0300 Subject: [PATCH 013/105] mdns --- Cargo.lock | 1 + protocols/mdns/Cargo.toml | 1 + protocols/mdns/src/behaviour.rs | 12 ++++++------ protocols/mdns/src/behaviour/iface.rs | 23 ++++++++++++----------- protocols/mdns/src/behaviour/iface/dns.rs | 2 +- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 36960ac6637..34caaaed606 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2873,6 +2873,7 @@ dependencies = [ "smallvec", "socket2 0.5.3", "tokio", + "tracing", "trust-dns-proto", "void", ] diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index 41f5d9af428..eb5da4524b9 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -23,6 +23,7 @@ rand = "0.8.3" smallvec = "1.11.0" socket2 = { version = "0.5.3", features = ["all"] } tokio = { version = "1.32", default-features = false, features = ["net", "time"], optional = true} +tracing = "0.1.37" trust-dns-proto = { version = "0.22.0", default-features = false, features = ["mdns", "tokio-runtime"] } void = "1.0.2" diff --git a/protocols/mdns/src/behaviour.rs b/protocols/mdns/src/behaviour.rs index bc102f832df..71d3714b91e 100644 --- a/protocols/mdns/src/behaviour.rs +++ b/protocols/mdns/src/behaviour.rs @@ -229,7 +229,7 @@ where match event { FromSwarm::NewListener(_) => { - log::trace!("waking interface state because listening address changed"); + tracing::trace!("waking interface state because listening address changed"); for iface in self.iface_states.values_mut() { iface.fire_timer(); } @@ -272,17 +272,17 @@ where Ok(iface_state) => { e.insert(iface_state); } - Err(err) => log::error!("failed to create `InterfaceState`: {}", err), + Err(err) => tracing::error!("failed to create `InterfaceState`: {}", err), } } } Ok(IfEvent::Down(inet)) => { if self.iface_states.contains_key(&inet.addr()) { - log::info!("dropping instance {}", inet.addr()); + tracing::info!("dropping instance {}", inet.addr()); self.iface_states.remove(&inet.addr()); } } - Err(err) => log::error!("if watch returned an error: {}", err), + Err(err) => tracing::error!("if watch returned an error: {}", err), } } // Emit discovered event. @@ -298,7 +298,7 @@ where { *cur_expires = cmp::max(*cur_expires, expiration); } else { - log::info!("discovered: {} {}", peer, addr); + tracing::info!("discovered: {} {}", peer, addr); self.discovered_nodes.push((peer, addr.clone(), expiration)); discovered.push((peer, addr)); } @@ -314,7 +314,7 @@ where let mut expired = Vec::new(); self.discovered_nodes.retain(|(peer, addr, expiration)| { if *expiration <= now { - log::info!("expired: {} {}", peer, addr); + tracing::info!("expired: {} {}", peer, addr); expired.push((*peer, addr.clone())); return false; } diff --git a/protocols/mdns/src/behaviour/iface.rs b/protocols/mdns/src/behaviour/iface.rs index 54d6c657380..11010398de0 100644 --- a/protocols/mdns/src/behaviour/iface.rs +++ b/protocols/mdns/src/behaviour/iface.rs @@ -37,6 +37,7 @@ use std::{ task::{Context, Poll}, time::{Duration, Instant}, }; +use tracing::{info, trace, debug, error}; /// Initial interval for starting probe const INITIAL_TIMEOUT_INTERVAL: Duration = Duration::from_millis(500); @@ -102,7 +103,7 @@ where { /// Builds a new [`InterfaceState`]. pub(crate) fn new(addr: IpAddr, config: Config, local_peer_id: PeerId) -> io::Result { - log::info!("creating instance on iface {}", addr); + info!("creating instance on iface {}", addr); let recv_socket = match addr { IpAddr::V4(addr) => { let socket = Socket::new(Domain::IPV4, Type::DGRAM, Some(socket2::Protocol::UDP))?; @@ -167,7 +168,7 @@ where } pub(crate) fn reset_timer(&mut self) { - log::trace!("reset timer on {:#?} {:#?}", self.addr, self.probe_state); + trace!("reset timer on {:#?} {:#?}", self.addr, self.probe_state); let interval = *self.probe_state.interval(); self.timeout = T::interval(interval); } @@ -184,9 +185,9 @@ where loop { // 1st priority: Low latency: Create packet ASAP after timeout. if Pin::new(&mut self.timeout).poll_next(cx).is_ready() { - log::trace!("sending query on iface {}", self.addr); + trace!("sending query on iface {}", self.addr); self.send_buffer.push_back(build_query()); - log::trace!("tick on {:#?} {:#?}", self.addr, self.probe_state); + trace!("tick on {:#?} {:#?}", self.addr, self.probe_state); // Stop to probe when the initial interval reach the query interval if let ProbeState::Probing(interval) = self.probe_state { @@ -209,11 +210,11 @@ where SocketAddr::new(self.multicast_addr, 5353), ) { Poll::Ready(Ok(_)) => { - log::trace!("sent packet on iface {}", self.addr); + trace!("sent packet on iface {}", self.addr); continue; } Poll::Ready(Err(err)) => { - log::error!("error sending packet on iface {} {}", self.addr, err); + error!("error sending packet on iface {} {}", self.addr, err); continue; } Poll::Pending => { @@ -233,7 +234,7 @@ where .map_ok(|(len, from)| MdnsPacket::new_from_bytes(&self.recv_buffer[..len], from)) { Poll::Ready(Ok(Ok(Some(MdnsPacket::Query(query))))) => { - log::trace!( + trace!( "received query from {} on {}", query.remote_addr(), self.addr @@ -248,7 +249,7 @@ where continue; } Poll::Ready(Ok(Ok(Some(MdnsPacket::Response(response))))) => { - log::trace!( + trace!( "received response from {} on {}", response.remote_addr(), self.addr @@ -265,7 +266,7 @@ where continue; } Poll::Ready(Ok(Ok(Some(MdnsPacket::ServiceDiscovery(disc))))) => { - log::trace!( + trace!( "received service discovery from {} on {}", disc.remote_addr(), self.addr @@ -279,10 +280,10 @@ where // No more bytes available on the socket to read } Poll::Ready(Err(err)) => { - log::error!("failed reading datagram: {}", err); + error!("failed reading datagram: {}", err); } Poll::Ready(Ok(Err(err))) => { - log::debug!("Parsing mdns packet failed: {:?}", err); + debug!("Parsing mdns packet failed: {:?}", err); } Poll::Ready(Ok(Ok(None))) | Poll::Pending => {} } diff --git a/protocols/mdns/src/behaviour/iface/dns.rs b/protocols/mdns/src/behaviour/iface/dns.rs index 6a10497e69f..70fca5a0d47 100644 --- a/protocols/mdns/src/behaviour/iface/dns.rs +++ b/protocols/mdns/src/behaviour/iface/dns.rs @@ -134,7 +134,7 @@ pub(crate) fn build_query_response<'a>( records.push(txt_record); } Err(e) => { - log::warn!("Excluding address {} from response: {:?}", addr, e); + tracing::warn!("Excluding address {} from response: {:?}", addr, e); } } From ec8f0f163190ad909fed5743cb6f1b692e30744b Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 30 Aug 2023 18:20:24 +0300 Subject: [PATCH 014/105] perf --- Cargo.lock | 1 + protocols/perf/Cargo.toml | 1 + protocols/perf/src/bin/perf.rs | 2 +- protocols/perf/src/server/handler.rs | 3 +-- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 34caaaed606..4f0502cdb39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3001,6 +3001,7 @@ dependencies = [ "serde_json", "thiserror", "tokio", + "tracing", "void", ] diff --git a/protocols/perf/Cargo.toml b/protocols/perf/Cargo.toml index 41b91ea1209..6362f7d0a06 100644 --- a/protocols/perf/Cargo.toml +++ b/protocols/perf/Cargo.toml @@ -30,6 +30,7 @@ log = "0.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" +tracing = "0.1.37" tokio = { version = "1.32.0", features = ["full"] } void = "1" diff --git a/protocols/perf/src/bin/perf.rs b/protocols/perf/src/bin/perf.rs index b6b090608f5..da7b915a796 100644 --- a/protocols/perf/src/bin/perf.rs +++ b/protocols/perf/src/bin/perf.rs @@ -32,7 +32,7 @@ use libp2p_core::{ use libp2p_identity::PeerId; use libp2p_perf::{Run, RunDuration, RunParams}; use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent}; -use log::{error, info}; +use tracing::{error, info}; use serde::{Deserialize, Serialize}; #[derive(Debug, Parser)] diff --git a/protocols/perf/src/server/handler.rs b/protocols/perf/src/server/handler.rs index e8f7b72e605..cafe49b403c 100644 --- a/protocols/perf/src/server/handler.rs +++ b/protocols/perf/src/server/handler.rs @@ -32,7 +32,6 @@ use libp2p_swarm::{ }, ConnectionHandler, ConnectionHandlerEvent, KeepAlive, StreamProtocol, SubstreamProtocol, }; -use log::error; use void::Void; use super::RunStats; @@ -133,7 +132,7 @@ impl ConnectionHandler for Handler { return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour(Event { stats })) } Err(e) => { - error!("{e:?}") + tracing::error!("{e:?}") } } } From 2000e42c8660786873565d302d8ef563f7ff8e0d Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 30 Aug 2023 18:34:17 +0300 Subject: [PATCH 015/105] rendezvous --- Cargo.lock | 1 + protocols/rendezvous/Cargo.toml | 1 + protocols/rendezvous/src/server.rs | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 4f0502cdb39..149b89d608f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3148,6 +3148,7 @@ dependencies = [ "rand 0.8.5", "thiserror", "tokio", + "tracing", "void", ] diff --git a/protocols/rendezvous/Cargo.toml b/protocols/rendezvous/Cargo.toml index b231f9d7c24..88e48ad98b4 100644 --- a/protocols/rendezvous/Cargo.toml +++ b/protocols/rendezvous/Cargo.toml @@ -26,6 +26,7 @@ quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } rand = "0.8" thiserror = "1" +tracing = "0.1.37" void = "1" [dev-dependencies] diff --git a/protocols/rendezvous/src/server.rs b/protocols/rendezvous/src/server.rs index 44f2f97a6a0..7c97bb33cfe 100644 --- a/protocols/rendezvous/src/server.rs +++ b/protocols/rendezvous/src/server.rs @@ -195,7 +195,7 @@ impl NetworkBehaviour for Behaviour { request_id, error, }) => { - log::warn!("Inbound request {request_id} with peer {peer} failed: {error}"); + tracing::warn!("Inbound request {request_id} with peer {peer} failed: {error}"); continue; } From 3f40960833f33528553e761b7532ca8939a7af83 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 30 Aug 2023 18:35:36 +0300 Subject: [PATCH 016/105] request-response --- Cargo.lock | 2 +- protocols/request-response/Cargo.toml | 2 +- protocols/request-response/src/handler.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 149b89d608f..bf25a94db56 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3170,11 +3170,11 @@ dependencies = [ "libp2p-swarm-test", "libp2p-tcp", "libp2p-yamux", - "log", "rand 0.8.5", "serde", "serde_json", "smallvec", + "tracing", "void", ] diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index 0db687592f7..d661a120b36 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -22,8 +22,8 @@ rand = "0.8" serde = { version = "1.0", optional = true} serde_json = { version = "1.0.105", optional = true } smallvec = "1.11.0" +tracing = "0.1.37" void = "1.0.2" -log = "0.4.20" [features] json = ["dep:serde", "dep:serde_json", "libp2p-swarm/macros"] diff --git a/protocols/request-response/src/handler.rs b/protocols/request-response/src/handler.rs index 35a2db98bdc..b20e3017444 100644 --- a/protocols/request-response/src/handler.rs +++ b/protocols/request-response/src/handler.rs @@ -149,10 +149,10 @@ where .push_back(Event::OutboundUnsupportedProtocols(info)); } StreamUpgradeError::Apply(e) => { - log::debug!("outbound stream {info} failed: {e}"); + tracing::debug!("outbound stream {info} failed: {e}"); } StreamUpgradeError::Io(e) => { - log::debug!("outbound stream {info} failed: {e}"); + tracing::debug!("outbound stream {info} failed: {e}"); } } } @@ -163,7 +163,7 @@ where ::InboundProtocol, >, ) { - log::debug!("inbound stream {info} failed: {error}"); + tracing::debug!("inbound stream {info} failed: {error}"); } } From d9904881a13839ac9f96dda1ef09ab24c0c30a66 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 30 Aug 2023 22:22:07 +0300 Subject: [PATCH 017/105] chat example changes --- Cargo.lock | 2 ++ examples/chat-example/Cargo.toml | 2 ++ examples/chat-example/src/main.rs | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index bf25a94db56..660af18f991 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -833,6 +833,8 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p", + "tracing", + "tracing-subscriber", ] [[package]] diff --git a/examples/chat-example/Cargo.toml b/examples/chat-example/Cargo.toml index cfc417cf3cb..b99f73a1f81 100644 --- a/examples/chat-example/Cargo.toml +++ b/examples/chat-example/Cargo.toml @@ -11,3 +11,5 @@ async-trait = "0.1" env_logger = "0.10.0" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "gossipsub", "mdns", "noise", "macros", "tcp", "yamux", "quic"] } +tracing = { version = "0.1.37", features = ["log"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file diff --git a/examples/chat-example/src/main.rs b/examples/chat-example/src/main.rs index 95a16f388d9..fa807b2cfd6 100644 --- a/examples/chat-example/src/main.rs +++ b/examples/chat-example/src/main.rs @@ -29,6 +29,7 @@ use libp2p::{ swarm::{SwarmBuilder, SwarmEvent}, tcp, yamux, PeerId, Transport, }; +use tracing_subscriber::{EnvFilter, filter::LevelFilter}; use std::collections::hash_map::DefaultHasher; use std::error::Error; use std::hash::{Hash, Hasher}; @@ -43,6 +44,11 @@ struct MyBehaviour { #[async_std::main] async fn main() -> Result<(), Box> { + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::DEBUG.into()) + .from_env_lossy(); + + tracing_subscriber::fmt().with_env_filter(env_filter).init(); // Create a random PeerId let id_keys = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(id_keys.public()); From 3e7af9b3cceb41ed03ff8a34e12f7ac44af3286e Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 30 Aug 2023 22:28:39 +0300 Subject: [PATCH 018/105] distributed key value store example --- Cargo.lock | 2 ++ examples/distributed-key-value-store/Cargo.toml | 2 ++ examples/distributed-key-value-store/src/main.rs | 7 ++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 660af18f991..41205f470d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1453,6 +1453,8 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p", + "tracing", + "tracing-subscriber", ] [[package]] diff --git a/examples/distributed-key-value-store/Cargo.toml b/examples/distributed-key-value-store/Cargo.toml index f8e0fd2339d..13684f0e351 100644 --- a/examples/distributed-key-value-store/Cargo.toml +++ b/examples/distributed-key-value-store/Cargo.toml @@ -11,3 +11,5 @@ async-trait = "0.1" env_logger = "0.10" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "kad", "mdns", "noise", "macros", "tcp", "websocket", "yamux"] } +tracing = { version = "0.1.37", features = ["log"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file diff --git a/examples/distributed-key-value-store/src/main.rs b/examples/distributed-key-value-store/src/main.rs index ce0998a9ac5..447c9195adc 100644 --- a/examples/distributed-key-value-store/src/main.rs +++ b/examples/distributed-key-value-store/src/main.rs @@ -35,10 +35,15 @@ use libp2p::{ tcp, yamux, PeerId, Transport, }; use std::error::Error; +use tracing_subscriber::{EnvFilter, filter::LevelFilter}; #[async_std::main] async fn main() -> Result<(), Box> { - env_logger::init(); + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::DEBUG.into()) + .from_env_lossy(); + + tracing_subscriber::fmt().with_env_filter(env_filter).init(); // Create a random key for ourselves. let local_key = identity::Keypair::generate_ed25519(); From f4d99449d876d403f803b82537bc9355b2aae05a Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 31 Aug 2023 08:54:16 +0300 Subject: [PATCH 019/105] inline tracing spans --- swarm/src/connection.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index e74ed02d749..016c50f65e8 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -717,7 +717,6 @@ mod tests { let max_negotiating_inbound_streams: usize = max_negotiating_inbound_streams.into(); let alive_substream_counter = Arc::new(()); - let span = tracing::Span::none(); let mut connection = Connection::new( StreamMuxerBox::new(DummyStreamMuxer { counter: alive_substream_counter.clone(), @@ -725,7 +724,7 @@ mod tests { keep_alive::ConnectionHandler, None, max_negotiating_inbound_streams, - span, + tracing::Span::none(), ); let result = connection.poll_noop_waker(); @@ -743,14 +742,13 @@ mod tests { #[test] fn outbound_stream_timeout_starts_on_request() { - let span = tracing::Span::none(); let upgrade_timeout = Duration::from_secs(1); let mut connection = Connection::new( StreamMuxerBox::new(PendingStreamMuxer), MockConnectionHandler::new(upgrade_timeout), None, 2, - span, + tracing::Span::none(), ); connection.handler.open_new_outbound(); @@ -768,13 +766,12 @@ mod tests { #[test] fn propagates_changes_to_supported_inbound_protocols() { - let span = tracing::Span::none(); let mut connection = Connection::new( StreamMuxerBox::new(PendingStreamMuxer), ConfigurableProtocolConnectionHandler::default(), None, 0, - span, + tracing::Span::none(), ); // First, start listening on a single protocol. @@ -808,13 +805,12 @@ mod tests { #[test] fn only_propagtes_actual_changes_to_remote_protocols_to_handler() { - let span = tracing::Span::none(); let mut connection = Connection::new( StreamMuxerBox::new(PendingStreamMuxer), ConfigurableProtocolConnectionHandler::default(), None, 0, - span, + tracing::Span::none(), ); // First, remote supports a single protocol. From ea8683f688121433a382c0083f71cbdc94596206 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 31 Aug 2023 09:04:30 +0300 Subject: [PATCH 020/105] add tracing to the rest of the examples --- Cargo.lock | 23 +++++++++-------- examples/autonat/Cargo.toml | 1 - examples/chat-example/Cargo.toml | 1 - .../distributed-key-value-store/Cargo.toml | 1 - examples/file-sharing/Cargo.toml | 3 ++- examples/file-sharing/src/main.rs | 7 +++++- examples/identify/Cargo.toml | 2 ++ examples/identify/src/main.rs | 7 ++++++ examples/ipfs-kad/Cargo.toml | 3 ++- examples/ipfs-kad/src/main.rs | 7 +++++- examples/ipfs-private/Cargo.toml | 3 ++- examples/ipfs-private/src/main.rs | 7 +++++- examples/metrics/Cargo.toml | 4 +-- examples/metrics/src/http_service.rs | 2 +- examples/metrics/src/main.rs | 10 +++++--- examples/relay-server/Cargo.toml | 1 - examples/relay-server/src/main.rs | 3 +-- examples/rendezvous/Cargo.toml | 4 +-- examples/rendezvous/src/bin/rzv-discover.rs | 17 ++++++++----- examples/rendezvous/src/bin/rzv-identify.rs | 23 ++++++++++------- examples/rendezvous/src/bin/rzv-register.rs | 25 +++++++++++-------- examples/rendezvous/src/main.rs | 19 ++++++++------ 22 files changed, 110 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 41205f470d7..dcf5364a559 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -524,7 +524,6 @@ version = "0.1.0" dependencies = [ "async-std", "clap", - "env_logger 0.10.0", "futures", "libp2p", "tracing", @@ -830,7 +829,6 @@ version = "0.1.0" dependencies = [ "async-std", "async-trait", - "env_logger 0.10.0", "futures", "libp2p", "tracing", @@ -1450,7 +1448,6 @@ version = "0.1.0" dependencies = [ "async-std", "async-trait", - "env_logger 0.10.0", "futures", "libp2p", "tracing", @@ -1708,10 +1705,11 @@ dependencies = [ "async-std", "clap", "either", - "env_logger 0.10.0", "futures", "libp2p", "serde", + "tracing", + "tracing-subscriber", "void", ] @@ -2237,6 +2235,8 @@ dependencies = [ "async-trait", "futures", "libp2p", + "tracing", + "tracing-subscriber", ] [[package]] @@ -2412,9 +2412,10 @@ version = "0.1.0" dependencies = [ "async-std", "async-trait", - "env_logger 0.10.0", "futures", "libp2p", + "tracing", + "tracing-subscriber", ] [[package]] @@ -2424,9 +2425,10 @@ dependencies = [ "async-std", "async-trait", "either", - "env_logger 0.10.0", "futures", "libp2p", + "tracing", + "tracing-subscriber", ] [[package]] @@ -3598,13 +3600,13 @@ dependencies = [ name = "metrics-example" version = "0.1.0" dependencies = [ - "env_logger 0.10.0", "futures", "hyper", "libp2p", - "log", "prometheus-client", "tokio", + "tracing", + "tracing-subscriber", ] [[package]] @@ -4635,7 +4637,6 @@ dependencies = [ "async-std", "async-trait", "clap", - "env_logger 0.10.0", "futures", "libp2p", "tracing", @@ -4648,11 +4649,11 @@ version = "0.1.0" dependencies = [ "async-std", "async-trait", - "env_logger 0.10.0", "futures", "libp2p", - "log", "tokio", + "tracing", + "tracing-subscriber", ] [[package]] diff --git a/examples/autonat/Cargo.toml b/examples/autonat/Cargo.toml index 64936bb6a9b..669e0561280 100644 --- a/examples/autonat/Cargo.toml +++ b/examples/autonat/Cargo.toml @@ -8,7 +8,6 @@ license = "MIT" [dependencies] async-std = { version = "1.12", features = ["attributes"] } clap = { version = "4.3.23", features = ["derive"] } -env_logger = "0.10.0" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "tcp", "noise", "yamux", "autonat", "identify", "macros"] } tracing = { version = "0.1.37", features = ["log"] } diff --git a/examples/chat-example/Cargo.toml b/examples/chat-example/Cargo.toml index b99f73a1f81..f2bcba671eb 100644 --- a/examples/chat-example/Cargo.toml +++ b/examples/chat-example/Cargo.toml @@ -8,7 +8,6 @@ license = "MIT" [dependencies] async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" -env_logger = "0.10.0" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "gossipsub", "mdns", "noise", "macros", "tcp", "yamux", "quic"] } tracing = { version = "0.1.37", features = ["log"] } diff --git a/examples/distributed-key-value-store/Cargo.toml b/examples/distributed-key-value-store/Cargo.toml index 13684f0e351..495bb645177 100644 --- a/examples/distributed-key-value-store/Cargo.toml +++ b/examples/distributed-key-value-store/Cargo.toml @@ -8,7 +8,6 @@ license = "MIT" [dependencies] async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" -env_logger = "0.10" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "kad", "mdns", "noise", "macros", "tcp", "websocket", "yamux"] } tracing = { version = "0.1.37", features = ["log"] } diff --git a/examples/file-sharing/Cargo.toml b/examples/file-sharing/Cargo.toml index 555a8e9c188..4cbf5766a50 100644 --- a/examples/file-sharing/Cargo.toml +++ b/examples/file-sharing/Cargo.toml @@ -10,7 +10,8 @@ serde = { version = "1.0", features = ["derive"] } async-std = { version = "1.12", features = ["attributes"] } clap = { version = "4.3.23", features = ["derive"] } either = "1.9" -env_logger = "0.10" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "cbor", "dns", "kad", "noise", "macros", "request-response", "tcp", "websocket", "yamux"] } +tracing = { version = "0.1.37", features = ["log"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } void = "1.0.2" diff --git a/examples/file-sharing/src/main.rs b/examples/file-sharing/src/main.rs index 4b6d368fc47..88e26610f48 100644 --- a/examples/file-sharing/src/main.rs +++ b/examples/file-sharing/src/main.rs @@ -31,10 +31,15 @@ use libp2p::{core::Multiaddr, multiaddr::Protocol}; use std::error::Error; use std::io::Write; use std::path::PathBuf; +use tracing_subscriber::{EnvFilter, filter::LevelFilter}; #[async_std::main] async fn main() -> Result<(), Box> { - env_logger::init(); + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::DEBUG.into()) + .from_env_lossy(); + + tracing_subscriber::fmt().with_env_filter(env_filter).init(); let opt = Opt::parse(); diff --git a/examples/identify/Cargo.toml b/examples/identify/Cargo.toml index b11ea227c61..a1ece814173 100644 --- a/examples/identify/Cargo.toml +++ b/examples/identify/Cargo.toml @@ -10,3 +10,5 @@ async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "dcutr", "identify", "macros", "noise", "ping", "relay", "rendezvous", "tcp", "tokio", "yamux"] } +tracing = { version = "0.1.37", features = ["log"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file diff --git a/examples/identify/src/main.rs b/examples/identify/src/main.rs index 7abdd5e9b92..02fedd15c97 100644 --- a/examples/identify/src/main.rs +++ b/examples/identify/src/main.rs @@ -28,9 +28,16 @@ use libp2p::{ tcp, yamux, PeerId, Transport, }; use std::error::Error; +use tracing_subscriber::{EnvFilter, filter::LevelFilter}; #[async_std::main] async fn main() -> Result<(), Box> { + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::DEBUG.into()) + .from_env_lossy(); + + tracing_subscriber::fmt().with_env_filter(env_filter).init(); + let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); println!("Local peer id: {local_peer_id:?}"); diff --git a/examples/ipfs-kad/Cargo.toml b/examples/ipfs-kad/Cargo.toml index 94587a90fbd..3329fd610cc 100644 --- a/examples/ipfs-kad/Cargo.toml +++ b/examples/ipfs-kad/Cargo.toml @@ -8,6 +8,7 @@ license = "MIT" [dependencies] async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" -env_logger = "0.10" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "kad", "noise", "tcp", "websocket", "yamux", "rsa"] } +tracing = { version = "0.1.37", features = ["log"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file diff --git a/examples/ipfs-kad/src/main.rs b/examples/ipfs-kad/src/main.rs index 1d0ed0a3b00..665225c612e 100644 --- a/examples/ipfs-kad/src/main.rs +++ b/examples/ipfs-kad/src/main.rs @@ -29,6 +29,7 @@ use libp2p::{ PeerId, }; use std::{env, error::Error, time::Duration}; +use tracing_subscriber::{EnvFilter, filter::LevelFilter}; const BOOTNODES: [&str; 4] = [ "QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN", @@ -39,7 +40,11 @@ const BOOTNODES: [&str; 4] = [ #[async_std::main] async fn main() -> Result<(), Box> { - env_logger::init(); + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::DEBUG.into()) + .from_env_lossy(); + + tracing_subscriber::fmt().with_env_filter(env_filter).init(); // Create a random key for ourselves. let local_key = identity::Keypair::generate_ed25519(); diff --git a/examples/ipfs-private/Cargo.toml b/examples/ipfs-private/Cargo.toml index 7871e5c41f5..e4d2567465b 100644 --- a/examples/ipfs-private/Cargo.toml +++ b/examples/ipfs-private/Cargo.toml @@ -9,6 +9,7 @@ license = "MIT" async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" either = "1.9" -env_logger = "0.10" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "gossipsub", "dns", "identify", "kad", "macros", "noise", "ping", "pnet", "tcp", "websocket", "yamux"] } +tracing = { version = "0.1.37", features = ["log"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file diff --git a/examples/ipfs-private/src/main.rs b/examples/ipfs-private/src/main.rs index 172131751d7..0c0b25e5d4b 100644 --- a/examples/ipfs-private/src/main.rs +++ b/examples/ipfs-private/src/main.rs @@ -33,6 +33,7 @@ use libp2p::{ tcp, yamux, Multiaddr, PeerId, Transport, }; use std::{env, error::Error, fs, path::Path, str::FromStr, time::Duration}; +use tracing_subscriber::{EnvFilter, filter::LevelFilter}; /// Builds the transport that serves as a common ground for all connections. pub fn build_transport( @@ -110,7 +111,11 @@ fn parse_legacy_multiaddr(text: &str) -> Result> { #[async_std::main] async fn main() -> Result<(), Box> { - env_logger::init(); + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::DEBUG.into()) + .from_env_lossy(); + + tracing_subscriber::fmt().with_env_filter(env_filter).init(); let ipfs_path = get_ipfs_path(); println!("using IPFS_PATH {ipfs_path:?}"); diff --git a/examples/metrics/Cargo.toml b/examples/metrics/Cargo.toml index b81c0142fd9..752e40e0baa 100644 --- a/examples/metrics/Cargo.toml +++ b/examples/metrics/Cargo.toml @@ -6,10 +6,10 @@ publish = false license = "MIT" [dependencies] -env_logger = "0.10.0" futures = "0.3.27" hyper = { version = "0.14", features = ["server", "tcp", "http1"] } libp2p = { path = "../../libp2p", features = ["async-std", "metrics", "ping", "noise", "identify", "tcp", "yamux", "macros"] } -log = "0.4.20" tokio = { version = "1", features = ["rt-multi-thread"] } prometheus-client = "0.21.2" +tracing = { version = "0.1.37", features = ["log"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file diff --git a/examples/metrics/src/http_service.rs b/examples/metrics/src/http_service.rs index 46cb7aacb84..fa46655f07c 100644 --- a/examples/metrics/src/http_service.rs +++ b/examples/metrics/src/http_service.rs @@ -21,7 +21,7 @@ use hyper::http::StatusCode; use hyper::service::Service; use hyper::{Body, Method, Request, Response, Server}; -use log::{error, info}; +use tracing::{error, info}; use prometheus_client::encoding::text::encode; use prometheus_client::registry::Registry; use std::future::Future; diff --git a/examples/metrics/src/main.rs b/examples/metrics/src/main.rs index 177ff3af09d..e846fadbcfc 100644 --- a/examples/metrics/src/main.rs +++ b/examples/metrics/src/main.rs @@ -20,7 +20,6 @@ #![doc = include_str!("../README.md")] -use env_logger::Env; use futures::executor::block_on; use futures::stream::StreamExt; use libp2p::core::{upgrade::Version, Multiaddr, Transport}; @@ -28,15 +27,20 @@ use libp2p::identity::PeerId; use libp2p::metrics::{Metrics, Recorder}; use libp2p::swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent}; use libp2p::{identify, identity, noise, ping, tcp, yamux}; -use log::info; +use tracing::info; use prometheus_client::registry::Registry; use std::error::Error; use std::thread; +use tracing_subscriber::{EnvFilter, filter::LevelFilter}; mod http_service; fn main() -> Result<(), Box> { - env_logger::Builder::from_env(Env::default().default_filter_or("info")).init(); + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::DEBUG.into()) + .from_env_lossy(); + + tracing_subscriber::fmt().with_env_filter(env_filter).init(); let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); diff --git a/examples/relay-server/Cargo.toml b/examples/relay-server/Cargo.toml index 6338b6a8c5a..b180e1d91c2 100644 --- a/examples/relay-server/Cargo.toml +++ b/examples/relay-server/Cargo.toml @@ -9,7 +9,6 @@ license = "MIT" clap = { version = "4.3.23", features = ["derive"] } async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" -env_logger = "0.10.0" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "noise", "macros", "ping", "tcp", "identify", "yamux", "relay", "quic"] } tracing = { version = "0.1.37", features = ["log"] } diff --git a/examples/relay-server/src/main.rs b/examples/relay-server/src/main.rs index 3a37ace8f64..37e3f353d10 100644 --- a/examples/relay-server/src/main.rs +++ b/examples/relay-server/src/main.rs @@ -37,8 +37,7 @@ use libp2p::{ }; use std::error::Error; use std::net::{Ipv4Addr, Ipv6Addr}; -use tracing::level_filters::LevelFilter; -use tracing_subscriber::EnvFilter; +use tracing_subscriber::{EnvFilter, filter::LevelFilter}; fn main() -> Result<(), Box> { let env_filter = EnvFilter::builder() diff --git a/examples/rendezvous/Cargo.toml b/examples/rendezvous/Cargo.toml index a66c758e018..197f7ea2a63 100644 --- a/examples/rendezvous/Cargo.toml +++ b/examples/rendezvous/Cargo.toml @@ -8,8 +8,8 @@ license = "MIT" [dependencies] async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" -env_logger = "0.10.0" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "identify", "macros", "noise", "ping", "rendezvous", "tcp", "tokio", "yamux"] } -log = "0.4" tokio = { version = "1.32", features = [ "rt-multi-thread", "macros", "time" ] } +tracing = { version = "0.1.37", features = ["log"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file diff --git a/examples/rendezvous/src/bin/rzv-discover.rs b/examples/rendezvous/src/bin/rzv-discover.rs index 710b491ff0a..5a9282dc37a 100644 --- a/examples/rendezvous/src/bin/rzv-discover.rs +++ b/examples/rendezvous/src/bin/rzv-discover.rs @@ -28,12 +28,17 @@ use libp2p::{ tcp, yamux, Multiaddr, PeerId, Transport, }; use std::time::Duration; +use tracing_subscriber::{EnvFilter, filter::LevelFilter}; const NAMESPACE: &str = "rendezvous"; #[tokio::main] async fn main() { - env_logger::init(); + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::DEBUG.into()) + .from_env_lossy(); + + tracing_subscriber::fmt().with_env_filter(env_filter).init(); let key_pair = identity::Keypair::generate_ed25519(); let rendezvous_point_address = "/ip4/127.0.0.1/tcp/62649".parse::().unwrap(); @@ -56,7 +61,7 @@ async fn main() { ) .build(); - log::info!("Local peer id: {}", swarm.local_peer_id()); + tracing::info!("Local peer id: {}", swarm.local_peer_id()); swarm.dial(rendezvous_point_address.clone()).unwrap(); @@ -67,7 +72,7 @@ async fn main() { tokio::select! { event = swarm.select_next_some() => match event { SwarmEvent::ConnectionEstablished { peer_id, .. } if peer_id == rendezvous_point => { - log::info!( + tracing::info!( "Connected to rendezvous point, discovering nodes in '{}' namespace ...", NAMESPACE ); @@ -89,7 +94,7 @@ async fn main() { for registration in registrations { for address in registration.record.addresses() { let peer = registration.record.peer_id(); - log::info!("Discovered peer {} at {}", peer, address); + tracing::info!("Discovered peer {} at {}", peer, address); let p2p_suffix = Protocol::P2p(peer); let address_with_p2p = @@ -108,10 +113,10 @@ async fn main() { result: Ok(rtt), .. })) if peer != rendezvous_point => { - log::info!("Ping to {} is {}ms", peer, rtt.as_millis()) + tracing::info!("Ping to {} is {}ms", peer, rtt.as_millis()) } other => { - log::debug!("Unhandled {:?}", other); + tracing::debug!("Unhandled {:?}", other); } }, _ = discover_tick.tick(), if cookie.is_some() => diff --git a/examples/rendezvous/src/bin/rzv-identify.rs b/examples/rendezvous/src/bin/rzv-identify.rs index 7c326688231..0f37642696a 100644 --- a/examples/rendezvous/src/bin/rzv-identify.rs +++ b/examples/rendezvous/src/bin/rzv-identify.rs @@ -26,10 +26,15 @@ use libp2p::{ tcp, yamux, Multiaddr, PeerId, Transport, }; use std::time::Duration; +use tracing_subscriber::{EnvFilter, filter::LevelFilter}; #[tokio::main] async fn main() { - env_logger::init(); + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::DEBUG.into()) + .from_env_lossy(); + + tracing_subscriber::fmt().with_env_filter(env_filter).init(); let key_pair = identity::Keypair::generate_ed25519(); let rendezvous_point_address = "/ip4/127.0.0.1/tcp/62649".parse::().unwrap(); @@ -56,7 +61,7 @@ async fn main() { ) .build(); - log::info!("Local peer id: {}", swarm.local_peer_id()); + tracing::info!("Local peer id: {}", swarm.local_peer_id()); let _ = swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse().unwrap()); @@ -65,14 +70,14 @@ async fn main() { while let Some(event) = swarm.next().await { match event { SwarmEvent::NewListenAddr { address, .. } => { - log::info!("Listening on {}", address); + tracing::info!("Listening on {}", address); } SwarmEvent::ConnectionClosed { peer_id, cause: Some(error), .. } if peer_id == rendezvous_point => { - log::error!("Lost connection to rendezvous point {}", error); + tracing::error!("Lost connection to rendezvous point {}", error); } // once `/identify` did its job, we know our external address and can register SwarmEvent::Behaviour(MyBehaviourEvent::Identify(identify::Event::Received { @@ -83,7 +88,7 @@ async fn main() { rendezvous_point, None, ) { - log::error!("Failed to register: {error}"); + tracing::error!("Failed to register: {error}"); return; } } @@ -94,7 +99,7 @@ async fn main() { rendezvous_node, }, )) => { - log::info!( + tracing::info!( "Registered for namespace '{}' at rendezvous point {} for the next {} seconds", namespace, rendezvous_node, @@ -108,7 +113,7 @@ async fn main() { error, }, )) => { - log::error!( + tracing::error!( "Failed to register: rendezvous_node={}, namespace={}, error_code={:?}", rendezvous_node, namespace, @@ -121,10 +126,10 @@ async fn main() { result: Ok(rtt), .. })) if peer != rendezvous_point => { - log::info!("Ping to {} is {}ms", peer, rtt.as_millis()) + tracing::info!("Ping to {} is {}ms", peer, rtt.as_millis()) } other => { - log::debug!("Unhandled {:?}", other); + tracing::debug!("Unhandled {:?}", other); } } } diff --git a/examples/rendezvous/src/bin/rzv-register.rs b/examples/rendezvous/src/bin/rzv-register.rs index f9fd12b1493..5a0bddf9c3e 100644 --- a/examples/rendezvous/src/bin/rzv-register.rs +++ b/examples/rendezvous/src/bin/rzv-register.rs @@ -26,10 +26,15 @@ use libp2p::{ tcp, yamux, Multiaddr, PeerId, Transport, }; use std::time::Duration; +use tracing_subscriber::{EnvFilter, filter::LevelFilter}; #[tokio::main] async fn main() { - env_logger::init(); + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::DEBUG.into()) + .from_env_lossy(); + + tracing_subscriber::fmt().with_env_filter(env_filter).init(); let key_pair = identity::Keypair::generate_ed25519(); let rendezvous_point_address = "/ip4/127.0.0.1/tcp/62649".parse::().unwrap(); @@ -57,21 +62,21 @@ async fn main() { let external_address = "/ip4/127.0.0.1/tcp/0".parse::().unwrap(); swarm.add_external_address(external_address); - log::info!("Local peer id: {}", swarm.local_peer_id()); + tracing::info!("Local peer id: {}", swarm.local_peer_id()); swarm.dial(rendezvous_point_address.clone()).unwrap(); while let Some(event) = swarm.next().await { match event { SwarmEvent::NewListenAddr { address, .. } => { - log::info!("Listening on {}", address); + tracing::info!("Listening on {}", address); } SwarmEvent::ConnectionClosed { peer_id, cause: Some(error), .. } if peer_id == rendezvous_point => { - log::error!("Lost connection to rendezvous point {}", error); + tracing::error!("Lost connection to rendezvous point {}", error); } SwarmEvent::ConnectionEstablished { peer_id, .. } if peer_id == rendezvous_point => { if let Err(error) = swarm.behaviour_mut().rendezvous.register( @@ -79,10 +84,10 @@ async fn main() { rendezvous_point, None, ) { - log::error!("Failed to register: {error}"); + tracing::error!("Failed to register: {error}"); return; } - log::info!("Connection established with rendezvous point {}", peer_id); + tracing::info!("Connection established with rendezvous point {}", peer_id); } // once `/identify` did its job, we know our external address and can register SwarmEvent::Behaviour(MyBehaviourEvent::Rendezvous( @@ -92,7 +97,7 @@ async fn main() { rendezvous_node, }, )) => { - log::info!( + tracing::info!( "Registered for namespace '{}' at rendezvous point {} for the next {} seconds", namespace, rendezvous_node, @@ -106,7 +111,7 @@ async fn main() { error, }, )) => { - log::error!( + tracing::error!( "Failed to register: rendezvous_node={}, namespace={}, error_code={:?}", rendezvous_node, namespace, @@ -119,10 +124,10 @@ async fn main() { result: Ok(rtt), .. })) if peer != rendezvous_point => { - log::info!("Ping to {} is {}ms", peer, rtt.as_millis()) + tracing::info!("Ping to {} is {}ms", peer, rtt.as_millis()) } other => { - log::debug!("Unhandled {:?}", other); + tracing::debug!("Unhandled {:?}", other); } } } diff --git a/examples/rendezvous/src/main.rs b/examples/rendezvous/src/main.rs index 4f5aca75e52..edfa2104099 100644 --- a/examples/rendezvous/src/main.rs +++ b/examples/rendezvous/src/main.rs @@ -28,10 +28,15 @@ use libp2p::{ tcp, yamux, PeerId, Transport, }; use std::time::Duration; +use tracing_subscriber::{EnvFilter, filter::LevelFilter}; #[tokio::main] async fn main() { - env_logger::init(); + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::DEBUG.into()) + .from_env_lossy(); + + tracing_subscriber::fmt().with_env_filter(env_filter).init(); let key_pair = identity::Keypair::generate_ed25519(); @@ -54,22 +59,22 @@ async fn main() { ) .build(); - log::info!("Local peer id: {}", swarm.local_peer_id()); + tracing::info!("Local peer id: {}", swarm.local_peer_id()); let _ = swarm.listen_on("/ip4/0.0.0.0/tcp/62649".parse().unwrap()); while let Some(event) = swarm.next().await { match event { SwarmEvent::ConnectionEstablished { peer_id, .. } => { - log::info!("Connected to {}", peer_id); + tracing::info!("Connected to {}", peer_id); } SwarmEvent::ConnectionClosed { peer_id, .. } => { - log::info!("Disconnected from {}", peer_id); + tracing::info!("Disconnected from {}", peer_id); } SwarmEvent::Behaviour(MyBehaviourEvent::Rendezvous( rendezvous::server::Event::PeerRegistered { peer, registration }, )) => { - log::info!( + tracing::info!( "Peer {} registered for namespace '{}'", peer, registration.namespace @@ -81,14 +86,14 @@ async fn main() { registrations, }, )) => { - log::info!( + tracing::info!( "Served peer {} with {} registrations", enquirer, registrations.len() ); } other => { - log::debug!("Unhandled {:?}", other); + tracing::debug!("Unhandled {:?}", other); } } } From 8eb986fad7f327d90443f316015e45530e6066a1 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 6 Sep 2023 18:01:22 +0300 Subject: [PATCH 021/105] fully qualified tracing usage --- examples/metrics/src/http_service.rs | 6 +- interop-tests/src/bin/wasm_ping.rs | 8 +- protocols/gossipsub/src/behaviour.rs | 240 +++++++++++++------------- protocols/gossipsub/src/handler.rs | 28 +-- protocols/gossipsub/src/mcache.rs | 8 +- protocols/gossipsub/src/peer_score.rs | 21 ++- protocols/gossipsub/src/protocol.rs | 26 +-- protocols/identify/src/handler.rs | 4 +- protocols/identify/src/protocol.rs | 12 +- protocols/kad/src/behaviour.rs | 48 +++--- protocols/kad/src/handler.rs | 22 +-- protocols/mdns/src/behaviour/iface.rs | 24 +-- protocols/perf/src/bin/perf.rs | 40 ++--- 13 files changed, 243 insertions(+), 244 deletions(-) diff --git a/examples/metrics/src/http_service.rs b/examples/metrics/src/http_service.rs index fa46655f07c..76b6ee62a33 100644 --- a/examples/metrics/src/http_service.rs +++ b/examples/metrics/src/http_service.rs @@ -21,13 +21,13 @@ use hyper::http::StatusCode; use hyper::service::Service; use hyper::{Body, Method, Request, Response, Server}; -use tracing::{error, info}; use prometheus_client::encoding::text::encode; use prometheus_client::registry::Registry; use std::future::Future; use std::pin::Pin; use std::sync::{Arc, Mutex}; use std::task::{Context, Poll}; +use tracing; const METRICS_CONTENT_TYPE: &str = "application/openmetrics-text;charset=utf-8;version=1.0.0"; @@ -39,9 +39,9 @@ pub(crate) async fn metrics_server(registry: Registry) -> Result<(), std::io::Er let rt = tokio::runtime::Runtime::new()?; rt.block_on(async { let server = Server::bind(&addr).serve(MakeMetricService::new(registry)); - info!("Metrics server on http://{}/metrics", server.local_addr()); + tracing::info!("Metrics server on http://{}/metrics", server.local_addr()); if let Err(e) = server.await { - error!("server error: {}", e); + tracing::error!("server error: {}", e); } Ok(()) }) diff --git a/interop-tests/src/bin/wasm_ping.rs b/interop-tests/src/bin/wasm_ping.rs index 83ed3c37465..409b051be5b 100644 --- a/interop-tests/src/bin/wasm_ping.rs +++ b/interop-tests/src/bin/wasm_ping.rs @@ -14,7 +14,7 @@ use tokio::process::Child; use tokio::sync::mpsc; use tower_http::cors::CorsLayer; use tower_http::trace::TraceLayer; -use tracing::{error, warn}; +use tracing; use tracing_subscriber::{fmt, prelude::*, EnvFilter}; use interop_tests::{BlpopRequest, Report}; @@ -143,14 +143,14 @@ async fn redis_blpop( ) -> Result>, StatusCode> { let client = state.0.redis_client; let mut conn = client.get_async_connection().await.map_err(|e| { - warn!("Failed to connect to redis: {e}"); + tracing::warn!("Failed to connect to redis: {e}"); StatusCode::INTERNAL_SERVER_ERROR })?; let res = conn .blpop(&request.key, request.timeout as usize) .await .map_err(|e| { - warn!( + tracing::warn!( "Failed to get list elem {} within timeout {}: {e}", request.key, request.timeout ); @@ -166,7 +166,7 @@ async fn post_results( request: Json>, ) -> Result<(), StatusCode> { state.0.results_tx.send(request.0).await.map_err(|_| { - error!("Failed to send results"); + tracing::error!("Failed to send results"); StatusCode::INTERNAL_SERVER_ERROR }) } diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index ac027a5f2a3..bf6f8ccbe16 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -31,7 +31,7 @@ use std::{ use futures::StreamExt; use futures_ticker::Ticker; -use tracing::{debug, error, trace, warn}; +use tracing; use prometheus_client::registry::Registry; use rand::{seq::SliceRandom, thread_rng}; @@ -527,14 +527,14 @@ where /// Returns [`Ok(true)`] if the subscription worked. Returns [`Ok(false)`] if we were already /// subscribed. pub fn subscribe(&mut self, topic: &Topic) -> Result { - debug!("Subscribing to topic: {}", topic); + tracing::debug!("Subscribing to topic: {}", topic); let topic_hash = topic.hash(); if !self.subscription_filter.can_subscribe(&topic_hash) { return Err(SubscriptionError::NotAllowed); } if self.mesh.get(&topic_hash).is_some() { - debug!("Topic: {} is already in the mesh.", topic); + tracing::debug!("Topic: {} is already in the mesh.", topic); return Ok(false); } @@ -552,7 +552,7 @@ where .into_protobuf(); for peer in peer_list { - debug!("Sending SUBSCRIBE to peer: {:?}", peer); + tracing::debug!("Sending SUBSCRIBE to peer: {:?}", peer); self.send_message(peer, event.clone()) .map_err(SubscriptionError::PublishError)?; } @@ -561,7 +561,7 @@ where // call JOIN(topic) // this will add new peers to the mesh for the topic self.join(&topic_hash); - debug!("Subscribed to topic: {}", topic); + tracing::debug!("Subscribed to topic: {}", topic); Ok(true) } @@ -569,11 +569,11 @@ where /// /// Returns [`Ok(true)`] if we were subscribed to this topic. pub fn unsubscribe(&mut self, topic: &Topic) -> Result { - debug!("Unsubscribing from topic: {}", topic); + tracing::debug!("Unsubscribing from topic: {}", topic); let topic_hash = topic.hash(); if self.mesh.get(&topic_hash).is_none() { - debug!("Already unsubscribed from topic: {:?}", topic_hash); + tracing::debug!("Already unsubscribed from topic: {:?}", topic_hash); // we are not subscribed return Ok(false); } @@ -592,7 +592,7 @@ where .into_protobuf(); for peer in peer_list { - debug!("Sending UNSUBSCRIBE to peer: {}", peer.to_string()); + tracing::debug!("Sending UNSUBSCRIBE to peer: {}", peer.to_string()); self.send_message(peer, event.clone())?; } } @@ -601,7 +601,7 @@ where // this will remove the topic from the mesh self.leave(&topic_hash); - debug!("Unsubscribed from topic: {:?}", topic_hash); + tracing::debug!("Unsubscribed from topic: {:?}", topic_hash); Ok(true) } @@ -645,14 +645,14 @@ where if self.duplicate_cache.contains(&msg_id) { // This message has already been seen. We don't re-publish messages that have already // been published on the network. - warn!( + tracing::warn!( "Not publishing a message that has already been published. Msg-id {}", msg_id ); return Err(PublishError::Duplicate); } - trace!("Publishing message: {:?}", msg_id); + tracing::trace!("Publishing message: {:?}", msg_id); let topic_hash = raw_message.topic.clone(); @@ -693,7 +693,7 @@ where // Gossipsub peers if self.mesh.get(&topic_hash).is_none() { - debug!("Topic: {:?} not in the mesh", topic_hash); + tracing::debug!("Topic: {:?} not in the mesh", topic_hash); // If we have fanout peers add them to the map. if self.fanout.contains_key(&topic_hash) { for peer in self.fanout.get(&topic_hash).expect("Topic must exist") { @@ -719,7 +719,7 @@ where // Add the new peers to the fanout and recipient peers self.fanout.insert(topic_hash.clone(), new_peers.clone()); for peer in new_peers { - debug!("Peer added to fanout: {:?}", peer); + tracing::debug!("Peer added to fanout: {:?}", peer); recipient_peers.insert(peer); } } @@ -750,7 +750,7 @@ where // Send to peers we know are subscribed to the topic. let msg_bytes = event.get_size(); for peer_id in recipient_peers.iter() { - trace!("Sending message to peer: {:?}", peer_id); + tracing::trace!("Sending message to peer: {:?}", peer_id); self.send_message(*peer_id, event.clone())?; if let Some(m) = self.metrics.as_mut() { @@ -758,7 +758,7 @@ where } } - debug!("Published message: {:?}", &msg_id); + tracing::debug!("Published message: {:?}", &msg_id); if let Some(metrics) = self.metrics.as_mut() { metrics.register_published_message(&topic_hash); @@ -799,7 +799,7 @@ where (raw_message.clone(), originating_peers) } None => { - warn!( + tracing::warn!( "Message not in cache. Ignoring forwarding. Message Id: {}", msg_id ); @@ -846,14 +846,14 @@ where } Ok(true) } else { - warn!("Rejected message not in cache. Message Id: {}", msg_id); + tracing::warn!("Rejected message not in cache. Message Id: {}", msg_id); Ok(false) } } /// Adds a new peer to the list of explicitly connected peers. pub fn add_explicit_peer(&mut self, peer_id: &PeerId) { - debug!("Adding explicit peer {}", peer_id); + tracing::debug!("Adding explicit peer {}", peer_id); self.explicit_peers.insert(*peer_id); @@ -863,7 +863,7 @@ where /// This removes the peer from explicitly connected peers, note that this does not disconnect /// the peer. pub fn remove_explicit_peer(&mut self, peer_id: &PeerId) { - debug!("Removing explicit peer {}", peer_id); + tracing::debug!("Removing explicit peer {}", peer_id); self.explicit_peers.remove(peer_id); } @@ -871,14 +871,14 @@ where /// created by this peer will be rejected. pub fn blacklist_peer(&mut self, peer_id: &PeerId) { if self.blacklisted_peers.insert(*peer_id) { - debug!("Peer has been blacklisted: {}", peer_id); + tracing::debug!("Peer has been blacklisted: {}", peer_id); } } /// Removes a peer from the blacklist if it has previously been blacklisted. pub fn remove_blacklisted_peer(&mut self, peer_id: &PeerId) { if self.blacklisted_peers.remove(peer_id) { - debug!("Peer has been removed from the blacklist: {}", peer_id); + tracing::debug!("Peer has been removed from the blacklist: {}", peer_id); } } @@ -947,11 +947,11 @@ where /// Gossipsub JOIN(topic) - adds topic peers to mesh and sends them GRAFT messages. fn join(&mut self, topic_hash: &TopicHash) { - debug!("Running JOIN for topic: {:?}", topic_hash); + tracing::debug!("Running JOIN for topic: {:?}", topic_hash); // if we are already in the mesh, return if self.mesh.contains_key(topic_hash) { - debug!("JOIN: The topic is already in the mesh, ignoring JOIN"); + tracing::debug!("JOIN: The topic is already in the mesh, ignoring JOIN"); return; } @@ -964,7 +964,7 @@ where // check if we have mesh_n peers in fanout[topic] and add them to the mesh if we do, // removing the fanout entry. if let Some((_, mut peers)) = self.fanout.remove_entry(topic_hash) { - debug!( + tracing::debug!( "JOIN: Removing peers from the fanout for topic: {:?}", topic_hash ); @@ -979,7 +979,7 @@ where // Add up to mesh_n of them them to the mesh // NOTE: These aren't randomly added, currently FIFO let add_peers = std::cmp::min(peers.len(), self.config.mesh_n()); - debug!( + tracing::debug!( "JOIN: Adding {:?} peers from the fanout for topic: {:?}", add_peers, topic_hash ); @@ -1016,7 +1016,7 @@ where ); added_peers.extend(new_peers.clone()); // add them to the mesh - debug!( + tracing::debug!( "JOIN: Inserting {:?} random peers into the mesh", new_peers.len() ); @@ -1031,7 +1031,7 @@ where for peer_id in added_peers { // Send a GRAFT control message - debug!("JOIN: Sending Graft message to peer: {:?}", peer_id); + tracing::debug!("JOIN: Sending Graft message to peer: {:?}", peer_id); if let Some((peer_score, ..)) = &mut self.peer_score { peer_score.graft(&peer_id, topic_hash.clone()); } @@ -1059,7 +1059,7 @@ where m.set_mesh_peers(topic_hash, mesh_peers) } - debug!("Completed JOIN for topic: {:?}", topic_hash); + tracing::debug!("Completed JOIN for topic: {:?}", topic_hash); } /// Creates a PRUNE gossipsub action. @@ -1076,7 +1076,7 @@ where match self.connected_peers.get(peer).map(|v| &v.kind) { Some(PeerKind::Floodsub) => { - error!("Attempted to prune a Floodsub peer"); + tracing::error!("Attempted to prune a Floodsub peer"); } Some(PeerKind::Gossipsub) => { // GossipSub v1.0 -- no peer exchange, the peer won't be able to parse it anyway @@ -1087,7 +1087,7 @@ where }; } None => { - error!("Attempted to Prune an unknown peer"); + tracing::error!("Attempted to Prune an unknown peer"); } _ => {} // Gossipsub 1.1 peer perform the `Prune` } @@ -1126,7 +1126,7 @@ where /// Gossipsub LEAVE(topic) - Notifies mesh\[topic\] peers with PRUNE messages. fn leave(&mut self, topic_hash: &TopicHash) { - debug!("Running LEAVE for topic {:?}", topic_hash); + tracing::debug!("Running LEAVE for topic {:?}", topic_hash); // If our mesh contains the topic, send prune to peers and delete it from the mesh if let Some((_, peers)) = self.mesh.remove_entry(topic_hash) { @@ -1135,7 +1135,7 @@ where } for peer in peers { // Send a PRUNE control message - debug!("LEAVE: Sending PRUNE to peer: {:?}", peer); + tracing::debug!("LEAVE: Sending PRUNE to peer: {:?}", peer); let on_unsubscribe = true; let control = self.make_prune(topic_hash, &peer, self.config.do_px(), on_unsubscribe); @@ -1152,14 +1152,14 @@ where ); } } - debug!("Completed LEAVE for topic: {:?}", topic_hash); + tracing::debug!("Completed LEAVE for topic: {:?}", topic_hash); } /// Checks if the given peer is still connected and if not dials the peer again. fn check_explicit_peer_connection(&mut self, peer_id: &PeerId) { if !self.peer_topics.contains_key(peer_id) { // Connect to peer - debug!("Connecting to explicit peer {:?}", peer_id); + tracing::debug!("Connecting to explicit peer {:?}", peer_id); self.events.push_back(ToSwarm::Dial { opts: DialOpts::peer_id(*peer_id).build(), }); @@ -1197,7 +1197,7 @@ where fn handle_ihave(&mut self, peer_id: &PeerId, ihave_msgs: Vec<(TopicHash, Vec)>) { // We ignore IHAVE gossip from any peer whose score is below the gossip threshold if let (true, score) = self.score_below_threshold(peer_id, |pst| pst.gossip_threshold) { - debug!( + tracing::debug!( "IHAVE: ignoring peer {:?} with score below threshold [score = {}]", peer_id, score ); @@ -1208,7 +1208,7 @@ where let peer_have = self.count_received_ihave.entry(*peer_id).or_insert(0); *peer_have += 1; if *peer_have > self.config.max_ihave_messages() { - debug!( + tracing::debug!( "IHAVE: peer {} has advertised too many times ({}) within this heartbeat \ interval; ignoring", peer_id, *peer_have @@ -1218,7 +1218,7 @@ where if let Some(iasked) = self.count_sent_iwant.get(peer_id) { if *iasked >= self.config.max_ihave_length() { - debug!( + tracing::debug!( "IHAVE: peer {} has already advertised too many messages ({}); ignoring", peer_id, *iasked ); @@ -1226,7 +1226,7 @@ where } } - trace!("Handling IHAVE for peer: {:?}", peer_id); + tracing::trace!("Handling IHAVE for peer: {:?}", peer_id); let mut iwant_ids = HashSet::new(); @@ -1248,7 +1248,7 @@ where for (topic, ids) in ihave_msgs { // only process the message if we are subscribed if !self.mesh.contains_key(&topic) { - debug!( + tracing::debug!( "IHAVE: Ignoring IHAVE - Not subscribed to topic: {:?}", topic ); @@ -1274,7 +1274,7 @@ where } // Send the list of IWANT control messages - debug!( + tracing::debug!( "IHAVE: Asking for {} out of {} messages from {}", iask, iwant_ids.len(), @@ -1301,7 +1301,7 @@ where Instant::now() + self.config.iwant_followup_time(), ); } - trace!( + tracing::trace!( "IHAVE: Asking for the following messages from {}: {:?}", peer_id, iwant_ids_vec @@ -1315,7 +1315,7 @@ where }, ); } - trace!("Completed IHAVE handling for peer: {:?}", peer_id); + tracing::trace!("Completed IHAVE handling for peer: {:?}", peer_id); } /// Handles an IWANT control message. Checks our cache of messages. If the message exists it is @@ -1323,14 +1323,14 @@ where fn handle_iwant(&mut self, peer_id: &PeerId, iwant_msgs: Vec) { // We ignore IWANT gossip from any peer whose score is below the gossip threshold if let (true, score) = self.score_below_threshold(peer_id, |pst| pst.gossip_threshold) { - debug!( + tracing::debug!( "IWANT: ignoring peer {:?} with score below threshold [score = {}]", peer_id, score ); return; } - debug!("Handling IWANT for peer: {:?}", peer_id); + tracing::debug!("Handling IWANT for peer: {:?}", peer_id); // build a hashmap of available messages let mut cached_messages = HashMap::new(); @@ -1339,7 +1339,7 @@ where // cached_messages mapping if let Some((msg, count)) = self.mcache.get_with_iwant_counts(&id, peer_id) { if count > self.config.gossip_retransimission() { - debug!( + tracing::debug!( "IWANT: Peer {} has asked for message {} too many times; ignoring \ request", peer_id, &id @@ -1351,7 +1351,7 @@ where } if !cached_messages.is_empty() { - debug!("IWANT: Sending cached messages to peer: {:?}", peer_id); + tracing::debug!("IWANT: Sending cached messages to peer: {:?}", peer_id); // Send the messages to the peer let message_list: Vec<_> = cached_messages.into_iter().map(|entry| entry.1).collect(); @@ -1370,7 +1370,7 @@ where let msg_bytes = message.get_size(); if self.send_message(*peer_id, message).is_err() { - error!("Failed to send cached messages. Messages too large"); + tracing::error!("Failed to send cached messages. Messages too large"); } else if let Some(m) = self.metrics.as_mut() { // Sending of messages succeeded, register them on the internal metrics. for topic in topics.iter() { @@ -1378,13 +1378,13 @@ where } } } - debug!("Completed IWANT handling for peer: {}", peer_id); + tracing::debug!("Completed IWANT handling for peer: {}", peer_id); } /// Handles GRAFT control messages. If subscribed to the topic, adds the peer to mesh, if not, /// responds with PRUNE messages. fn handle_graft(&mut self, peer_id: &PeerId, topics: Vec) { - debug!("Handling GRAFT message for peer: {}", peer_id); + tracing::debug!("Handling GRAFT message for peer: {}", peer_id); let mut to_prune_topics = HashSet::new(); @@ -1405,7 +1405,7 @@ where // we don't GRAFT to/from explicit peers; complain loudly if this happens if self.explicit_peers.contains(peer_id) { - warn!("GRAFT: ignoring request from direct peer {}", peer_id); + tracing::warn!("GRAFT: ignoring request from direct peer {}", peer_id); // this is possibly a bug from non-reciprocal configuration; send a PRUNE for all topics to_prune_topics = topics.into_iter().collect(); // but don't PX @@ -1417,7 +1417,7 @@ where if let Some(peers) = self.mesh.get_mut(&topic_hash) { // if the peer is already in the mesh ignore the graft if peers.contains(peer_id) { - debug!( + tracing::debug!( "GRAFT: Received graft for peer {:?} that is already in topic {:?}", peer_id, &topic_hash ); @@ -1428,7 +1428,7 @@ where if let Some(backoff_time) = self.backoffs.get_backoff_time(&topic_hash, peer_id) { if backoff_time > now { - warn!( + tracing::warn!( "[Penalty] Peer attempted graft within backoff time, penalizing {}", peer_id ); @@ -1461,7 +1461,7 @@ where // check the score if below_zero { // we don't GRAFT peers with negative score - debug!( + tracing::debug!( "GRAFT: ignoring peer {:?} with negative score [score = {}, \ topic = {}]", peer_id, score, topic_hash @@ -1483,7 +1483,7 @@ where } // add peer to the mesh - debug!( + tracing::debug!( "GRAFT: Mesh link added for peer: {:?} in topic: {:?}", peer_id, &topic_hash ); @@ -1510,7 +1510,7 @@ where } else { // don't do PX when there is an unknown topic to avoid leaking our peers do_px = false; - debug!( + tracing::debug!( "GRAFT: Received graft for unknown topic {:?} from peer {:?}", &topic_hash, peer_id ); @@ -1528,7 +1528,7 @@ where .map(|t| self.make_prune(t, peer_id, do_px, on_unsubscribe)) .collect(); // Send the prune messages to the peer - debug!( + tracing::debug!( "GRAFT: Not subscribed to topics - Sending PRUNE to peer: {}", peer_id ); @@ -1542,10 +1542,10 @@ where } .into_protobuf(), ) { - error!("Failed to send PRUNE: {:?}", e); + tracing::error!("Failed to send PRUNE: {:?}", e); } } - debug!("Completed GRAFT handling for peer: {}", peer_id); + tracing::debug!("Completed GRAFT handling for peer: {}", peer_id); } fn remove_peer_from_mesh( @@ -1560,7 +1560,7 @@ where if let Some(peers) = self.mesh.get_mut(topic_hash) { // remove the peer if it exists in the mesh if peers.remove(peer_id) { - debug!( + tracing::debug!( "PRUNE: Removing peer: {} from the mesh for topic: {}", peer_id.to_string(), topic_hash @@ -1603,7 +1603,7 @@ where peer_id: &PeerId, prune_data: Vec<(TopicHash, Vec, Option)>, ) { - debug!("Handling PRUNE message for peer: {}", peer_id); + tracing::debug!("Handling PRUNE message for peer: {}", peer_id); let (below_threshold, score) = self.score_below_threshold(peer_id, |pst| pst.accept_px_threshold); for (topic_hash, px, backoff) in prune_data { @@ -1614,7 +1614,7 @@ where if !px.is_empty() { // we ignore PX from peers with insufficient score if below_threshold { - debug!( + tracing::debug!( "PRUNE: ignoring PX from peer {:?} with insufficient score \ [score ={} topic = {}]", peer_id, score, topic_hash @@ -1634,7 +1634,7 @@ where } } } - debug!("Completed PRUNE handling for peer: {}", peer_id.to_string()); + tracing::debug!("Completed PRUNE handling for peer: {}", peer_id.to_string()); } fn px_connect(&mut self, mut px: Vec) { @@ -1674,7 +1674,7 @@ where raw_message: &mut RawMessage, propagation_source: &PeerId, ) -> bool { - debug!( + tracing::debug!( "Handling message: {:?} from peer: {}", msg_id, propagation_source.to_string() @@ -1682,7 +1682,7 @@ where // Reject any message from a blacklisted peer if self.blacklisted_peers.contains(propagation_source) { - debug!( + tracing::debug!( "Rejecting message from blacklisted peer: {}", propagation_source ); @@ -1701,7 +1701,7 @@ where // Also reject any message that originated from a blacklisted peer if let Some(source) = raw_message.source.as_ref() { if self.blacklisted_peers.contains(source) { - debug!( + tracing::debug!( "Rejecting message from peer {} because of blacklisted source: {}", propagation_source, source ); @@ -1731,7 +1731,7 @@ where }; if self_published { - debug!( + tracing::debug!( "Dropping message {} claiming to be from self but forwarded from {}", msg_id, propagation_source ); @@ -1784,7 +1784,7 @@ where let message = match self.data_transform.inbound_transform(raw_message.clone()) { Ok(message) => message, Err(e) => { - debug!("Invalid message. Transform error: {:?}", e); + tracing::debug!("Invalid message. Transform error: {:?}", e); // Reject the message and return self.handle_invalid_message( propagation_source, @@ -1814,14 +1814,14 @@ where } if !self.duplicate_cache.insert(msg_id.clone()) { - debug!("Message already received, ignoring. Message: {}", msg_id); + tracing::debug!("Message already received, ignoring. Message: {}", msg_id); if let Some((peer_score, ..)) = &mut self.peer_score { peer_score.duplicated_message(propagation_source, &msg_id, &message.topic); } self.mcache.observe_duplicate(&msg_id, propagation_source); return; } - debug!( + tracing::debug!( "Put message {:?} in duplicate_cache and resolve promises", msg_id ); @@ -1843,7 +1843,7 @@ where // Dispatch the message to the user if we are subscribed to any of the topics if self.mesh.contains_key(&message.topic) { - debug!("Sending received message to user"); + tracing::debug!("Sending received message to user"); self.events .push_back(ToSwarm::GenerateEvent(Event::Message { propagation_source: *propagation_source, @@ -1851,7 +1851,7 @@ where message, })); } else { - debug!( + tracing::debug!( "Received message on a topic we are not subscribed to: {:?}", message.topic ); @@ -1869,9 +1869,9 @@ where ) .is_err() { - error!("Failed to forward message. Too large"); + tracing::error!("Failed to forward message. Too large"); } - debug!("Completed message handling for message: {:?}", msg_id); + tracing::debug!("Completed message handling for message: {:?}", msg_id); } } @@ -1916,7 +1916,7 @@ where subscriptions: &[Subscription], propagation_source: &PeerId, ) { - debug!( + tracing::debug!( "Handling subscriptions: {:?}, from source: {}", subscriptions, propagation_source.to_string() @@ -1927,7 +1927,7 @@ where let subscribed_topics = match self.peer_topics.get_mut(propagation_source) { Some(topics) => topics, None => { - error!( + tracing::error!( "Subscription by unknown peer: {}", propagation_source.to_string() ); @@ -1947,7 +1947,7 @@ where { Ok(topics) => topics, Err(s) => { - error!( + tracing::error!( "Subscription filter error: {}; ignoring RPC from peer {}", s, propagation_source.to_string() @@ -1964,7 +1964,7 @@ where match subscription.action { SubscriptionAction::Subscribe => { if peer_list.insert(*propagation_source) { - debug!( + tracing::debug!( "SUBSCRIPTION: Adding gossip peer: {} to topic: {:?}", propagation_source.to_string(), topic_hash @@ -1996,7 +1996,7 @@ where if peers.len() < self.config.mesh_n_low() && peers.insert(*propagation_source) { - debug!( + tracing::debug!( "SUBSCRIPTION: Adding peer {} to the mesh for topic {:?}", propagation_source.to_string(), topic_hash @@ -2005,7 +2005,7 @@ where m.peers_included(topic_hash, Inclusion::Subscribed, 1) } // send graft to the peer - debug!( + tracing::debug!( "Sending GRAFT to peer {} for topic {:?}", propagation_source.to_string(), topic_hash @@ -2025,7 +2025,7 @@ where } SubscriptionAction::Unsubscribe => { if peer_list.remove(propagation_source) { - debug!( + tracing::debug!( "SUBSCRIPTION: Removing gossip peer: {} from topic: {:?}", propagation_source.to_string(), topic_hash @@ -2084,7 +2084,7 @@ where ) .is_err() { - error!("Failed sending grafts. Message too large"); + tracing::error!("Failed sending grafts. Message too large"); } // Notify the application of the subscriptions @@ -2092,7 +2092,7 @@ where self.events.push_back(event); } - trace!( + tracing::trace!( "Completed handling subscriptions from source: {:?}", propagation_source ); @@ -2112,7 +2112,7 @@ where /// Heartbeat function which shifts the memcache and updates the mesh. fn heartbeat(&mut self) { - debug!("Starting heartbeat"); + tracing::debug!("Starting heartbeat"); let start = Instant::now(); self.heartbeat_ticks += 1; @@ -2168,7 +2168,7 @@ where } if peer_score < 0.0 { - debug!( + tracing::debug!( "HEARTBEAT: Prune peer {:?} with negative score [score = {}, topic = \ {}]", peer_id, peer_score, topic_hash @@ -2191,7 +2191,7 @@ where // too little peers - add some if peers.len() < self.config.mesh_n_low() { - debug!( + tracing::debug!( "HEARTBEAT: Mesh low. Topic: {} Contains: {} needs: {}", topic_hash, peers.len(), @@ -2216,7 +2216,7 @@ where current_topic.push(topic_hash.clone()); } // update the mesh - debug!("Updating mesh, new mesh: {:?}", peer_list); + tracing::debug!("Updating mesh, new mesh: {:?}", peer_list); if let Some(m) = self.metrics.as_mut() { m.peers_included(topic_hash, Inclusion::Random, peer_list.len()) } @@ -2225,7 +2225,7 @@ where // too many peers - remove some if peers.len() > self.config.mesh_n_high() { - debug!( + tracing::debug!( "HEARTBEAT: Mesh high. Topic: {} Contains: {} needs: {}", topic_hash, peers.len(), @@ -2310,7 +2310,7 @@ where current_topic.push(topic_hash.clone()); } // update the mesh - debug!("Updating mesh, new mesh: {:?}", peer_list); + tracing::debug!("Updating mesh, new mesh: {:?}", peer_list); if let Some(m) = self.metrics.as_mut() { m.peers_included(topic_hash, Inclusion::Outbound, peer_list.len()) } @@ -2377,7 +2377,7 @@ where current_topic.push(topic_hash.clone()); } // update the mesh - debug!( + tracing::debug!( "Opportunistically graft in topic {} with peers {:?}", topic_hash, peer_list ); @@ -2400,7 +2400,7 @@ where let fanout_ttl = self.config.fanout_ttl(); self.fanout_last_pub.retain(|topic_hash, last_pub_time| { if *last_pub_time + fanout_ttl < Instant::now() { - debug!( + tracing::debug!( "HEARTBEAT: Fanout topic removed due to timeout. Topic: {:?}", topic_hash ); @@ -2425,7 +2425,7 @@ where match self.peer_topics.get(peer) { Some(topics) => { if !topics.contains(topic_hash) || peer_score < publish_threshold { - debug!( + tracing::debug!( "HEARTBEAT: Peer removed from fanout for topic: {:?}", topic_hash ); @@ -2444,7 +2444,7 @@ where // not enough peers if peers.len() < self.config.mesh_n() { - debug!( + tracing::debug!( "HEARTBEAT: Fanout low. Contains: {:?} needs: {:?}", peers.len(), self.config.mesh_n() @@ -2467,7 +2467,7 @@ where } if self.peer_score.is_some() { - trace!("Mesh message deliveries: {:?}", { + tracing::trace!("Mesh message deliveries: {:?}", { self.mesh .iter() .map(|(t, peers)| { @@ -2506,7 +2506,7 @@ where // shift the memcache self.mcache.shift(); - debug!("Completed Heartbeat"); + tracing::debug!("Completed Heartbeat"); if let Some(metrics) = self.metrics.as_mut() { let duration = u64::try_from(start.elapsed().as_millis()).unwrap_or(u64::MAX); metrics.observe_heartbeat_duration(duration); @@ -2526,7 +2526,7 @@ where // if we are emitting more than GossipSubMaxIHaveLength message_ids, truncate the list if message_ids.len() > self.config.max_ihave_length() { // we do the truncation (with shuffling) per peer below - debug!( + tracing::debug!( "too many messages for gossip; will truncate IHAVE list ({} messages)", message_ids.len() ); @@ -2555,7 +2555,7 @@ where }, ); - debug!("Gossiping IHAVE to {} peers.", to_msg_peers.len()); + tracing::debug!("Gossiping IHAVE to {} peers.", to_msg_peers.len()); for peer in to_msg_peers { let mut peer_message_ids = message_ids.clone(); @@ -2650,7 +2650,7 @@ where ) .is_err() { - error!("Failed to send control messages. Message too large"); + tracing::error!("Failed to send control messages. Message too large"); } } @@ -2690,7 +2690,7 @@ where ) .is_err() { - error!("Failed to send prune messages. Message too large"); + tracing::error!("Failed to send prune messages. Message too large"); } } } @@ -2712,7 +2712,7 @@ where } } - debug!("Forwarding message: {:?}", msg_id); + tracing::debug!("Forwarding message: {:?}", msg_id); let mut recipient_peers = HashSet::new(); { @@ -2757,13 +2757,13 @@ where let msg_bytes = event.get_size(); for peer in recipient_peers.iter() { - debug!("Sending message: {:?} to peer {:?}", msg_id, peer); + tracing::debug!("Sending message: {:?} to peer {:?}", msg_id, peer); self.send_message(*peer, event.clone())?; if let Some(m) = self.metrics.as_mut() { m.msg_sent(&message.topic, msg_bytes); } } - debug!("Completed forwarding message"); + tracing::debug!("Completed forwarding message"); Ok(true) } else { Ok(false) @@ -2886,7 +2886,7 @@ where ) .is_err() { - error!("Failed to flush control pool. Message too large"); + tracing::error!("Failed to flush control pool. Message too large"); } } @@ -2953,7 +2953,7 @@ where if object_size + 2 > self.config.max_transmit_size() { // This should not be possible. All received and published messages have already // been vetted to fit within the size. - error!("Individual message too large to fragment"); + tracing::error!("Individual message too large to fragment"); return Err(PublishError::MessageTooLarge); } @@ -3058,7 +3058,7 @@ where if let Some(ip) = get_ip_addr(endpoint.get_remote_address()) { peer_score.add_ip(&peer_id, ip); } else { - trace!( + tracing::trace!( "Couldn't extract ip from endpoint of peer {} with endpoint {:?}", peer_id, endpoint @@ -3083,9 +3083,9 @@ where if other_established == 0 { // Ignore connections from blacklisted peers. if self.blacklisted_peers.contains(&peer_id) { - debug!("Ignoring connection from blacklisted peer: {}", peer_id); + tracing::debug!("Ignoring connection from blacklisted peer: {}", peer_id); } else { - debug!("New peer connected: {}", peer_id); + tracing::debug!("New peer connected: {}", peer_id); // We need to send our subscriptions to the newly-connected node. let mut subscriptions = vec![]; for topic_hash in self.mesh.keys() { @@ -3109,7 +3109,7 @@ where ) .is_err() { - error!("Failed to send subscriptions, message too large"); + tracing::error!("Failed to send subscriptions, message too large"); } } } @@ -3138,7 +3138,7 @@ where if let Some(ip) = get_ip_addr(endpoint.get_remote_address()) { peer_score.remove_ip(&peer_id, &ip); } else { - trace!( + tracing::trace!( "Couldn't extract ip from endpoint of peer {} with endpoint {:?}", peer_id, endpoint @@ -3177,7 +3177,7 @@ where } } else { // remove from mesh, topic_peers, peer_topic and the fanout - debug!("Peer disconnected: {}", peer_id); + tracing::debug!("Peer disconnected: {}", peer_id); { let topics = match self.peer_topics.get(&peer_id) { Some(topics) => topics, @@ -3207,7 +3207,7 @@ where if let Some(peer_list) = self.topic_peers.get_mut(topic) { if !peer_list.remove(&peer_id) { // debugging purposes - warn!( + tracing::warn!( "Disconnected node: {} not in topic_peers peer list", peer_id ); @@ -3216,7 +3216,7 @@ where m.set_topic_peers(topic, peer_list.len()) } } else { - warn!( + tracing::warn!( "Disconnected node: {} with topic: {:?} not in topic_peers", &peer_id, &topic ); @@ -3270,7 +3270,7 @@ where if let Some(ip) = get_ip_addr(endpoint_old.get_remote_address()) { peer_score.remove_ip(&peer_id, &ip); } else { - trace!( + tracing::trace!( "Couldn't extract ip from endpoint of peer {} with endpoint {:?}", &peer_id, endpoint_old @@ -3279,7 +3279,7 @@ where if let Some(ip) = get_ip_addr(endpoint_new.get_remote_address()) { peer_score.add_ip(&peer_id, ip); } else { - trace!( + tracing::trace!( "Couldn't extract ip from endpoint of peer {} with endpoint {:?}", peer_id, endpoint_new @@ -3346,7 +3346,7 @@ where } if let PeerKind::NotSupported = kind { - debug!( + tracing::debug!( "Peer does not support gossipsub protocols. {}", propagation_source ); @@ -3358,7 +3358,7 @@ where // Only change the value if the old value is Floodsub (the default set in // `NetworkBehaviour::on_event` with FromSwarm::ConnectionEstablished). // All other PeerKind changes are ignored. - debug!( + tracing::debug!( "New peer type found: {} for peer: {}", kind, propagation_source ); @@ -3383,7 +3383,7 @@ where if let (true, _) = self.score_below_threshold(&propagation_source, |pst| pst.graylist_threshold) { - debug!("RPC Dropped from greylisted peer {}", propagation_source); + tracing::debug!("RPC Dropped from greylisted peer {}", propagation_source); return; } @@ -3399,7 +3399,7 @@ where } else { // log the invalid messages for (message, validation_error) in invalid_messages { - warn!( + tracing::warn!( "Invalid message. Reason: {:?} propagation_peer {} source {:?}", validation_error, propagation_source.to_string(), @@ -3414,7 +3414,7 @@ where if self.config.max_messages_per_rpc().is_some() && Some(count) >= self.config.max_messages_per_rpc() { - warn!("Received more messages than permitted. Ignoring further messages. Processed: {}", count); + tracing::warn!("Received more messages than permitted. Ignoring further messages. Processed: {}", count); break; } self.handle_received_message(raw_message, &propagation_source); @@ -3613,7 +3613,7 @@ fn get_random_peers_dynamic( // if we have less than needed, return them let n = n_map(gossip_peers.len()); if gossip_peers.len() <= n { - debug!("RANDOM PEERS: Got {:?} peers", gossip_peers.len()); + tracing::debug!("RANDOM PEERS: Got {:?} peers", gossip_peers.len()); return gossip_peers.into_iter().collect(); } @@ -3621,7 +3621,7 @@ fn get_random_peers_dynamic( let mut rng = thread_rng(); gossip_peers.partial_shuffle(&mut rng, n); - debug!("RANDOM PEERS: Got {:?} peers", n); + tracing::debug!("RANDOM PEERS: Got {:?} peers", n); gossip_peers.into_iter().take(n).collect() } diff --git a/protocols/gossipsub/src/handler.rs b/protocols/gossipsub/src/handler.rs index 8ccc3b88737..48ad95925b4 100644 --- a/protocols/gossipsub/src/handler.rs +++ b/protocols/gossipsub/src/handler.rs @@ -40,7 +40,7 @@ use std::{ task::{Context, Poll}, time::Duration, }; -use tracing::{debug, trace, warn}; +use tracing; use void::Void; /// The event emitted by the Handler. This informs the behaviour of various events created @@ -194,7 +194,7 @@ impl EnabledHandler { } // new inbound substream. Replace the current one, if it exists. - trace!("New inbound substream request"); + tracing::trace!("New inbound substream request"); self.inbound_substream = Some(InboundSubstreamState::WaitingInput(substream)); } @@ -265,7 +265,7 @@ impl EnabledHandler { return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour(message)); } Poll::Ready(Some(Err(error))) => { - debug!("Failed to read from inbound stream: {error}"); + tracing::debug!("Failed to read from inbound stream: {error}"); // Close this side of the stream. If the // peer is still around, they will re-establish their // outbound stream i.e. our inbound stream. @@ -274,7 +274,7 @@ impl EnabledHandler { } // peer closed the stream Poll::Ready(None) => { - debug!("Inbound stream closed by remote"); + tracing::debug!("Inbound stream closed by remote"); self.inbound_substream = Some(InboundSubstreamState::Closing(substream)); } @@ -292,7 +292,7 @@ impl EnabledHandler { // Don't close the connection but just drop the inbound substream. // In case the remote has more to send, they will open up a new // substream. - debug!("Inbound substream error while closing: {e}"); + tracing::debug!("Inbound substream error while closing: {e}"); } self.inbound_substream = None; break; @@ -342,14 +342,14 @@ impl EnabledHandler { Some(OutboundSubstreamState::PendingFlush(substream)) } Err(e) => { - debug!("Failed to send message on outbound stream: {e}"); + tracing::debug!("Failed to send message on outbound stream: {e}"); self.outbound_substream = None; break; } } } Poll::Ready(Err(e)) => { - debug!("Failed to send message on outbound stream: {e}"); + tracing::debug!("Failed to send message on outbound stream: {e}"); self.outbound_substream = None; break; } @@ -368,7 +368,7 @@ impl EnabledHandler { Some(OutboundSubstreamState::WaitingOutput(substream)) } Poll::Ready(Err(e)) => { - debug!("Failed to flush outbound stream: {e}"); + tracing::debug!("Failed to flush outbound stream: {e}"); self.outbound_substream = None; break; } @@ -425,7 +425,7 @@ impl ConnectionHandler for Handler { } }, Handler::Disabled(_) => { - debug!("Handler is disabled. Dropping message {:?}", message); + tracing::debug!("Handler is disabled. Dropping message {:?}", message); } } } @@ -493,7 +493,7 @@ impl ConnectionHandler for Handler { handler.inbound_substream_attempts += 1; if handler.inbound_substream_attempts == MAX_SUBSTREAM_ATTEMPTS { - warn!( + tracing::warn!( "The maximum number of inbound substreams attempts has been exceeded" ); *self = Handler::Disabled(DisabledHandler::MaxSubstreamAttempts); @@ -507,7 +507,7 @@ impl ConnectionHandler for Handler { handler.outbound_substream_attempts += 1; if handler.outbound_substream_attempts == MAX_SUBSTREAM_ATTEMPTS { - warn!( + tracing::warn!( "The maximum number of outbound substream attempts has been exceeded" ); *self = Handler::Disabled(DisabledHandler::MaxSubstreamAttempts); @@ -530,7 +530,7 @@ impl ConnectionHandler for Handler { error: StreamUpgradeError::Timeout, .. }) => { - debug!("Dial upgrade error: Protocol negotiation timeout"); + tracing::debug!("Dial upgrade error: Protocol negotiation timeout"); } ConnectionEvent::DialUpgradeError(DialUpgradeError { error: StreamUpgradeError::Apply(e), @@ -541,7 +541,7 @@ impl ConnectionHandler for Handler { .. }) => { // The protocol is not supported - debug!( + tracing::debug!( "The remote peer does not support gossipsub on this connection" ); *self = Handler::Disabled(DisabledHandler::ProtocolUnsupported { @@ -552,7 +552,7 @@ impl ConnectionHandler for Handler { error: StreamUpgradeError::Io(e), .. }) => { - debug!("Protocol negotiation failed: {e}") + tracing::debug!("Protocol negotiation failed: {e}") } ConnectionEvent::AddressChange(_) | ConnectionEvent::ListenUpgradeError(_) diff --git a/protocols/gossipsub/src/mcache.rs b/protocols/gossipsub/src/mcache.rs index be4e37bdd21..c4abcd3ac96 100644 --- a/protocols/gossipsub/src/mcache.rs +++ b/protocols/gossipsub/src/mcache.rs @@ -21,7 +21,7 @@ use crate::topic::TopicHash; use crate::types::{MessageId, RawMessage}; use libp2p_identity::PeerId; -use tracing::{debug, trace}; +use tracing; use std::collections::hash_map::Entry; use std::fmt::Debug; use std::{ @@ -87,7 +87,7 @@ impl MessageCache { entry.insert((msg, HashSet::default())); self.history[0].push(cache_entry); - trace!("Put message {:?} in mcache", message_id); + tracing::trace!("Put message {:?} in mcache", message_id); true } } @@ -191,13 +191,13 @@ impl MessageCache { // If GossipsubConfig::validate_messages is true, the implementing // application has to ensure that Gossipsub::validate_message gets called for // each received message within the cache timeout time." - debug!( + tracing::debug!( "The message with id {} got removed from the cache without being validated.", &entry.mid ); } } - trace!("Remove message from the cache: {}", &entry.mid); + tracing::trace!("Remove message from the cache: {}", &entry.mid); self.iwant_counts.remove(&entry.mid); } diff --git a/protocols/gossipsub/src/peer_score.rs b/protocols/gossipsub/src/peer_score.rs index d2b1df8935b..0601181b7ee 100644 --- a/protocols/gossipsub/src/peer_score.rs +++ b/protocols/gossipsub/src/peer_score.rs @@ -26,7 +26,6 @@ use crate::time_cache::TimeCache; use crate::{MessageId, TopicHash}; use instant::Instant; use libp2p_identity::PeerId; -use tracing::{debug, trace, warn}; use std::collections::{hash_map, HashMap, HashSet}; use std::net::IpAddr; use std::time::Duration; @@ -274,7 +273,7 @@ impl PeerScore { if let Some(metrics) = metrics.as_mut() { metrics.register_score_penalty(Penalty::MessageDeficit); } - debug!( + tracing::debug!( "[Penalty] The peer {} has a mesh message deliveries deficit of {} in topic\ {} and will get penalized by {}", peer_id, @@ -326,7 +325,7 @@ impl PeerScore { if let Some(metrics) = metrics.as_mut() { metrics.register_score_penalty(Penalty::IPColocation); } - debug!( + tracing::debug!( "[Penalty] The peer {} gets penalized because of too many peers with the ip {}. \ The surplus is {}. ", peer_id, ip, surplus @@ -347,7 +346,7 @@ impl PeerScore { pub(crate) fn add_penalty(&mut self, peer_id: &PeerId, count: usize) { if let Some(peer_stats) = self.peer_stats.get_mut(peer_id) { - debug!( + tracing::debug!( "[Penalty] Behavioral penalty for peer {}, count = {}.", peer_id, count ); @@ -445,7 +444,7 @@ impl PeerScore { /// Adds a new ip to a peer, if the peer is not yet known creates a new peer_stats entry for it pub(crate) fn add_ip(&mut self, peer_id: &PeerId, ip: IpAddr) { - trace!("Add ip for peer {}, ip: {}", peer_id, ip); + tracing::trace!("Add ip for peer {}, ip: {}", peer_id, ip); let peer_stats = self.peer_stats.entry(*peer_id).or_default(); // Mark the peer as connected (currently the default is connected, but we don't want to @@ -462,17 +461,17 @@ impl PeerScore { if let Some(peer_stats) = self.peer_stats.get_mut(peer_id) { peer_stats.known_ips.remove(ip); if let Some(peer_ids) = self.peer_ips.get_mut(ip) { - trace!("Remove ip for peer {}, ip: {}", peer_id, ip); + tracing::trace!("Remove ip for peer {}, ip: {}", peer_id, ip); peer_ids.remove(peer_id); } else { - trace!( + tracing::trace!( "No entry in peer_ips for ip {} which should get removed for peer {}", ip, peer_id ); } } else { - trace!( + tracing::trace!( "No peer_stats for peer {} which should remove the ip {}", peer_id, ip @@ -594,7 +593,7 @@ impl PeerScore { // this should be the first delivery trace if record.status != DeliveryStatus::Unknown { - warn!("Unexpected delivery trace: Message from {} was first seen {}s ago and has a delivery status {:?}", from, record.first_seen.elapsed().as_secs(), record.status); + tracing::warn!("Unexpected delivery trace: Message from {} was first seen {}s ago and has a delivery status {:?}", from, record.first_seen.elapsed().as_secs(), record.status); return; } @@ -611,7 +610,7 @@ impl PeerScore { /// Similar to `reject_message` except does not require the message id or reason for an invalid message. pub(crate) fn reject_invalid_message(&mut self, from: &PeerId, topic_hash: &TopicHash) { - debug!( + tracing::debug!( "[Penalty] Message from {} rejected because of ValidationError or SelfOrigin", from ); @@ -778,7 +777,7 @@ impl PeerScore { if let Some(topic_stats) = peer_stats.stats_or_default_mut(topic_hash.clone(), &self.params) { - debug!( + tracing::debug!( "[Penalty] Peer {} delivered an invalid message in topic {} and gets penalized \ for it", peer_id, topic_hash diff --git a/protocols/gossipsub/src/protocol.rs b/protocols/gossipsub/src/protocol.rs index 95b1a450217..f45e9e39168 100644 --- a/protocols/gossipsub/src/protocol.rs +++ b/protocols/gossipsub/src/protocol.rs @@ -34,7 +34,7 @@ use futures::prelude::*; use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; use libp2p_identity::{PeerId, PublicKey}; use libp2p_swarm::StreamProtocol; -use tracing::{debug, warn}; +use tracing; use quick_protobuf::Writer; use std::pin::Pin; use unsigned_varint::codec; @@ -169,7 +169,7 @@ impl GossipsubCodec { let from = match message.from.as_ref() { Some(v) => v, None => { - debug!("Signature verification failed: No source id given"); + tracing::debug!("Signature verification failed: No source id given"); return false; } }; @@ -177,7 +177,7 @@ impl GossipsubCodec { let source = match PeerId::from_bytes(from) { Ok(v) => v, Err(_) => { - debug!("Signature verification failed: Invalid Peer Id"); + tracing::debug!("Signature verification failed: Invalid Peer Id"); return false; } }; @@ -185,7 +185,7 @@ impl GossipsubCodec { let signature = match message.signature.as_ref() { Some(v) => v, None => { - debug!("Signature verification failed: No signature provided"); + tracing::debug!("Signature verification failed: No signature provided"); return false; } }; @@ -197,7 +197,7 @@ impl GossipsubCodec { _ => match PublicKey::try_decode_protobuf(&source.to_bytes()[2..]) { Ok(v) => v, Err(_) => { - warn!("Signature verification failed: No valid public key supplied"); + tracing::warn!("Signature verification failed: No valid public key supplied"); return false; } }, @@ -205,7 +205,7 @@ impl GossipsubCodec { // The key must match the peer_id if source != public_key.to_peer_id() { - warn!("Signature verification failed: Public key doesn't match source peer id"); + tracing::warn!("Signature verification failed: Public key doesn't match source peer id"); return false; } @@ -276,13 +276,13 @@ impl Decoder for GossipsubCodec { } ValidationMode::Anonymous => { if message.signature.is_some() { - warn!("Signature field was non-empty and anonymous validation mode is set"); + tracing::warn!("Signature field was non-empty and anonymous validation mode is set"); invalid_kind = Some(ValidationError::SignaturePresent); } else if message.seqno.is_some() { - warn!("Sequence number was non-empty and anonymous validation mode is set"); + tracing::warn!("Sequence number was non-empty and anonymous validation mode is set"); invalid_kind = Some(ValidationError::SequenceNumberPresent); } else if message.from.is_some() { - warn!("Message dropped. Message source was non-empty and anonymous validation mode is set"); + tracing::warn!("Message dropped. Message source was non-empty and anonymous validation mode is set"); invalid_kind = Some(ValidationError::MessageSourcePresent); } } @@ -308,7 +308,7 @@ impl Decoder for GossipsubCodec { // verify message signatures if required if verify_signature && !GossipsubCodec::verify_signature(&message) { - warn!("Invalid signature for received message"); + tracing::warn!("Invalid signature for received message"); // Build the invalid message (ignoring further validation of sequence number // and source) @@ -332,7 +332,7 @@ impl Decoder for GossipsubCodec { if seq_no.is_empty() { None } else if seq_no.len() != 8 { - debug!( + tracing::debug!( "Invalid sequence number length for received message. SeqNo: {:?} Size: {}", seq_no, seq_no.len() @@ -355,7 +355,7 @@ impl Decoder for GossipsubCodec { } } else { // sequence number was not present - debug!("Sequence number not present but expected"); + tracing::debug!("Sequence number not present but expected"); let message = RawMessage { source: None, // don't bother inform the application data: message.data.unwrap_or_default(), @@ -381,7 +381,7 @@ impl Decoder for GossipsubCodec { Ok(peer_id) => Some(peer_id), // valid peer id Err(_) => { // invalid peer id, add to invalid messages - debug!("Message source has an invalid PeerId"); + tracing::debug!("Message source has an invalid PeerId"); let message = RawMessage { source: None, // don't bother inform the application data: message.data.unwrap_or_default(), diff --git a/protocols/identify/src/handler.rs b/protocols/identify/src/handler.rs index 08c75e1227b..b11cad0cbc4 100644 --- a/protocols/identify/src/handler.rs +++ b/protocols/identify/src/handler.rs @@ -36,7 +36,7 @@ use libp2p_swarm::{ ConnectionHandler, ConnectionHandlerEvent, KeepAlive, StreamProtocol, StreamUpgradeError, SubstreamProtocol, SupportedProtocols, }; -use tracing::{warn, Level}; +use tracing::Level; use smallvec::SmallVec; use std::collections::HashSet; use std::{io, task::Context, task::Poll, time::Duration}; @@ -155,7 +155,7 @@ impl Handler { } future::Either::Right(fut) => { if self.inbound_identify_push.replace(fut).is_some() { - warn!( + tracing::warn!( "New inbound identify push stream from {} while still \ upgrading previous one. Replacing previous with new.", self.remote_peer_id, diff --git a/protocols/identify/src/protocol.rs b/protocols/identify/src/protocol.rs index 68ac0377ac6..8a87fe828a0 100644 --- a/protocols/identify/src/protocol.rs +++ b/protocols/identify/src/protocol.rs @@ -29,7 +29,7 @@ use libp2p_core::{ use libp2p_identity as identity; use libp2p_identity::PublicKey; use libp2p_swarm::StreamProtocol; -use tracing::{debug, trace}; +use tracing; use std::convert::TryFrom; use std::{io, iter, pin::Pin}; use thiserror::Error; @@ -154,7 +154,7 @@ pub(crate) async fn send(io: T, info: Info) -> Result<(), UpgradeError> where T: AsyncWrite + Unpin, { - trace!("Sending: {:?}", info); + tracing::trace!("Sending: {:?}", info); let listen_addrs = info .listen_addrs @@ -202,7 +202,7 @@ where .ok_or(UpgradeError::StreamClosed)?? .try_into()?; - trace!("Received: {:?}", info); + tracing::trace!("Received: {:?}", info); Ok(info) } @@ -221,7 +221,7 @@ impl TryFrom for Info { match parse_multiaddr(addr) { Ok(a) => addrs.push(a), Err(e) => { - debug!("Unable to parse multiaddr: {e:?}"); + tracing::debug!("Unable to parse multiaddr: {e:?}"); } } } @@ -233,7 +233,7 @@ impl TryFrom for Info { let observed_addr = match parse_multiaddr(msg.observedAddr.unwrap_or_default()) { Ok(a) => a, Err(e) => { - debug!("Unable to parse multiaddr: {e:?}"); + tracing::debug!("Unable to parse multiaddr: {e:?}"); Multiaddr::empty() } }; @@ -248,7 +248,7 @@ impl TryFrom for Info { .filter_map(|p| match StreamProtocol::try_from_owned(p) { Ok(p) => Some(p), Err(e) => { - debug!("Received invalid protocol from peer: {e}"); + tracing::debug!("Received invalid protocol from peer: {e}"); None } }) diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index da3cc21d1c5..0a61fb5b0b7 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -47,7 +47,7 @@ use libp2p_swarm::{ NetworkBehaviour, NotifyHandler, PollParameters, StreamProtocol, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, }; -use tracing::{debug, info, warn, trace, Level}; +use tracing::Level; use smallvec::SmallVec; use std::collections::{BTreeMap, HashMap, HashSet, VecDeque}; use std::fmt; @@ -574,7 +574,7 @@ where RoutingUpdate::Success } kbucket::InsertResult::Full => { - debug!("Bucket full. Peer not added to routing table: {}", peer); + tracing::trace!("Bucket full. Peer not added to routing table: {}", peer); RoutingUpdate::Failed } kbucket::InsertResult::Pending { disconnected } => { @@ -1027,7 +1027,7 @@ where let num_connections = self.connections.len(); - debug!( + tracing::trace!( "Re-configuring {} established connection{}", num_connections, if num_connections > 1 { "s" } else { "" } @@ -1050,7 +1050,7 @@ where fn determine_mode_from_external_addresses(&mut self) { self.mode = match (self.external_addresses.as_slice(), self.mode) { ([], Mode::Server) => { - debug!("Switching to client-mode because we no longer have any confirmed external addresses"); + tracing::trace!("Switching to client-mode because we no longer have any confirmed external addresses"); Mode::Client } @@ -1064,7 +1064,7 @@ where let confirmed_external_addresses = to_comma_separated_list(confirmed_external_addresses); - debug!("Switching to server-mode assuming that one of [{confirmed_external_addresses}] is externally reachable"); + tracing::trace!("Switching to server-mode assuming that one of [{confirmed_external_addresses}] is externally reachable"); } Mode::Server @@ -1092,9 +1092,9 @@ where let local_id = self.kbuckets.local_key().preimage(); let others_iter = peers.filter(|p| &p.node_id != local_id); if let Some(query) = self.queries.get_mut(query_id) { - trace!("Request to {:?} in query {:?} succeeded.", source, query_id); + tracing::trace!("Request to {:?} in query {:?} succeeded.", source, query_id); for peer in others_iter.clone() { - trace!( + tracing::trace!( "Peer {:?} reported by {:?} in query {:?}.", peer, source, @@ -1287,7 +1287,7 @@ where self.queued_events.push_back(ToSwarm::GenerateEvent(event)); } kbucket::InsertResult::Full => { - debug!("Bucket full. Peer not added to routing table: {}", peer); + tracing::trace!("Bucket full. Peer not added to routing table: {}", peer); let address = addresses.first().clone(); self.queued_events.push_back(ToSwarm::GenerateEvent( KademliaEvent::RoutablePeer { peer, address }, @@ -1324,7 +1324,7 @@ where /// Handles a finished (i.e. successful) query. fn query_finished(&mut self, q: Query) -> Option { let query_id = q.id(); - trace!("Query {:?} finished.", query_id); + tracing::trace!("Query {:?} finished.", query_id); let result = q.into_result(); match result.inner.info { QueryInfo::Bootstrap { @@ -1551,7 +1551,7 @@ where step: ProgressStep::first_and_last(), }), PutRecordContext::Replicate => { - debug!("Record replicated: {:?}", record.key); + tracing::trace!("Record replicated: {:?}", record.key); None } } @@ -1562,7 +1562,7 @@ where /// Handles a query that timed out. fn query_timeout(&mut self, query: Query) -> Option { let query_id = query.id(); - trace!("Query {:?} timed out.", query_id); + tracing::trace!("Query {:?} timed out.", query_id); let result = query.into_result(); match result.inner.info { QueryInfo::Bootstrap { @@ -1660,11 +1660,11 @@ where }), PutRecordContext::Replicate => match phase { PutRecordPhase::GetClosestPeers => { - warn!("Locating closest peers for replication failed: {:?}", err); + tracing::trace!("Locating closest peers for replication failed: {:?}", err); None } PutRecordPhase::PutRecord { .. } => { - debug!("Replicating record failed: {:?}", err); + tracing::trace!("Replicating record failed: {:?}", err); None } }, @@ -1764,7 +1764,7 @@ where match self.record_filtering { KademliaStoreInserts::Unfiltered => match self.store.put(record.clone()) { Ok(()) => { - debug!( + tracing::trace!( "Record stored: {:?}; {} bytes", record.key, record.value.len() @@ -1780,7 +1780,7 @@ where )); } Err(e) => { - info!("Record not stored: {:?}", e); + tracing::info!("Record not stored: {:?}", e); self.queued_events.push_back(ToSwarm::NotifyHandler { peer_id: source, handler: NotifyHandler::One(connection), @@ -1834,7 +1834,7 @@ where match self.record_filtering { KademliaStoreInserts::Unfiltered => { if let Err(e) = self.store.add_provider(record) { - info!("Provider record not stored: {:?}", e); + tracing::info!("Provider record not stored: {:?}", e); return; } @@ -1867,7 +1867,7 @@ where // of the error is not possible (and also not truly desirable or ergonomic). // The error passed in should rather be a dedicated enum. if addrs.remove(address).is_ok() { - debug!( + tracing::trace!( "Address '{}' removed from peer '{}' due to error.", address, peer_id ); @@ -1881,7 +1881,7 @@ where // into the same bucket. This is handled transparently by the // `KBucketsTable` and takes effect through `KBucketsTable::take_applied_pending` // within `Kademlia::poll`. - debug!( + tracing::trace!( "Last remaining address '{}' of peer '{}' is unreachable.", address, peer_id, ) @@ -1949,19 +1949,19 @@ where // Update routing table. if let Some(addrs) = self.kbuckets.entry(&kbucket::Key::from(peer)).value() { if addrs.replace(old, new) { - debug!( + tracing::trace!( "Address '{}' replaced with '{}' for peer '{}'.", old, new, peer ); } else { - debug!( + tracing::trace!( "Address '{}' not replaced with '{}' for peer '{}' as old address wasn't \ present.", old, new, peer ); } } else { - debug!( + tracing::trace!( "Address '{}' not replaced with '{}' for peer '{}' as peer is not present in the \ routing table.", old, new, peer @@ -2261,7 +2261,7 @@ where } KademliaHandlerEvent::QueryError { query_id, error } => { - debug!( + tracing::trace!( "Request to {:?} in query {:?} failed with {:?}", source, query_id, @@ -2353,7 +2353,7 @@ where *step = step.next(); } else { - trace!("Record with key {:?} not found at {}", key, source); + tracing::trace!("Record with key {:?} not found at {}", key, source); if let KademliaCaching::Enabled { max_peers } = self.caching { let source_key = kbucket::Key::from(source); let target_key = kbucket::Key::from(key.clone()); @@ -2394,7 +2394,7 @@ where let peers = success.clone(); let finished = query.try_finish(peers.iter()); if !finished { - debug!( + tracing::trace!( "PutRecord query ({:?}) reached quorum ({}/{}) with response \ from peer {} but could not yet finish.", query_id, diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 84c86ba7f81..e6de5de60ff 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -38,7 +38,7 @@ use libp2p_swarm::{ ConnectionHandler, ConnectionHandlerEvent, ConnectionId, KeepAlive, Stream, StreamUpgradeError, SubstreamProtocol, SupportedProtocols, }; -use tracing::{trace, debug, warn}; +use tracing; use std::collections::VecDeque; use std::task::Waker; use std::{ @@ -481,12 +481,12 @@ impl KademliaHandler { ) -> Self { match &endpoint { ConnectedPoint::Dialer { .. } => { - debug!( + tracing::debug!( "Operating in {mode}-mode on new outbound connection to {remote_peer_id}" ); } ConnectedPoint::Listener { .. } => { - debug!( + tracing::debug!( "Operating in {mode}-mode on new inbound connection to {remote_peer_id}" ); } @@ -566,13 +566,13 @@ impl KademliaHandler { ) }) { *s = InboundSubstreamState::Cancelled; - debug!( + tracing::debug!( "New inbound substream to {:?} exceeds inbound substream limit. \ Removed older substream waiting to be reused.", self.remote_peer_id, ) } else { - warn!( + tracing::warn!( "New inbound substream to {:?} exceeds inbound substream limit. \ No older substream waiting to be reused. Dropping new substream.", self.remote_peer_id, @@ -704,12 +704,12 @@ impl ConnectionHandler for KademliaHandler { match &self.endpoint { ConnectedPoint::Dialer { .. } => { - debug!( + tracing::debug!( "Now operating in {new_mode}-mode on outbound connection with {peer}" ) } ConnectedPoint::Listener { local_addr, .. } => { - debug!("Now operating in {new_mode}-mode on inbound connection with {peer} assuming that one of our external addresses routes to {local_addr}") + tracing::debug!("Now operating in {new_mode}-mode on inbound connection with {peer} assuming that one of our external addresses routes to {local_addr}") } } @@ -808,7 +808,7 @@ impl ConnectionHandler for KademliaHandler { match (remote_supports_our_kademlia_protocols, self.protocol_status) { (true, ProtocolStatus::Confirmed | ProtocolStatus::Reported) => {} (true, _) => { - debug!( + tracing::debug!( "Remote {} now supports our kademlia protocol on connection {}", self.remote_peer_id, self.connection_id, @@ -817,7 +817,7 @@ impl ConnectionHandler for KademliaHandler { self.protocol_status = ProtocolStatus::Confirmed; } (false, ProtocolStatus::Confirmed | ProtocolStatus::Reported) => { - debug!( + tracing::debug!( "Remote {} no longer supports our kademlia protocol on connection {}", self.remote_peer_id, self.connection_id, @@ -1005,7 +1005,7 @@ impl futures::Stream for InboundSubstreamState { mut substream, } => match substream.poll_next_unpin(cx) { Poll::Ready(Some(Ok(KadRequestMsg::Ping))) => { - warn!("Kademlia PING messages are unsupported"); + tracing::warn!("Kademlia PING messages are unsupported"); *this = InboundSubstreamState::Closing(substream); } @@ -1079,7 +1079,7 @@ impl futures::Stream for InboundSubstreamState { return Poll::Ready(None); } Poll::Ready(Some(Err(e))) => { - trace!("Inbound substream error: {:?}", e); + tracing::trace!("Inbound substream error: {:?}", e); return Poll::Ready(None); } }, diff --git a/protocols/mdns/src/behaviour/iface.rs b/protocols/mdns/src/behaviour/iface.rs index 11010398de0..486857bdc4f 100644 --- a/protocols/mdns/src/behaviour/iface.rs +++ b/protocols/mdns/src/behaviour/iface.rs @@ -37,7 +37,7 @@ use std::{ task::{Context, Poll}, time::{Duration, Instant}, }; -use tracing::{info, trace, debug, error}; +use tracing; /// Initial interval for starting probe const INITIAL_TIMEOUT_INTERVAL: Duration = Duration::from_millis(500); @@ -103,7 +103,7 @@ where { /// Builds a new [`InterfaceState`]. pub(crate) fn new(addr: IpAddr, config: Config, local_peer_id: PeerId) -> io::Result { - info!("creating instance on iface {}", addr); + tracing::info!("creating instance on iface {}", addr); let recv_socket = match addr { IpAddr::V4(addr) => { let socket = Socket::new(Domain::IPV4, Type::DGRAM, Some(socket2::Protocol::UDP))?; @@ -168,7 +168,7 @@ where } pub(crate) fn reset_timer(&mut self) { - trace!("reset timer on {:#?} {:#?}", self.addr, self.probe_state); + tracing::trace!("reset timer on {:#?} {:#?}", self.addr, self.probe_state); let interval = *self.probe_state.interval(); self.timeout = T::interval(interval); } @@ -185,9 +185,9 @@ where loop { // 1st priority: Low latency: Create packet ASAP after timeout. if Pin::new(&mut self.timeout).poll_next(cx).is_ready() { - trace!("sending query on iface {}", self.addr); + tracing::trace!("sending query on iface {}", self.addr); self.send_buffer.push_back(build_query()); - trace!("tick on {:#?} {:#?}", self.addr, self.probe_state); + tracing::trace!("tick on {:#?} {:#?}", self.addr, self.probe_state); // Stop to probe when the initial interval reach the query interval if let ProbeState::Probing(interval) = self.probe_state { @@ -210,11 +210,11 @@ where SocketAddr::new(self.multicast_addr, 5353), ) { Poll::Ready(Ok(_)) => { - trace!("sent packet on iface {}", self.addr); + tracing::trace!("sent packet on iface {}", self.addr); continue; } Poll::Ready(Err(err)) => { - error!("error sending packet on iface {} {}", self.addr, err); + tracing::error!("error sending packet on iface {} {}", self.addr, err); continue; } Poll::Pending => { @@ -234,7 +234,7 @@ where .map_ok(|(len, from)| MdnsPacket::new_from_bytes(&self.recv_buffer[..len], from)) { Poll::Ready(Ok(Ok(Some(MdnsPacket::Query(query))))) => { - trace!( + tracing::trace!( "received query from {} on {}", query.remote_addr(), self.addr @@ -249,7 +249,7 @@ where continue; } Poll::Ready(Ok(Ok(Some(MdnsPacket::Response(response))))) => { - trace!( + tracing::trace!( "received response from {} on {}", response.remote_addr(), self.addr @@ -266,7 +266,7 @@ where continue; } Poll::Ready(Ok(Ok(Some(MdnsPacket::ServiceDiscovery(disc))))) => { - trace!( + tracing::trace!( "received service discovery from {} on {}", disc.remote_addr(), self.addr @@ -280,10 +280,10 @@ where // No more bytes available on the socket to read } Poll::Ready(Err(err)) => { - error!("failed reading datagram: {}", err); + tracing::error!("failed reading datagram: {}", err); } Poll::Ready(Ok(Err(err))) => { - debug!("Parsing mdns packet failed: {:?}", err); + tracing::debug!("Parsing mdns packet failed: {:?}", err); } Poll::Ready(Ok(Ok(None))) | Poll::Pending => {} } diff --git a/protocols/perf/src/bin/perf.rs b/protocols/perf/src/bin/perf.rs index da7b915a796..e37eccb9e74 100644 --- a/protocols/perf/src/bin/perf.rs +++ b/protocols/perf/src/bin/perf.rs @@ -32,7 +32,7 @@ use libp2p_core::{ use libp2p_identity::PeerId; use libp2p_perf::{Run, RunDuration, RunParams}; use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent}; -use tracing::{error, info}; +use tracing; use serde::{Deserialize, Serialize}; #[derive(Debug, Parser)] @@ -123,20 +123,20 @@ async fn server(server_address: SocketAddr) -> Result<()> { loop { match swarm.next().await.unwrap() { SwarmEvent::NewListenAddr { address, .. } => { - info!("Listening on {address}"); + tracing::info!("Listening on {address}"); } SwarmEvent::IncomingConnection { .. } => {} e @ SwarmEvent::IncomingConnectionError { .. } => { - error!("{e:?}"); + tracing::error!("{e:?}"); } SwarmEvent::ConnectionEstablished { peer_id, endpoint, .. } => { - info!("Established connection to {:?} via {:?}", peer_id, endpoint); + tracing::info!("Established connection to {:?} via {:?}", peer_id, endpoint); } SwarmEvent::ConnectionClosed { .. } => {} SwarmEvent::Behaviour(()) => { - info!("Finished run",) + tracing::info!("Finished run",) } e => panic!("{e:?}"), } @@ -195,7 +195,7 @@ async fn client( } async fn custom(server_address: Multiaddr, params: RunParams) -> Result<()> { - info!("start benchmark: custom"); + tracing::info!("start benchmark: custom"); let mut swarm = swarm().await?; let start = Instant::now(); @@ -222,7 +222,7 @@ async fn custom(server_address: Multiaddr, params: RunParams) -> Result<()> { } async fn latency(server_address: Multiaddr) -> Result<()> { - info!("start benchmark: round-trip-time latency"); + tracing::info!("start benchmark: round-trip-time latency"); let mut swarm = swarm().await?; let server_peer_id = connect(&mut swarm, server_address.clone()).await?; @@ -254,12 +254,12 @@ async fn latency(server_address: Multiaddr) -> Result<()> { latencies.sort_by(|a, b| a.partial_cmp(b).unwrap()); - info!( + tracing::info!( "Finished: {rounds} pings in {:.4}s", start.elapsed().as_secs_f64() ); - info!("- {:.4} s median", percentile(&latencies, 0.50),); - info!("- {:.4} s 95th percentile\n", percentile(&latencies, 0.95),); + tracing::info!("- {:.4} s median", percentile(&latencies, 0.50),); + tracing::info!("- {:.4} s 95th percentile\n", percentile(&latencies, 0.95),); Ok(()) } @@ -269,7 +269,7 @@ fn percentile(values: &[V], percentile: f64) -> V { } async fn throughput(server_address: Multiaddr) -> Result<()> { - info!("start benchmark: single connection single channel throughput"); + tracing::info!("start benchmark: single connection single channel throughput"); let mut swarm = swarm().await?; let server_peer_id = connect(&mut swarm, server_address.clone()).await?; @@ -285,7 +285,7 @@ async fn throughput(server_address: Multiaddr) -> Result<()> { } async fn requests_per_second(server_address: Multiaddr) -> Result<()> { - info!("start benchmark: single connection parallel requests per second"); + tracing::info!("start benchmark: single connection parallel requests per second"); let mut swarm = swarm().await?; let server_peer_id = connect(&mut swarm, server_address.clone()).await?; @@ -326,16 +326,16 @@ async fn requests_per_second(server_address: Multiaddr) -> Result<()> { let duration = start.elapsed().as_secs_f64(); let requests_per_second = num as f64 / duration; - info!( + tracing::info!( "Finished: sent {num} {to_send} bytes requests with {to_receive} bytes response each within {duration:.2} s", ); - info!("- {requests_per_second:.2} req/s\n"); + tracing::info!("- {requests_per_second:.2} req/s\n"); Ok(()) } async fn sequential_connections_per_second(server_address: Multiaddr) -> Result<()> { - info!("start benchmark: sequential connections with single request per second"); + tracing::info!("start benchmark: sequential connections with single request per second"); let mut rounds = 0; let to_send = 1; let to_receive = 1; @@ -380,11 +380,11 @@ async fn sequential_connections_per_second(server_address: Multiaddr) -> Result< let connection_establishment_plus_request_95th = percentile(&latency_connection_establishment_plus_request, 0.95); - info!( + tracing::info!( "Finished: established {rounds} connections with one {to_send} bytes request and one {to_receive} bytes response within {duration:.2} s", ); - info!("- {connection_establishment_95th:.4} s 95th percentile connection establishment"); - info!("- {connection_establishment_plus_request_95th:.4} s 95th percentile connection establishment + one request"); + tracing::info!("- {connection_establishment_95th:.4} s 95th percentile connection establishment"); + tracing::info!("- {connection_establishment_plus_request_95th:.4} s 95th percentile connection establishment + one request"); Ok(()) } @@ -441,7 +441,7 @@ async fn connect( let duration = start.elapsed(); let duration_seconds = duration.as_secs_f64(); - info!("established connection in {duration_seconds:.4} s"); + tracing::info!("established connection in {duration_seconds:.4} s"); Ok(server_peer_id) } @@ -461,7 +461,7 @@ async fn perf( e => panic!("{e:?}"), }; - info!("{}", Run { params, duration }); + tracing::info!("{}", Run { params, duration }); Ok(duration) } From 79a533b3ec46af5d241513c7b4828b79c99787bf Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 6 Sep 2023 18:11:20 +0300 Subject: [PATCH 022/105] fix --- protocols/kad/src/behaviour.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index 0a61fb5b0b7..f0bbad19bc1 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -574,7 +574,7 @@ where RoutingUpdate::Success } kbucket::InsertResult::Full => { - tracing::trace!("Bucket full. Peer not added to routing table: {}", peer); + tracing::debug!("Bucket full. Peer not added to routing table: {}", peer); RoutingUpdate::Failed } kbucket::InsertResult::Pending { disconnected } => { @@ -1027,7 +1027,7 @@ where let num_connections = self.connections.len(); - tracing::trace!( + tracing::debug!( "Re-configuring {} established connection{}", num_connections, if num_connections > 1 { "s" } else { "" } @@ -1050,7 +1050,7 @@ where fn determine_mode_from_external_addresses(&mut self) { self.mode = match (self.external_addresses.as_slice(), self.mode) { ([], Mode::Server) => { - tracing::trace!("Switching to client-mode because we no longer have any confirmed external addresses"); + tracing::debug!("Switching to client-mode because we no longer have any confirmed external addresses"); Mode::Client } @@ -1064,7 +1064,7 @@ where let confirmed_external_addresses = to_comma_separated_list(confirmed_external_addresses); - tracing::trace!("Switching to server-mode assuming that one of [{confirmed_external_addresses}] is externally reachable"); + tracing::debug!("Switching to server-mode assuming that one of [{confirmed_external_addresses}] is externally reachable"); } Mode::Server @@ -1287,7 +1287,7 @@ where self.queued_events.push_back(ToSwarm::GenerateEvent(event)); } kbucket::InsertResult::Full => { - tracing::trace!("Bucket full. Peer not added to routing table: {}", peer); + tracing::debug!("Bucket full. Peer not added to routing table: {}", peer); let address = addresses.first().clone(); self.queued_events.push_back(ToSwarm::GenerateEvent( KademliaEvent::RoutablePeer { peer, address }, @@ -1551,7 +1551,7 @@ where step: ProgressStep::first_and_last(), }), PutRecordContext::Replicate => { - tracing::trace!("Record replicated: {:?}", record.key); + tracing::debug!("Record replicated: {:?}", record.key); None } } @@ -1660,11 +1660,11 @@ where }), PutRecordContext::Replicate => match phase { PutRecordPhase::GetClosestPeers => { - tracing::trace!("Locating closest peers for replication failed: {:?}", err); + tracing::warn!("Locating closest peers for replication failed: {:?}", err); None } PutRecordPhase::PutRecord { .. } => { - tracing::trace!("Replicating record failed: {:?}", err); + tracing::debug!("Replicating record failed: {:?}", err); None } }, @@ -1764,7 +1764,7 @@ where match self.record_filtering { KademliaStoreInserts::Unfiltered => match self.store.put(record.clone()) { Ok(()) => { - tracing::trace!( + tracing::debug!( "Record stored: {:?}; {} bytes", record.key, record.value.len() @@ -1867,7 +1867,7 @@ where // of the error is not possible (and also not truly desirable or ergonomic). // The error passed in should rather be a dedicated enum. if addrs.remove(address).is_ok() { - tracing::trace!( + tracing::debug!( "Address '{}' removed from peer '{}' due to error.", address, peer_id ); @@ -1881,7 +1881,7 @@ where // into the same bucket. This is handled transparently by the // `KBucketsTable` and takes effect through `KBucketsTable::take_applied_pending` // within `Kademlia::poll`. - tracing::trace!( + tracing::debug!( "Last remaining address '{}' of peer '{}' is unreachable.", address, peer_id, ) @@ -1949,19 +1949,19 @@ where // Update routing table. if let Some(addrs) = self.kbuckets.entry(&kbucket::Key::from(peer)).value() { if addrs.replace(old, new) { - tracing::trace!( + tracing::debug!( "Address '{}' replaced with '{}' for peer '{}'.", old, new, peer ); } else { - tracing::trace!( + tracing::debug!( "Address '{}' not replaced with '{}' for peer '{}' as old address wasn't \ present.", old, new, peer ); } } else { - tracing::trace!( + tracing::debug!( "Address '{}' not replaced with '{}' for peer '{}' as peer is not present in the \ routing table.", old, new, peer @@ -2261,7 +2261,7 @@ where } KademliaHandlerEvent::QueryError { query_id, error } => { - tracing::trace!( + tracing::debug!( "Request to {:?} in query {:?} failed with {:?}", source, query_id, @@ -2394,7 +2394,7 @@ where let peers = success.clone(); let finished = query.try_finish(peers.iter()); if !finished { - tracing::trace!( + tracing::debug!( "PutRecord query ({:?}) reached quorum ({}/{}) with response \ from peer {} but could not yet finish.", query_id, From 1a5c1eecd1b86038d25fe8778b4129f713bdaffa Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 6 Sep 2023 18:13:36 +0300 Subject: [PATCH 023/105] fix cargo newline issue --- examples/chat-example/Cargo.toml | 2 +- examples/distributed-key-value-store/Cargo.toml | 2 +- examples/identify/Cargo.toml | 2 +- examples/ipfs-kad/Cargo.toml | 2 +- examples/ipfs-private/Cargo.toml | 2 +- examples/metrics/Cargo.toml | 2 +- examples/ping-example/Cargo.toml | 2 +- examples/rendezvous/Cargo.toml | 2 +- protocols/ping/src/handler.rs | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/chat-example/Cargo.toml b/examples/chat-example/Cargo.toml index f2bcba671eb..1fa090d31df 100644 --- a/examples/chat-example/Cargo.toml +++ b/examples/chat-example/Cargo.toml @@ -11,4 +11,4 @@ async-trait = "0.1" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "gossipsub", "mdns", "noise", "macros", "tcp", "yamux", "quic"] } tracing = { version = "0.1.37", features = ["log"] } -tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/distributed-key-value-store/Cargo.toml b/examples/distributed-key-value-store/Cargo.toml index 495bb645177..cde4b695a35 100644 --- a/examples/distributed-key-value-store/Cargo.toml +++ b/examples/distributed-key-value-store/Cargo.toml @@ -11,4 +11,4 @@ async-trait = "0.1" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "kad", "mdns", "noise", "macros", "tcp", "websocket", "yamux"] } tracing = { version = "0.1.37", features = ["log"] } -tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/identify/Cargo.toml b/examples/identify/Cargo.toml index a1ece814173..793d78270a7 100644 --- a/examples/identify/Cargo.toml +++ b/examples/identify/Cargo.toml @@ -11,4 +11,4 @@ async-trait = "0.1" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "dcutr", "identify", "macros", "noise", "ping", "relay", "rendezvous", "tcp", "tokio", "yamux"] } tracing = { version = "0.1.37", features = ["log"] } -tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/ipfs-kad/Cargo.toml b/examples/ipfs-kad/Cargo.toml index 3329fd610cc..3083ff44827 100644 --- a/examples/ipfs-kad/Cargo.toml +++ b/examples/ipfs-kad/Cargo.toml @@ -11,4 +11,4 @@ async-trait = "0.1" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "kad", "noise", "tcp", "websocket", "yamux", "rsa"] } tracing = { version = "0.1.37", features = ["log"] } -tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/ipfs-private/Cargo.toml b/examples/ipfs-private/Cargo.toml index e4d2567465b..5979de2c73b 100644 --- a/examples/ipfs-private/Cargo.toml +++ b/examples/ipfs-private/Cargo.toml @@ -12,4 +12,4 @@ either = "1.9" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "gossipsub", "dns", "identify", "kad", "macros", "noise", "ping", "pnet", "tcp", "websocket", "yamux"] } tracing = { version = "0.1.37", features = ["log"] } -tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/metrics/Cargo.toml b/examples/metrics/Cargo.toml index 752e40e0baa..ef7c922dd57 100644 --- a/examples/metrics/Cargo.toml +++ b/examples/metrics/Cargo.toml @@ -12,4 +12,4 @@ libp2p = { path = "../../libp2p", features = ["async-std", "metrics", "ping", "n tokio = { version = "1", features = ["rt-multi-thread"] } prometheus-client = "0.21.2" tracing = { version = "0.1.37", features = ["log"] } -tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/ping-example/Cargo.toml b/examples/ping-example/Cargo.toml index 6c39aab3738..4ab2a1defe8 100644 --- a/examples/ping-example/Cargo.toml +++ b/examples/ping-example/Cargo.toml @@ -11,4 +11,4 @@ async-trait = "0.1" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "macros", "noise", "ping", "tcp", "websocket", "yamux"] } tracing = { version = "0.1.37", features = ["log"] } -tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/rendezvous/Cargo.toml b/examples/rendezvous/Cargo.toml index 197f7ea2a63..778209d1a43 100644 --- a/examples/rendezvous/Cargo.toml +++ b/examples/rendezvous/Cargo.toml @@ -12,4 +12,4 @@ futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "identify", "macros", "noise", "ping", "rendezvous", "tcp", "tokio", "yamux"] } tokio = { version = "1.32", features = [ "rt-multi-thread", "macros", "time" ] } tracing = { version = "0.1.37", features = ["log"] } -tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index c4546be20a3..ed3402c89a6 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -295,7 +295,7 @@ impl ConnectionHandler for Handler { break; } Poll::Ready(Ok((stream, rtt))) => { - tracing::event!(tracing::Level::TRACE, ?rtt); + tracing::debug!(?rtt, "ping succeeded"); self.failures = 0; self.interval.reset(self.config.interval); self.outbound = Some(OutboundState::Idle(stream)); From f6b2f6e5c5b692bba233ead815577c06501e1b85 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 6 Sep 2023 18:15:24 +0300 Subject: [PATCH 024/105] fully qualify trace usage --- examples/metrics/src/main.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/metrics/src/main.rs b/examples/metrics/src/main.rs index e846fadbcfc..df5b28a0a16 100644 --- a/examples/metrics/src/main.rs +++ b/examples/metrics/src/main.rs @@ -27,7 +27,7 @@ use libp2p::identity::PeerId; use libp2p::metrics::{Metrics, Recorder}; use libp2p::swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent}; use libp2p::{identify, identity, noise, ping, tcp, yamux}; -use tracing::info; +use tracing; use prometheus_client::registry::Registry; use std::error::Error; use std::thread; @@ -45,7 +45,7 @@ fn main() -> Result<(), Box> { let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); let local_pub_key = local_key.public(); - info!("Local peer id: {local_peer_id:?}"); + tracing::info!("Local peer id: {local_peer_id:?}"); let mut swarm = SwarmBuilder::without_executor( tcp::async_io::Transport::default() @@ -63,7 +63,7 @@ fn main() -> Result<(), Box> { if let Some(addr) = std::env::args().nth(1) { let remote: Multiaddr = addr.parse()?; swarm.dial(remote)?; - info!("Dialed {}", addr) + tracing::info!("Dialed {}", addr) } let mut metric_registry = Registry::default(); @@ -74,15 +74,15 @@ fn main() -> Result<(), Box> { loop { match swarm.select_next_some().await { SwarmEvent::Behaviour(BehaviourEvent::Ping(ping_event)) => { - info!("{:?}", ping_event); + tracing::info!("{:?}", ping_event); metrics.record(&ping_event); } SwarmEvent::Behaviour(BehaviourEvent::Identify(identify_event)) => { - info!("{:?}", identify_event); + tracing::info!("{:?}", identify_event); metrics.record(&identify_event); } swarm_event => { - info!("{:?}", swarm_event); + tracing::info!("{:?}", swarm_event); metrics.record(&swarm_event); } } From a2e9834ff53e3b7bb77de1a31272cbdf4cadb705 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 21 Sep 2023 19:25:15 +1000 Subject: [PATCH 025/105] Fix clippy lints --- examples/chat/src/main.rs | 3 +- examples/metrics/src/http_service.rs | 1 - examples/metrics/src/main.rs | 1 - interop-tests/src/bin/wasm_ping.rs | 4 +- protocols/gossipsub/src/behaviour.rs | 55 ++++++++++++++++++--------- protocols/gossipsub/src/handler.rs | 5 ++- protocols/gossipsub/src/mcache.rs | 1 - protocols/gossipsub/src/protocol.rs | 13 +++++-- protocols/identify/src/protocol.rs | 1 - protocols/kad/src/handler.rs | 1 - protocols/mdns/src/behaviour/iface.rs | 1 - protocols/perf/src/bin/perf.rs | 5 ++- swarm/src/connection.rs | 3 ++ 13 files changed, 58 insertions(+), 36 deletions(-) diff --git a/examples/chat/src/main.rs b/examples/chat/src/main.rs index 4aee16b3719..99868102282 100644 --- a/examples/chat/src/main.rs +++ b/examples/chat/src/main.rs @@ -29,11 +29,11 @@ use libp2p::{ swarm::{SwarmBuilder, SwarmEvent}, tcp, yamux, PeerId, Transport, }; -use tracing_subscriber::{EnvFilter, filter::LevelFilter}; use std::collections::hash_map::DefaultHasher; use std::error::Error; use std::hash::{Hash, Hasher}; use std::time::Duration; +use tracing_subscriber::{filter::LevelFilter, EnvFilter}; // We create a custom network behaviour that combines Gossipsub and Mdns. #[derive(NetworkBehaviour)] @@ -50,7 +50,6 @@ async fn main() -> Result<(), Box> { tracing_subscriber::fmt().with_env_filter(env_filter).init(); // Create a random PeerId - env_logger::init(); let id_keys = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(id_keys.public()); diff --git a/examples/metrics/src/http_service.rs b/examples/metrics/src/http_service.rs index 76b6ee62a33..161f9a4baa7 100644 --- a/examples/metrics/src/http_service.rs +++ b/examples/metrics/src/http_service.rs @@ -27,7 +27,6 @@ use std::future::Future; use std::pin::Pin; use std::sync::{Arc, Mutex}; use std::task::{Context, Poll}; -use tracing; const METRICS_CONTENT_TYPE: &str = "application/openmetrics-text;charset=utf-8;version=1.0.0"; diff --git a/examples/metrics/src/main.rs b/examples/metrics/src/main.rs index a115f9a4a15..7dc04b61e40 100644 --- a/examples/metrics/src/main.rs +++ b/examples/metrics/src/main.rs @@ -31,7 +31,6 @@ use prometheus_client::registry::Registry; use std::error::Error; use std::thread; use std::time::Duration; -use tracing; use tracing_subscriber::{filter::LevelFilter, EnvFilter}; mod http_service; diff --git a/interop-tests/src/bin/wasm_ping.rs b/interop-tests/src/bin/wasm_ping.rs index 7b6eadd53dc..7977c59f048 100644 --- a/interop-tests/src/bin/wasm_ping.rs +++ b/interop-tests/src/bin/wasm_ping.rs @@ -15,7 +15,6 @@ use tokio::process::Child; use tokio::sync::mpsc; use tower_http::cors::CorsLayer; use tower_http::trace::TraceLayer; -use tracing; use tracing_subscriber::{fmt, prelude::*, EnvFilter}; use interop_tests::{BlpopRequest, Report}; @@ -153,7 +152,8 @@ async fn redis_blpop( .map_err(|e| { tracing::warn!( "Failed to get list elem {} within timeout {}: {e}", - request.key, request.timeout + request.key, + request.timeout ); StatusCode::INTERNAL_SERVER_ERROR })?; diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index bf6f8ccbe16..30210e7c8c1 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -31,7 +31,6 @@ use std::{ use futures::StreamExt; use futures_ticker::Ticker; -use tracing; use prometheus_client::registry::Registry; use rand::{seq::SliceRandom, thread_rng}; @@ -981,7 +980,8 @@ where let add_peers = std::cmp::min(peers.len(), self.config.mesh_n()); tracing::debug!( "JOIN: Adding {:?} peers from the fanout for topic: {:?}", - add_peers, topic_hash + add_peers, + topic_hash ); added_peers.extend(peers.iter().cloned().take(add_peers)); @@ -1199,7 +1199,8 @@ where if let (true, score) = self.score_below_threshold(peer_id, |pst| pst.gossip_threshold) { tracing::debug!( "IHAVE: ignoring peer {:?} with score below threshold [score = {}]", - peer_id, score + peer_id, + score ); return; } @@ -1211,7 +1212,8 @@ where tracing::debug!( "IHAVE: peer {} has advertised too many times ({}) within this heartbeat \ interval; ignoring", - peer_id, *peer_have + peer_id, + *peer_have ); return; } @@ -1220,7 +1222,8 @@ where if *iasked >= self.config.max_ihave_length() { tracing::debug!( "IHAVE: peer {} has already advertised too many messages ({}); ignoring", - peer_id, *iasked + peer_id, + *iasked ); return; } @@ -1325,7 +1328,8 @@ where if let (true, score) = self.score_below_threshold(peer_id, |pst| pst.gossip_threshold) { tracing::debug!( "IWANT: ignoring peer {:?} with score below threshold [score = {}]", - peer_id, score + peer_id, + score ); return; } @@ -1342,7 +1346,8 @@ where tracing::debug!( "IWANT: Peer {} has asked for message {} too many times; ignoring \ request", - peer_id, &id + peer_id, + &id ); } else { cached_messages.insert(id.clone(), msg.clone()); @@ -1419,7 +1424,8 @@ where if peers.contains(peer_id) { tracing::debug!( "GRAFT: Received graft for peer {:?} that is already in topic {:?}", - peer_id, &topic_hash + peer_id, + &topic_hash ); continue; } @@ -1464,7 +1470,9 @@ where tracing::debug!( "GRAFT: ignoring peer {:?} with negative score [score = {}, \ topic = {}]", - peer_id, score, topic_hash + peer_id, + score, + topic_hash ); // we do send them PRUNE however, because it's a matter of protocol correctness to_prune_topics.insert(topic_hash.clone()); @@ -1485,7 +1493,8 @@ where // add peer to the mesh tracing::debug!( "GRAFT: Mesh link added for peer: {:?} in topic: {:?}", - peer_id, &topic_hash + peer_id, + &topic_hash ); if peers.insert(*peer_id) { @@ -1512,7 +1521,8 @@ where do_px = false; tracing::debug!( "GRAFT: Received graft for unknown topic {:?} from peer {:?}", - &topic_hash, peer_id + &topic_hash, + peer_id ); // spam hardening: ignore GRAFTs for unknown topics continue; @@ -1617,7 +1627,9 @@ where tracing::debug!( "PRUNE: ignoring PX from peer {:?} with insufficient score \ [score ={} topic = {}]", - peer_id, score, topic_hash + peer_id, + score, + topic_hash ); continue; } @@ -1703,7 +1715,8 @@ where if self.blacklisted_peers.contains(source) { tracing::debug!( "Rejecting message from peer {} because of blacklisted source: {}", - propagation_source, source + propagation_source, + source ); self.handle_invalid_message( propagation_source, @@ -1733,7 +1746,8 @@ where if self_published { tracing::debug!( "Dropping message {} claiming to be from self but forwarded from {}", - msg_id, propagation_source + msg_id, + propagation_source ); self.handle_invalid_message(propagation_source, raw_message, RejectReason::SelfOrigin); return false; @@ -2171,7 +2185,9 @@ where tracing::debug!( "HEARTBEAT: Prune peer {:?} with negative score [score = {}, topic = \ {}]", - peer_id, peer_score, topic_hash + peer_id, + peer_score, + topic_hash ); let current_topic = to_prune.entry(*peer_id).or_insert_with(Vec::new); @@ -2379,7 +2395,8 @@ where // update the mesh tracing::debug!( "Opportunistically graft in topic {} with peers {:?}", - topic_hash, peer_list + topic_hash, + peer_list ); if let Some(m) = self.metrics.as_mut() { m.peers_included(topic_hash, Inclusion::Random, peer_list.len()) @@ -3218,7 +3235,8 @@ where } else { tracing::warn!( "Disconnected node: {} with topic: {:?} not in topic_peers", - &peer_id, &topic + &peer_id, + &topic ); } @@ -3360,7 +3378,8 @@ where // All other PeerKind changes are ignored. tracing::debug!( "New peer type found: {} for peer: {}", - kind, propagation_source + kind, + propagation_source ); if let PeerKind::Floodsub = conn.kind { conn.kind = kind; diff --git a/protocols/gossipsub/src/handler.rs b/protocols/gossipsub/src/handler.rs index 48ad95925b4..1cd7f26b554 100644 --- a/protocols/gossipsub/src/handler.rs +++ b/protocols/gossipsub/src/handler.rs @@ -40,7 +40,6 @@ use std::{ task::{Context, Poll}, time::Duration, }; -use tracing; use void::Void; /// The event emitted by the Handler. This informs the behaviour of various events created @@ -342,7 +341,9 @@ impl EnabledHandler { Some(OutboundSubstreamState::PendingFlush(substream)) } Err(e) => { - tracing::debug!("Failed to send message on outbound stream: {e}"); + tracing::debug!( + "Failed to send message on outbound stream: {e}" + ); self.outbound_substream = None; break; } diff --git a/protocols/gossipsub/src/mcache.rs b/protocols/gossipsub/src/mcache.rs index c4abcd3ac96..024caa27954 100644 --- a/protocols/gossipsub/src/mcache.rs +++ b/protocols/gossipsub/src/mcache.rs @@ -21,7 +21,6 @@ use crate::topic::TopicHash; use crate::types::{MessageId, RawMessage}; use libp2p_identity::PeerId; -use tracing; use std::collections::hash_map::Entry; use std::fmt::Debug; use std::{ diff --git a/protocols/gossipsub/src/protocol.rs b/protocols/gossipsub/src/protocol.rs index f45e9e39168..e8a8739be8c 100644 --- a/protocols/gossipsub/src/protocol.rs +++ b/protocols/gossipsub/src/protocol.rs @@ -34,7 +34,6 @@ use futures::prelude::*; use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; use libp2p_identity::{PeerId, PublicKey}; use libp2p_swarm::StreamProtocol; -use tracing; use quick_protobuf::Writer; use std::pin::Pin; use unsigned_varint::codec; @@ -205,7 +204,9 @@ impl GossipsubCodec { // The key must match the peer_id if source != public_key.to_peer_id() { - tracing::warn!("Signature verification failed: Public key doesn't match source peer id"); + tracing::warn!( + "Signature verification failed: Public key doesn't match source peer id" + ); return false; } @@ -276,10 +277,14 @@ impl Decoder for GossipsubCodec { } ValidationMode::Anonymous => { if message.signature.is_some() { - tracing::warn!("Signature field was non-empty and anonymous validation mode is set"); + tracing::warn!( + "Signature field was non-empty and anonymous validation mode is set" + ); invalid_kind = Some(ValidationError::SignaturePresent); } else if message.seqno.is_some() { - tracing::warn!("Sequence number was non-empty and anonymous validation mode is set"); + tracing::warn!( + "Sequence number was non-empty and anonymous validation mode is set" + ); invalid_kind = Some(ValidationError::SequenceNumberPresent); } else if message.from.is_some() { tracing::warn!("Message dropped. Message source was non-empty and anonymous validation mode is set"); diff --git a/protocols/identify/src/protocol.rs b/protocols/identify/src/protocol.rs index 8a87fe828a0..c4d528768e8 100644 --- a/protocols/identify/src/protocol.rs +++ b/protocols/identify/src/protocol.rs @@ -29,7 +29,6 @@ use libp2p_core::{ use libp2p_identity as identity; use libp2p_identity::PublicKey; use libp2p_swarm::StreamProtocol; -use tracing; use std::convert::TryFrom; use std::{io, iter, pin::Pin}; use thiserror::Error; diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index e6de5de60ff..b70406b6d45 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -38,7 +38,6 @@ use libp2p_swarm::{ ConnectionHandler, ConnectionHandlerEvent, ConnectionId, KeepAlive, Stream, StreamUpgradeError, SubstreamProtocol, SupportedProtocols, }; -use tracing; use std::collections::VecDeque; use std::task::Waker; use std::{ diff --git a/protocols/mdns/src/behaviour/iface.rs b/protocols/mdns/src/behaviour/iface.rs index 486857bdc4f..408db2ee763 100644 --- a/protocols/mdns/src/behaviour/iface.rs +++ b/protocols/mdns/src/behaviour/iface.rs @@ -37,7 +37,6 @@ use std::{ task::{Context, Poll}, time::{Duration, Instant}, }; -use tracing; /// Initial interval for starting probe const INITIAL_TIMEOUT_INTERVAL: Duration = Duration::from_millis(500); diff --git a/protocols/perf/src/bin/perf.rs b/protocols/perf/src/bin/perf.rs index e37eccb9e74..35b38048f79 100644 --- a/protocols/perf/src/bin/perf.rs +++ b/protocols/perf/src/bin/perf.rs @@ -32,7 +32,6 @@ use libp2p_core::{ use libp2p_identity::PeerId; use libp2p_perf::{Run, RunDuration, RunParams}; use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent}; -use tracing; use serde::{Deserialize, Serialize}; #[derive(Debug, Parser)] @@ -383,7 +382,9 @@ async fn sequential_connections_per_second(server_address: Multiaddr) -> Result< tracing::info!( "Finished: established {rounds} connections with one {to_send} bytes request and one {to_receive} bytes response within {duration:.2} s", ); - tracing::info!("- {connection_establishment_95th:.4} s 95th percentile connection establishment"); + tracing::info!( + "- {connection_establishment_95th:.4} s 95th percentile connection establishment" + ); tracing::info!("- {connection_establishment_plus_request_95th:.4} s 95th percentile connection establishment + one request"); Ok(()) diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 6bf64f6a312..4a9262fb015 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -892,6 +892,7 @@ mod tests { None, 0, idle_timeout, + tracing::Span::none(), ); assert!(connection.poll_noop_waker().is_pending()); @@ -916,6 +917,7 @@ mod tests { None, 0, idle_timeout, + tracing::Span::none(), ); assert!(connection.poll_noop_waker().is_pending()); @@ -947,6 +949,7 @@ mod tests { None, 0, idle_timeout, + tracing::Span::none(), ); assert!(connection.poll_noop_waker().is_pending()); From e8d77452cdd427c00e3af3b795c89569f96396d7 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 21 Sep 2023 19:26:24 +1000 Subject: [PATCH 026/105] Fix formatting --- .../distributed-key-value-store/src/main.rs | 2 +- examples/file-sharing/src/main.rs | 2 +- examples/ipfs-kad/src/main.rs | 2 +- examples/ipfs-private/src/main.rs | 2 +- examples/relay-server/src/main.rs | 2 +- protocols/gossipsub/src/gossip_promises.rs | 3 +- protocols/gossipsub/src/peer_score.rs | 3 +- .../gossipsub/src/subscription_filter.rs | 2 +- protocols/identify/src/handler.rs | 2 +- protocols/kad/src/behaviour.rs | 30 ++++++++++++++----- protocols/mdns/src/behaviour.rs | 4 ++- protocols/rendezvous/src/server.rs | 4 ++- 12 files changed, 39 insertions(+), 19 deletions(-) diff --git a/examples/distributed-key-value-store/src/main.rs b/examples/distributed-key-value-store/src/main.rs index 447c9195adc..83720c904f4 100644 --- a/examples/distributed-key-value-store/src/main.rs +++ b/examples/distributed-key-value-store/src/main.rs @@ -35,7 +35,7 @@ use libp2p::{ tcp, yamux, PeerId, Transport, }; use std::error::Error; -use tracing_subscriber::{EnvFilter, filter::LevelFilter}; +use tracing_subscriber::{filter::LevelFilter, EnvFilter}; #[async_std::main] async fn main() -> Result<(), Box> { diff --git a/examples/file-sharing/src/main.rs b/examples/file-sharing/src/main.rs index 88e26610f48..482abd57c0d 100644 --- a/examples/file-sharing/src/main.rs +++ b/examples/file-sharing/src/main.rs @@ -31,7 +31,7 @@ use libp2p::{core::Multiaddr, multiaddr::Protocol}; use std::error::Error; use std::io::Write; use std::path::PathBuf; -use tracing_subscriber::{EnvFilter, filter::LevelFilter}; +use tracing_subscriber::{filter::LevelFilter, EnvFilter}; #[async_std::main] async fn main() -> Result<(), Box> { diff --git a/examples/ipfs-kad/src/main.rs b/examples/ipfs-kad/src/main.rs index 665225c612e..cb75db86733 100644 --- a/examples/ipfs-kad/src/main.rs +++ b/examples/ipfs-kad/src/main.rs @@ -29,7 +29,7 @@ use libp2p::{ PeerId, }; use std::{env, error::Error, time::Duration}; -use tracing_subscriber::{EnvFilter, filter::LevelFilter}; +use tracing_subscriber::{filter::LevelFilter, EnvFilter}; const BOOTNODES: [&str; 4] = [ "QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN", diff --git a/examples/ipfs-private/src/main.rs b/examples/ipfs-private/src/main.rs index 0c0b25e5d4b..f01ebd53288 100644 --- a/examples/ipfs-private/src/main.rs +++ b/examples/ipfs-private/src/main.rs @@ -33,7 +33,7 @@ use libp2p::{ tcp, yamux, Multiaddr, PeerId, Transport, }; use std::{env, error::Error, fs, path::Path, str::FromStr, time::Duration}; -use tracing_subscriber::{EnvFilter, filter::LevelFilter}; +use tracing_subscriber::{filter::LevelFilter, EnvFilter}; /// Builds the transport that serves as a common ground for all connections. pub fn build_transport( diff --git a/examples/relay-server/src/main.rs b/examples/relay-server/src/main.rs index ee9d9979c4b..a3581b07f0e 100644 --- a/examples/relay-server/src/main.rs +++ b/examples/relay-server/src/main.rs @@ -37,7 +37,7 @@ use libp2p::{ }; use std::error::Error; use std::net::{Ipv4Addr, Ipv6Addr}; -use tracing_subscriber::{EnvFilter, filter::LevelFilter}; +use tracing_subscriber::{filter::LevelFilter, EnvFilter}; fn main() -> Result<(), Box> { let env_filter = EnvFilter::builder() diff --git a/protocols/gossipsub/src/gossip_promises.rs b/protocols/gossipsub/src/gossip_promises.rs index 04335a9944c..ed56126845a 100644 --- a/protocols/gossipsub/src/gossip_promises.rs +++ b/protocols/gossipsub/src/gossip_promises.rs @@ -86,7 +86,8 @@ impl GossipPromises { *count += 1; tracing::debug!( "[Penalty] The peer {} broke the promise to deliver message {} in time!", - peer_id, msg + peer_id, + msg ); false } else { diff --git a/protocols/gossipsub/src/peer_score.rs b/protocols/gossipsub/src/peer_score.rs index 0601181b7ee..7120224015a 100644 --- a/protocols/gossipsub/src/peer_score.rs +++ b/protocols/gossipsub/src/peer_score.rs @@ -348,7 +348,8 @@ impl PeerScore { if let Some(peer_stats) = self.peer_stats.get_mut(peer_id) { tracing::debug!( "[Penalty] Behavioral penalty for peer {}, count = {}.", - peer_id, count + peer_id, + count ); peer_stats.behaviour_penalty += count as f64; } diff --git a/protocols/gossipsub/src/subscription_filter.rs b/protocols/gossipsub/src/subscription_filter.rs index cf68cb7f0f3..cc8677d1c60 100644 --- a/protocols/gossipsub/src/subscription_filter.rs +++ b/protocols/gossipsub/src/subscription_filter.rs @@ -20,8 +20,8 @@ use crate::types::Subscription; use crate::TopicHash; -use tracing::debug; use std::collections::{BTreeSet, HashMap, HashSet}; +use tracing::debug; pub trait TopicSubscriptionFilter { /// Returns true iff the topic is of interest and we can subscribe to it. diff --git a/protocols/identify/src/handler.rs b/protocols/identify/src/handler.rs index b11cad0cbc4..6a51d80a5c9 100644 --- a/protocols/identify/src/handler.rs +++ b/protocols/identify/src/handler.rs @@ -36,10 +36,10 @@ use libp2p_swarm::{ ConnectionHandler, ConnectionHandlerEvent, KeepAlive, StreamProtocol, StreamUpgradeError, SubstreamProtocol, SupportedProtocols, }; -use tracing::Level; use smallvec::SmallVec; use std::collections::HashSet; use std::{io, task::Context, task::Poll, time::Duration}; +use tracing::Level; /// Protocol handler for sending and receiving identification requests. /// diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index f0bbad19bc1..9796d44396c 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -47,7 +47,6 @@ use libp2p_swarm::{ NetworkBehaviour, NotifyHandler, PollParameters, StreamProtocol, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, }; -use tracing::Level; use smallvec::SmallVec; use std::collections::{BTreeMap, HashMap, HashSet, VecDeque}; use std::fmt; @@ -56,6 +55,7 @@ use std::task::{Context, Poll, Waker}; use std::time::Duration; use std::vec; use thiserror::Error; +use tracing::Level; pub use crate::query::QueryStats; @@ -1287,7 +1287,10 @@ where self.queued_events.push_back(ToSwarm::GenerateEvent(event)); } kbucket::InsertResult::Full => { - tracing::debug!("Bucket full. Peer not added to routing table: {}", peer); + tracing::debug!( + "Bucket full. Peer not added to routing table: {}", + peer + ); let address = addresses.first().clone(); self.queued_events.push_back(ToSwarm::GenerateEvent( KademliaEvent::RoutablePeer { peer, address }, @@ -1660,7 +1663,10 @@ where }), PutRecordContext::Replicate => match phase { PutRecordPhase::GetClosestPeers => { - tracing::warn!("Locating closest peers for replication failed: {:?}", err); + tracing::warn!( + "Locating closest peers for replication failed: {:?}", + err + ); None } PutRecordPhase::PutRecord { .. } => { @@ -1869,7 +1875,8 @@ where if addrs.remove(address).is_ok() { tracing::debug!( "Address '{}' removed from peer '{}' due to error.", - address, peer_id + address, + peer_id ); } else { // Despite apparently having no reachable address (any longer), @@ -1883,7 +1890,8 @@ where // within `Kademlia::poll`. tracing::debug!( "Last remaining address '{}' of peer '{}' is unreachable.", - address, peer_id, + address, + peer_id, ) } } @@ -1951,20 +1959,26 @@ where if addrs.replace(old, new) { tracing::debug!( "Address '{}' replaced with '{}' for peer '{}'.", - old, new, peer + old, + new, + peer ); } else { tracing::debug!( "Address '{}' not replaced with '{}' for peer '{}' as old address wasn't \ present.", - old, new, peer + old, + new, + peer ); } } else { tracing::debug!( "Address '{}' not replaced with '{}' for peer '{}' as peer is not present in the \ routing table.", - old, new, peer + old, + new, + peer ); } diff --git a/protocols/mdns/src/behaviour.rs b/protocols/mdns/src/behaviour.rs index 71d3714b91e..fa31004537f 100644 --- a/protocols/mdns/src/behaviour.rs +++ b/protocols/mdns/src/behaviour.rs @@ -272,7 +272,9 @@ where Ok(iface_state) => { e.insert(iface_state); } - Err(err) => tracing::error!("failed to create `InterfaceState`: {}", err), + Err(err) => { + tracing::error!("failed to create `InterfaceState`: {}", err) + } } } } diff --git a/protocols/rendezvous/src/server.rs b/protocols/rendezvous/src/server.rs index 7c97bb33cfe..78b68c3cf13 100644 --- a/protocols/rendezvous/src/server.rs +++ b/protocols/rendezvous/src/server.rs @@ -195,7 +195,9 @@ impl NetworkBehaviour for Behaviour { request_id, error, }) => { - tracing::warn!("Inbound request {request_id} with peer {peer} failed: {error}"); + tracing::warn!( + "Inbound request {request_id} with peer {peer} failed: {error}" + ); continue; } From b8473fdd78747254afc6432a4c755b430576388a Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 21 Sep 2023 19:27:21 +1000 Subject: [PATCH 027/105] Fix wasm compile error --- swarm/Cargo.toml | 2 +- swarm/src/connection.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index ecdf2e151e4..5561ae9c765 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -27,11 +27,11 @@ wasm-bindgen-futures = { version = "0.4.37", optional = true } getrandom = { version = "0.2.9", features = ["js"], optional = true } # Explicit dependency to be used in `wasm-bindgen` feature once_cell = "1.18.0" multistream-select = { workspace = true } +tracing = "0.1.37" [target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies] async-std = { version = "1.6.2", optional = true } tokio = { version = "1.32", features = ["rt"], optional = true } -tracing = "0.1.37" [features] macros = ["dep:libp2p-swarm-derive"] diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 4a9262fb015..c4c24e636fd 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -28,7 +28,6 @@ pub(crate) use error::{ PendingConnectionError, PendingInboundConnectionError, PendingOutboundConnectionError, }; pub use supported_protocols::SupportedProtocols; -use tracing::Span; use crate::handler::{ AddressChange, ConnectionEvent, ConnectionHandler, DialUpgradeError, FullyNegotiatedInbound, @@ -61,6 +60,7 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::task::Waker; use std::time::Duration; use std::{fmt, io, mem, pin::Pin, task::Context, task::Poll}; +use tracing::Span; static NEXT_CONNECTION_ID: AtomicUsize = AtomicUsize::new(1); From b9a7949a94e27341748e1be940f8ba05526ecfab Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 21 Sep 2023 18:25:25 +0300 Subject: [PATCH 028/105] added improved tracing for autonat, dcutr, floodsub, gossipsub --- examples/rendezvous/src/bin/rzv-discover.rs | 4 +- protocols/autonat/src/behaviour/as_client.rs | 6 +- protocols/dcutr/src/protocol/inbound.rs | 2 +- protocols/dcutr/src/protocol/outbound.rs | 2 +- protocols/gossipsub/src/behaviour.rs | 338 +++++++++--------- protocols/gossipsub/src/gossip_promises.rs | 6 +- protocols/gossipsub/src/handler.rs | 2 +- protocols/gossipsub/src/mcache.rs | 8 +- protocols/gossipsub/src/peer_score.rs | 53 +-- protocols/gossipsub/src/protocol.rs | 6 +- .../gossipsub/src/subscription_filter.rs | 3 +- 11 files changed, 216 insertions(+), 214 deletions(-) diff --git a/examples/rendezvous/src/bin/rzv-discover.rs b/examples/rendezvous/src/bin/rzv-discover.rs index 52d10a110e1..1b828570c70 100644 --- a/examples/rendezvous/src/bin/rzv-discover.rs +++ b/examples/rendezvous/src/bin/rzv-discover.rs @@ -92,7 +92,7 @@ async fn main() { for registration in registrations { for address in registration.record.addresses() { let peer = registration.record.peer_id(); - tracing::info!("Discovered peer {} at {}", peer, address); + tracing::info!(%peer, %address, "Discovered peer"); let p2p_suffix = Protocol::P2p(peer); let address_with_p2p = @@ -111,7 +111,7 @@ async fn main() { result: Ok(rtt), .. })) if peer != rendezvous_point => { - tracing::info!("Ping to {} is {}ms", peer, rtt.as_millis()) + tracing::info!(%peer, "Ping is {}ms", rtt.as_millis()) } other => { tracing::debug!("Unhandled {:?}", other); diff --git a/protocols/autonat/src/behaviour/as_client.rs b/protocols/autonat/src/behaviour/as_client.rs index 1e0717cc20a..c5ad7fe09db 100644 --- a/protocols/autonat/src/behaviour/as_client.rs +++ b/protocols/autonat/src/behaviour/as_client.rs @@ -156,9 +156,9 @@ impl<'a> HandleInnerEvent for AsClient<'a> { request_id, } => { tracing::debug!( - "Outbound Failure {} when on dial-back request to peer {}.", + %peer, + "Outbound Failure {} when on dial-back request to peer.", error, - peer ); let probe_id = self .ongoing_outbound @@ -294,7 +294,7 @@ impl<'a> AsClient<'a> { }, ); self.throttled_servers.push((server, Instant::now())); - tracing::debug!("Send dial-back request to peer {}.", server); + tracing::debug!(peer=%server, "Send dial-back request to peer."); self.ongoing_outbound.insert(request_id, probe_id); Ok(server) } diff --git a/protocols/dcutr/src/protocol/inbound.rs b/protocols/dcutr/src/protocol/inbound.rs index 9c28c05a85a..35eaeae5483 100644 --- a/protocols/dcutr/src/protocol/inbound.rs +++ b/protocols/dcutr/src/protocol/inbound.rs @@ -68,7 +68,7 @@ impl upgrade::InboundUpgrade for Upgrade { // Filter out relayed addresses. .filter(|a| { if a.iter().any(|p| p == Protocol::P2pCircuit) { - tracing::debug!("Dropping relayed address {a}"); + tracing::debug!(address=%a, "Dropping relayed address"); false } else { true diff --git a/protocols/dcutr/src/protocol/outbound.rs b/protocols/dcutr/src/protocol/outbound.rs index f415739661c..def8d14c675 100644 --- a/protocols/dcutr/src/protocol/outbound.rs +++ b/protocols/dcutr/src/protocol/outbound.rs @@ -94,7 +94,7 @@ impl upgrade::OutboundUpgrade for Upgrade { // Filter out relayed addresses. .filter(|a| { if a.iter().any(|p| p == Protocol::P2pCircuit) { - tracing::debug!("Dropping relayed address {a}"); + tracing::debug!(address=%a, "Dropping relayed address"); false } else { true diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 30210e7c8c1..7c47d329a2f 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -526,14 +526,14 @@ where /// Returns [`Ok(true)`] if the subscription worked. Returns [`Ok(false)`] if we were already /// subscribed. pub fn subscribe(&mut self, topic: &Topic) -> Result { - tracing::debug!("Subscribing to topic: {}", topic); + tracing::debug!(%topic, "Subscribing to topic:"); let topic_hash = topic.hash(); if !self.subscription_filter.can_subscribe(&topic_hash) { return Err(SubscriptionError::NotAllowed); } if self.mesh.get(&topic_hash).is_some() { - tracing::debug!("Topic: {} is already in the mesh.", topic); + tracing::debug!(%topic, "Topic is already in the mesh."); return Ok(false); } @@ -551,7 +551,7 @@ where .into_protobuf(); for peer in peer_list { - tracing::debug!("Sending SUBSCRIBE to peer: {:?}", peer); + tracing::debug!(%peer, "Sending SUBSCRIBE to peer"); self.send_message(peer, event.clone()) .map_err(SubscriptionError::PublishError)?; } @@ -560,7 +560,7 @@ where // call JOIN(topic) // this will add new peers to the mesh for the topic self.join(&topic_hash); - tracing::debug!("Subscribed to topic: {}", topic); + tracing::debug!(%topic, "Subscribed to topic"); Ok(true) } @@ -568,11 +568,11 @@ where /// /// Returns [`Ok(true)`] if we were subscribed to this topic. pub fn unsubscribe(&mut self, topic: &Topic) -> Result { - tracing::debug!("Unsubscribing from topic: {}", topic); + tracing::debug!(%topic, "Unsubscribing from topic"); let topic_hash = topic.hash(); if self.mesh.get(&topic_hash).is_none() { - tracing::debug!("Already unsubscribed from topic: {:?}", topic_hash); + tracing::debug!(topic=%topic_hash, "Already unsubscribed from topic"); // we are not subscribed return Ok(false); } @@ -591,7 +591,7 @@ where .into_protobuf(); for peer in peer_list { - tracing::debug!("Sending UNSUBSCRIBE to peer: {}", peer.to_string()); + tracing::debug!(%peer, "Sending UNSUBSCRIBE to peer"); self.send_message(peer, event.clone())?; } } @@ -600,7 +600,7 @@ where // this will remove the topic from the mesh self.leave(&topic_hash); - tracing::debug!("Unsubscribed from topic: {:?}", topic_hash); + tracing::debug!(topic=%topic_hash, "Unsubscribed from topic"); Ok(true) } @@ -645,13 +645,13 @@ where // This message has already been seen. We don't re-publish messages that have already // been published on the network. tracing::warn!( - "Not publishing a message that has already been published. Msg-id {}", - msg_id + message=%msg_id, + "Not publishing a message that has already been published" ); return Err(PublishError::Duplicate); } - tracing::trace!("Publishing message: {:?}", msg_id); + tracing::trace!(message=%msg_id, "Publishing message"); let topic_hash = raw_message.topic.clone(); @@ -692,7 +692,7 @@ where // Gossipsub peers if self.mesh.get(&topic_hash).is_none() { - tracing::debug!("Topic: {:?} not in the mesh", topic_hash); + tracing::debug!(topic=%topic_hash, "Topic not in the mesh"); // If we have fanout peers add them to the map. if self.fanout.contains_key(&topic_hash) { for peer in self.fanout.get(&topic_hash).expect("Topic must exist") { @@ -718,7 +718,7 @@ where // Add the new peers to the fanout and recipient peers self.fanout.insert(topic_hash.clone(), new_peers.clone()); for peer in new_peers { - tracing::debug!("Peer added to fanout: {:?}", peer); + tracing::debug!(%peer, "Peer added to fanout"); recipient_peers.insert(peer); } } @@ -749,7 +749,7 @@ where // Send to peers we know are subscribed to the topic. let msg_bytes = event.get_size(); for peer_id in recipient_peers.iter() { - tracing::trace!("Sending message to peer: {:?}", peer_id); + tracing::trace!(peer=%peer_id, "Sending message to peer"); self.send_message(*peer_id, event.clone())?; if let Some(m) = self.metrics.as_mut() { @@ -757,7 +757,7 @@ where } } - tracing::debug!("Published message: {:?}", &msg_id); + tracing::debug!(message=%msg_id, "Published message"); if let Some(metrics) = self.metrics.as_mut() { metrics.register_published_message(&topic_hash); @@ -799,8 +799,8 @@ where } None => { tracing::warn!( - "Message not in cache. Ignoring forwarding. Message Id: {}", - msg_id + message=%msg_id, + "Message not in cache. Ignoring forwarding" ); if let Some(metrics) = self.metrics.as_mut() { metrics.memcache_miss(); @@ -845,14 +845,14 @@ where } Ok(true) } else { - tracing::warn!("Rejected message not in cache. Message Id: {}", msg_id); + tracing::warn!(message=%msg_id, "Rejected message not in cache"); Ok(false) } } /// Adds a new peer to the list of explicitly connected peers. pub fn add_explicit_peer(&mut self, peer_id: &PeerId) { - tracing::debug!("Adding explicit peer {}", peer_id); + tracing::debug!(peer=%peer_id, "Adding explicit peer"); self.explicit_peers.insert(*peer_id); @@ -862,7 +862,7 @@ where /// This removes the peer from explicitly connected peers, note that this does not disconnect /// the peer. pub fn remove_explicit_peer(&mut self, peer_id: &PeerId) { - tracing::debug!("Removing explicit peer {}", peer_id); + tracing::debug!(peer=%peer_id, "Removing explicit peer"); self.explicit_peers.remove(peer_id); } @@ -870,14 +870,14 @@ where /// created by this peer will be rejected. pub fn blacklist_peer(&mut self, peer_id: &PeerId) { if self.blacklisted_peers.insert(*peer_id) { - tracing::debug!("Peer has been blacklisted: {}", peer_id); + tracing::debug!(peer=%peer_id, "Peer has been blacklisted"); } } /// Removes a peer from the blacklist if it has previously been blacklisted. pub fn remove_blacklisted_peer(&mut self, peer_id: &PeerId) { if self.blacklisted_peers.remove(peer_id) { - tracing::debug!("Peer has been removed from the blacklist: {}", peer_id); + tracing::debug!(peer=%peer_id, "Peer has been removed from the blacklist"); } } @@ -946,11 +946,11 @@ where /// Gossipsub JOIN(topic) - adds topic peers to mesh and sends them GRAFT messages. fn join(&mut self, topic_hash: &TopicHash) { - tracing::debug!("Running JOIN for topic: {:?}", topic_hash); + tracing::debug!(topic=%topic_hash, "Running JOIN for topic"); // if we are already in the mesh, return if self.mesh.contains_key(topic_hash) { - tracing::debug!("JOIN: The topic is already in the mesh, ignoring JOIN"); + tracing::debug!(topic=%topic_hash, "JOIN: The topic is already in the mesh, ignoring JOIN"); return; } @@ -964,8 +964,8 @@ where // removing the fanout entry. if let Some((_, mut peers)) = self.fanout.remove_entry(topic_hash) { tracing::debug!( - "JOIN: Removing peers from the fanout for topic: {:?}", - topic_hash + topic=%topic_hash, + "JOIN: Removing peers from the fanout for topic" ); // remove explicit peers, peers with negative scores, and backoffed peers @@ -979,9 +979,9 @@ where // NOTE: These aren't randomly added, currently FIFO let add_peers = std::cmp::min(peers.len(), self.config.mesh_n()); tracing::debug!( - "JOIN: Adding {:?} peers from the fanout for topic: {:?}", - add_peers, - topic_hash + topic=%topic_hash, + "JOIN: Adding {:?} peers from the fanout for topic", + add_peers ); added_peers.extend(peers.iter().cloned().take(add_peers)); @@ -1031,7 +1031,7 @@ where for peer_id in added_peers { // Send a GRAFT control message - tracing::debug!("JOIN: Sending Graft message to peer: {:?}", peer_id); + tracing::debug!(peer=%peer_id, "JOIN: Sending Graft message to peer"); if let Some((peer_score, ..)) = &mut self.peer_score { peer_score.graft(&peer_id, topic_hash.clone()); } @@ -1059,7 +1059,7 @@ where m.set_mesh_peers(topic_hash, mesh_peers) } - tracing::debug!("Completed JOIN for topic: {:?}", topic_hash); + tracing::debug!(topic=%topic_hash, "Completed JOIN for topic"); } /// Creates a PRUNE gossipsub action. @@ -1126,7 +1126,7 @@ where /// Gossipsub LEAVE(topic) - Notifies mesh\[topic\] peers with PRUNE messages. fn leave(&mut self, topic_hash: &TopicHash) { - tracing::debug!("Running LEAVE for topic {:?}", topic_hash); + tracing::debug!(topic=%topic_hash, "Running LEAVE for topic"); // If our mesh contains the topic, send prune to peers and delete it from the mesh if let Some((_, peers)) = self.mesh.remove_entry(topic_hash) { @@ -1135,7 +1135,7 @@ where } for peer in peers { // Send a PRUNE control message - tracing::debug!("LEAVE: Sending PRUNE to peer: {:?}", peer); + tracing::debug!(%peer, "LEAVE: Sending PRUNE to peer"); let on_unsubscribe = true; let control = self.make_prune(topic_hash, &peer, self.config.do_px(), on_unsubscribe); @@ -1152,14 +1152,14 @@ where ); } } - tracing::debug!("Completed LEAVE for topic: {:?}", topic_hash); + tracing::debug!(topic=%topic_hash, "Completed LEAVE for topic"); } /// Checks if the given peer is still connected and if not dials the peer again. fn check_explicit_peer_connection(&mut self, peer_id: &PeerId) { if !self.peer_topics.contains_key(peer_id) { // Connect to peer - tracing::debug!("Connecting to explicit peer {:?}", peer_id); + tracing::debug!(peer=%peer_id, "Connecting to explicit peer"); self.events.push_back(ToSwarm::Dial { opts: DialOpts::peer_id(*peer_id).build(), }); @@ -1198,9 +1198,9 @@ where // We ignore IHAVE gossip from any peer whose score is below the gossip threshold if let (true, score) = self.score_below_threshold(peer_id, |pst| pst.gossip_threshold) { tracing::debug!( - "IHAVE: ignoring peer {:?} with score below threshold [score = {}]", - peer_id, - score + peer=%peer_id, + %score, + "IHAVE: ignoring peer with score below threshold" ); return; } @@ -1210,9 +1210,9 @@ where *peer_have += 1; if *peer_have > self.config.max_ihave_messages() { tracing::debug!( - "IHAVE: peer {} has advertised too many times ({}) within this heartbeat \ + peer=%peer_id, + "IHAVE: peer has advertised too many times ({}) within this heartbeat \ interval; ignoring", - peer_id, *peer_have ); return; @@ -1221,15 +1221,15 @@ where if let Some(iasked) = self.count_sent_iwant.get(peer_id) { if *iasked >= self.config.max_ihave_length() { tracing::debug!( - "IHAVE: peer {} has already advertised too many messages ({}); ignoring", - peer_id, + peer=%peer_id, + "IHAVE: peer has already advertised too many messages ({}); ignoring", *iasked ); return; } } - tracing::trace!("Handling IHAVE for peer: {:?}", peer_id); + tracing::trace!(peer=%peer_id, "Handling IHAVE for peer"); let mut iwant_ids = HashSet::new(); @@ -1252,8 +1252,8 @@ where // only process the message if we are subscribed if !self.mesh.contains_key(&topic) { tracing::debug!( - "IHAVE: Ignoring IHAVE - Not subscribed to topic: {:?}", - topic + %topic, + "IHAVE: Ignoring IHAVE - Not subscribed to topic" ); continue; } @@ -1278,10 +1278,10 @@ where // Send the list of IWANT control messages tracing::debug!( - "IHAVE: Asking for {} out of {} messages from {}", + peer=%peer_id, + "IHAVE: Asking for {} out of {} messages from peer", iask, - iwant_ids.len(), - peer_id + iwant_ids.len() ); // Ask in random order @@ -1305,8 +1305,8 @@ where ); } tracing::trace!( - "IHAVE: Asking for the following messages from {}: {:?}", - peer_id, + peer=%peer_id, + "IHAVE: Asking for the following messages from peer: {:?}", iwant_ids_vec ); @@ -1318,7 +1318,7 @@ where }, ); } - tracing::trace!("Completed IHAVE handling for peer: {:?}", peer_id); + tracing::trace!(peer=%peer_id, "Completed IHAVE handling for peer"); } /// Handles an IWANT control message. Checks our cache of messages. If the message exists it is @@ -1327,14 +1327,14 @@ where // We ignore IWANT gossip from any peer whose score is below the gossip threshold if let (true, score) = self.score_below_threshold(peer_id, |pst| pst.gossip_threshold) { tracing::debug!( - "IWANT: ignoring peer {:?} with score below threshold [score = {}]", - peer_id, + peer=%peer_id, + "IWANT: ignoring peer with score below threshold [score = {}]", score ); return; } - tracing::debug!("Handling IWANT for peer: {:?}", peer_id); + tracing::debug!(peer=%peer_id, "Handling IWANT for peer"); // build a hashmap of available messages let mut cached_messages = HashMap::new(); @@ -1344,10 +1344,9 @@ where if let Some((msg, count)) = self.mcache.get_with_iwant_counts(&id, peer_id) { if count > self.config.gossip_retransimission() { tracing::debug!( - "IWANT: Peer {} has asked for message {} too many times; ignoring \ - request", - peer_id, - &id + peer=%peer_id, + message=%id, + "IWANT: Peer has asked for message too many times; ignoring request" ); } else { cached_messages.insert(id.clone(), msg.clone()); @@ -1356,7 +1355,7 @@ where } if !cached_messages.is_empty() { - tracing::debug!("IWANT: Sending cached messages to peer: {:?}", peer_id); + tracing::debug!(peer=%peer_id, "IWANT: Sending cached messages to peer"); // Send the messages to the peer let message_list: Vec<_> = cached_messages.into_iter().map(|entry| entry.1).collect(); @@ -1383,13 +1382,13 @@ where } } } - tracing::debug!("Completed IWANT handling for peer: {}", peer_id); + tracing::debug!(peer=%peer_id, "Completed IWANT handling for peer"); } /// Handles GRAFT control messages. If subscribed to the topic, adds the peer to mesh, if not, /// responds with PRUNE messages. fn handle_graft(&mut self, peer_id: &PeerId, topics: Vec) { - tracing::debug!("Handling GRAFT message for peer: {}", peer_id); + tracing::debug!(peer=%peer_id, "Handling GRAFT message for peer"); let mut to_prune_topics = HashSet::new(); @@ -1410,7 +1409,7 @@ where // we don't GRAFT to/from explicit peers; complain loudly if this happens if self.explicit_peers.contains(peer_id) { - tracing::warn!("GRAFT: ignoring request from direct peer {}", peer_id); + tracing::warn!(peer=%peer_id, "GRAFT: ignoring request from direct peer"); // this is possibly a bug from non-reciprocal configuration; send a PRUNE for all topics to_prune_topics = topics.into_iter().collect(); // but don't PX @@ -1423,9 +1422,9 @@ where // if the peer is already in the mesh ignore the graft if peers.contains(peer_id) { tracing::debug!( - "GRAFT: Received graft for peer {:?} that is already in topic {:?}", - peer_id, - &topic_hash + peer=%peer_id, + topic=%&topic_hash, + "GRAFT: Received graft for peer that is already in topic" ); continue; } @@ -1435,8 +1434,8 @@ where { if backoff_time > now { tracing::warn!( - "[Penalty] Peer attempted graft within backoff time, penalizing {}", - peer_id + peer=%peer_id, + "[Penalty] Peer attempted graft within backoff time, penalizing" ); // add behavioural penalty if let Some((peer_score, ..)) = &mut self.peer_score { @@ -1468,11 +1467,10 @@ where if below_zero { // we don't GRAFT peers with negative score tracing::debug!( - "GRAFT: ignoring peer {:?} with negative score [score = {}, \ - topic = {}]", - peer_id, - score, - topic_hash + peer=%peer_id, + %score, + topic=%topic_hash, + "GRAFT: ignoring peer with negative score" ); // we do send them PRUNE however, because it's a matter of protocol correctness to_prune_topics.insert(topic_hash.clone()); @@ -1492,9 +1490,9 @@ where // add peer to the mesh tracing::debug!( - "GRAFT: Mesh link added for peer: {:?} in topic: {:?}", - peer_id, - &topic_hash + peer=%peer_id, + topic=%topic_hash, + "GRAFT: Mesh link added for peer in topic" ); if peers.insert(*peer_id) { @@ -1520,9 +1518,9 @@ where // don't do PX when there is an unknown topic to avoid leaking our peers do_px = false; tracing::debug!( - "GRAFT: Received graft for unknown topic {:?} from peer {:?}", - &topic_hash, - peer_id + peer=%peer_id, + topic=%topic_hash, + "GRAFT: Received graft for unknown topic from peer" ); // spam hardening: ignore GRAFTs for unknown topics continue; @@ -1539,8 +1537,8 @@ where .collect(); // Send the prune messages to the peer tracing::debug!( - "GRAFT: Not subscribed to topics - Sending PRUNE to peer: {}", - peer_id + peer=%peer_id, + "GRAFT: Not subscribed to topics - Sending PRUNE to peer" ); if let Err(e) = self.send_message( @@ -1555,7 +1553,7 @@ where tracing::error!("Failed to send PRUNE: {:?}", e); } } - tracing::debug!("Completed GRAFT handling for peer: {}", peer_id); + tracing::debug!(peer=%peer_id, "Completed GRAFT handling for peer"); } fn remove_peer_from_mesh( @@ -1571,9 +1569,9 @@ where // remove the peer if it exists in the mesh if peers.remove(peer_id) { tracing::debug!( - "PRUNE: Removing peer: {} from the mesh for topic: {}", - peer_id.to_string(), - topic_hash + peer=%peer_id, + topic=%topic_hash, + "PRUNE: Removing peer from the mesh for topic" ); if let Some(m) = self.metrics.as_mut() { m.peers_removed(topic_hash, reason, 1) @@ -1613,7 +1611,7 @@ where peer_id: &PeerId, prune_data: Vec<(TopicHash, Vec, Option)>, ) { - tracing::debug!("Handling PRUNE message for peer: {}", peer_id); + tracing::debug!(peer=%peer_id, "Handling PRUNE message for peer"); let (below_threshold, score) = self.score_below_threshold(peer_id, |pst| pst.accept_px_threshold); for (topic_hash, px, backoff) in prune_data { @@ -1625,11 +1623,10 @@ where // we ignore PX from peers with insufficient score if below_threshold { tracing::debug!( - "PRUNE: ignoring PX from peer {:?} with insufficient score \ - [score ={} topic = {}]", - peer_id, - score, - topic_hash + peer=%peer_id, + %score, + topic=%topic_hash, + "PRUNE: ignoring PX from peer with insufficient score" ); continue; } @@ -1646,7 +1643,7 @@ where } } } - tracing::debug!("Completed PRUNE handling for peer: {}", peer_id.to_string()); + tracing::debug!(peer=%peer_id, "Completed PRUNE handling for peer"); } fn px_connect(&mut self, mut px: Vec) { @@ -1687,16 +1684,16 @@ where propagation_source: &PeerId, ) -> bool { tracing::debug!( - "Handling message: {:?} from peer: {}", - msg_id, - propagation_source.to_string() + peer=%propagation_source, + message=%msg_id, + "Handling message from peer" ); // Reject any message from a blacklisted peer if self.blacklisted_peers.contains(propagation_source) { tracing::debug!( - "Rejecting message from blacklisted peer: {}", - propagation_source + peer=%propagation_source, + "Rejecting message from blacklisted peer" ); if let Some((peer_score, .., gossip_promises)) = &mut self.peer_score { peer_score.reject_message( @@ -1714,9 +1711,9 @@ where if let Some(source) = raw_message.source.as_ref() { if self.blacklisted_peers.contains(source) { tracing::debug!( - "Rejecting message from peer {} because of blacklisted source: {}", - propagation_source, - source + peer=%propagation_source, + %source, + "Rejecting message from peer because of blacklisted source" ); self.handle_invalid_message( propagation_source, @@ -1745,9 +1742,9 @@ where if self_published { tracing::debug!( - "Dropping message {} claiming to be from self but forwarded from {}", - msg_id, - propagation_source + message=%msg_id, + source=%propagation_source, + "Dropping message claiming to be from self but forwarded from source" ); self.handle_invalid_message(propagation_source, raw_message, RejectReason::SelfOrigin); return false; @@ -1828,7 +1825,7 @@ where } if !self.duplicate_cache.insert(msg_id.clone()) { - tracing::debug!("Message already received, ignoring. Message: {}", msg_id); + tracing::debug!(message=%msg_id, "Message already received, ignoring."); if let Some((peer_score, ..)) = &mut self.peer_score { peer_score.duplicated_message(propagation_source, &msg_id, &message.topic); } @@ -1836,8 +1833,8 @@ where return; } tracing::debug!( - "Put message {:?} in duplicate_cache and resolve promises", - msg_id + message=%msg_id, + "Put message in duplicate_cache and resolve promises" ); // Record the received message with the metrics @@ -1866,8 +1863,8 @@ where })); } else { tracing::debug!( - "Received message on a topic we are not subscribed to: {:?}", - message.topic + topic=%message.topic, + "Received message on a topic we are not subscribed to" ); return; } @@ -1885,7 +1882,7 @@ where { tracing::error!("Failed to forward message. Too large"); } - tracing::debug!("Completed message handling for message: {:?}", msg_id); + tracing::debug!(message=%msg_id, "Completed message handling for message"); } } @@ -1931,9 +1928,9 @@ where propagation_source: &PeerId, ) { tracing::debug!( - "Handling subscriptions: {:?}, from source: {}", + source=%propagation_source, + "Handling subscriptions: {:?}", subscriptions, - propagation_source.to_string() ); let mut unsubscribed_peers = Vec::new(); @@ -1942,8 +1939,8 @@ where Some(topics) => topics, None => { tracing::error!( - "Subscription by unknown peer: {}", - propagation_source.to_string() + peer=%propagation_source, + "Subscription by unknown peer" ); return; } @@ -1962,9 +1959,9 @@ where Ok(topics) => topics, Err(s) => { tracing::error!( - "Subscription filter error: {}; ignoring RPC from peer {}", - s, - propagation_source.to_string() + peer=%propagation_source, + "Subscription filter error: {}; ignoring RPC from peer", + s ); return; } @@ -1979,9 +1976,9 @@ where SubscriptionAction::Subscribe => { if peer_list.insert(*propagation_source) { tracing::debug!( - "SUBSCRIPTION: Adding gossip peer: {} to topic: {:?}", - propagation_source.to_string(), - topic_hash + peer=%propagation_source, + topic=%topic_hash, + "SUBSCRIPTION: Adding gossip peer to topic" ); } @@ -2011,18 +2008,18 @@ where && peers.insert(*propagation_source) { tracing::debug!( - "SUBSCRIPTION: Adding peer {} to the mesh for topic {:?}", - propagation_source.to_string(), - topic_hash + peer=%propagation_source, + topic=%topic_hash, + "SUBSCRIPTION: Adding peer to the mesh for topic" ); if let Some(m) = self.metrics.as_mut() { m.peers_included(topic_hash, Inclusion::Subscribed, 1) } // send graft to the peer tracing::debug!( - "Sending GRAFT to peer {} for topic {:?}", - propagation_source.to_string(), - topic_hash + peer=%propagation_source, + topic=%topic_hash, + "Sending GRAFT to peer for topic" ); if let Some((peer_score, ..)) = &mut self.peer_score { peer_score.graft(propagation_source, topic_hash.clone()); @@ -2040,9 +2037,9 @@ where SubscriptionAction::Unsubscribe => { if peer_list.remove(propagation_source) { tracing::debug!( - "SUBSCRIPTION: Removing gossip peer: {} from topic: {:?}", - propagation_source.to_string(), - topic_hash + peer=%propagation_source, + topic=%topic_hash, + "SUBSCRIPTION: Removing gossip peer from topic" ); } @@ -2107,8 +2104,8 @@ where } tracing::trace!( - "Completed handling subscriptions from source: {:?}", - propagation_source + source=%propagation_source, + "Completed handling subscriptions from source" ); } @@ -2183,11 +2180,10 @@ where if peer_score < 0.0 { tracing::debug!( - "HEARTBEAT: Prune peer {:?} with negative score [score = {}, topic = \ - {}]", - peer_id, - peer_score, - topic_hash + peer=%peer_id, + score=%peer_score, + topic=%topic_hash, + "HEARTBEAT: Prune peer with negative score" ); let current_topic = to_prune.entry(*peer_id).or_insert_with(Vec::new); @@ -2208,8 +2204,8 @@ where // too little peers - add some if peers.len() < self.config.mesh_n_low() { tracing::debug!( - "HEARTBEAT: Mesh low. Topic: {} Contains: {} needs: {}", - topic_hash, + topic=%topic_hash, + "HEARTBEAT: Mesh low. Topic contains: {} needs: {}", peers.len(), self.config.mesh_n_low() ); @@ -2242,8 +2238,8 @@ where // too many peers - remove some if peers.len() > self.config.mesh_n_high() { tracing::debug!( - "HEARTBEAT: Mesh high. Topic: {} Contains: {} needs: {}", - topic_hash, + topic=%topic_hash, + "HEARTBEAT: Mesh high. Topic contains: {} needs: {}", peers.len(), self.config.mesh_n_high() ); @@ -2394,8 +2390,8 @@ where } // update the mesh tracing::debug!( - "Opportunistically graft in topic {} with peers {:?}", - topic_hash, + topic=%topic_hash, + "Opportunistically graft in topic with peers {:?}", peer_list ); if let Some(m) = self.metrics.as_mut() { @@ -2418,8 +2414,8 @@ where self.fanout_last_pub.retain(|topic_hash, last_pub_time| { if *last_pub_time + fanout_ttl < Instant::now() { tracing::debug!( - "HEARTBEAT: Fanout topic removed due to timeout. Topic: {:?}", - topic_hash + topic=%topic_hash, + "HEARTBEAT: Fanout topic removed due to timeout" ); fanout.remove(topic_hash); return false; @@ -2443,8 +2439,8 @@ where Some(topics) => { if !topics.contains(topic_hash) || peer_score < publish_threshold { tracing::debug!( - "HEARTBEAT: Peer removed from fanout for topic: {:?}", - topic_hash + topic=%topic_hash, + "HEARTBEAT: Peer removed from fanout for topic" ); to_remove_peers.push(*peer); } @@ -2729,7 +2725,7 @@ where } } - tracing::debug!("Forwarding message: {:?}", msg_id); + tracing::debug!(message=%msg_id, "Forwarding message"); let mut recipient_peers = HashSet::new(); { @@ -2774,7 +2770,7 @@ where let msg_bytes = event.get_size(); for peer in recipient_peers.iter() { - tracing::debug!("Sending message: {:?} to peer {:?}", msg_id, peer); + tracing::debug!(%peer, message=%msg_id, "Sending message to peer"); self.send_message(*peer, event.clone())?; if let Some(m) = self.metrics.as_mut() { m.msg_sent(&message.topic, msg_bytes); @@ -3076,8 +3072,8 @@ where peer_score.add_ip(&peer_id, ip); } else { tracing::trace!( - "Couldn't extract ip from endpoint of peer {} with endpoint {:?}", - peer_id, + peer=%peer_id, + "Couldn't extract ip from endpoint of peer with endpoint {:?}", endpoint ) } @@ -3100,9 +3096,9 @@ where if other_established == 0 { // Ignore connections from blacklisted peers. if self.blacklisted_peers.contains(&peer_id) { - tracing::debug!("Ignoring connection from blacklisted peer: {}", peer_id); + tracing::debug!(peer=%peer_id, "Ignoring connection from blacklisted peer"); } else { - tracing::debug!("New peer connected: {}", peer_id); + tracing::debug!(peer=%peer_id, "New peer connected"); // We need to send our subscriptions to the newly-connected node. let mut subscriptions = vec![]; for topic_hash in self.mesh.keys() { @@ -3156,8 +3152,8 @@ where peer_score.remove_ip(&peer_id, &ip); } else { tracing::trace!( - "Couldn't extract ip from endpoint of peer {} with endpoint {:?}", - peer_id, + peer=%peer_id, + "Couldn't extract ip from endpoint of peer with endpoint {:?}", endpoint ) } @@ -3194,7 +3190,7 @@ where } } else { // remove from mesh, topic_peers, peer_topic and the fanout - tracing::debug!("Peer disconnected: {}", peer_id); + tracing::debug!(peer=%peer_id, "Peer disconnected"); { let topics = match self.peer_topics.get(&peer_id) { Some(topics) => topics, @@ -3225,8 +3221,8 @@ where if !peer_list.remove(&peer_id) { // debugging purposes tracing::warn!( - "Disconnected node: {} not in topic_peers peer list", - peer_id + peer=%peer_id, + "Disconnected node: peer not in topic_peers" ); } if let Some(m) = self.metrics.as_mut() { @@ -3234,9 +3230,9 @@ where } } else { tracing::warn!( - "Disconnected node: {} with topic: {:?} not in topic_peers", - &peer_id, - &topic + peer=%peer_id, + topic=%topic, + "Disconnected node: peer with topic not in topic_peers" ); } @@ -3289,8 +3285,8 @@ where peer_score.remove_ip(&peer_id, &ip); } else { tracing::trace!( - "Couldn't extract ip from endpoint of peer {} with endpoint {:?}", - &peer_id, + peer=%&peer_id, + "Couldn't extract ip from endpoint of peer with endpoint {:?}", endpoint_old ) } @@ -3298,8 +3294,8 @@ where peer_score.add_ip(&peer_id, ip); } else { tracing::trace!( - "Couldn't extract ip from endpoint of peer {} with endpoint {:?}", - peer_id, + peer=%peer_id, + "Couldn't extract ip from endpoint of peer with endpoint {:?}", endpoint_new ) } @@ -3365,8 +3361,8 @@ where if let PeerKind::NotSupported = kind { tracing::debug!( - "Peer does not support gossipsub protocols. {}", - propagation_source + peer=%propagation_source, + "Peer does not support gossipsub protocols" ); self.events .push_back(ToSwarm::GenerateEvent(Event::GossipsubNotSupported { @@ -3377,9 +3373,9 @@ where // `NetworkBehaviour::on_event` with FromSwarm::ConnectionEstablished). // All other PeerKind changes are ignored. tracing::debug!( - "New peer type found: {} for peer: {}", - kind, - propagation_source + peer=%propagation_source, + peer_type=%kind, + "New peer type found for peer" ); if let PeerKind::Floodsub = conn.kind { conn.kind = kind; @@ -3402,7 +3398,7 @@ where if let (true, _) = self.score_below_threshold(&propagation_source, |pst| pst.graylist_threshold) { - tracing::debug!("RPC Dropped from greylisted peer {}", propagation_source); + tracing::debug!(peer=%propagation_source, "RPC Dropped from greylisted peer"); return; } @@ -3419,10 +3415,10 @@ where // log the invalid messages for (message, validation_error) in invalid_messages { tracing::warn!( - "Invalid message. Reason: {:?} propagation_peer {} source {:?}", + peer=%propagation_source, + source=?message.source, + "Invalid message from peer. Reason: {:?}", validation_error, - propagation_source.to_string(), - message.source ); } } diff --git a/protocols/gossipsub/src/gossip_promises.rs b/protocols/gossipsub/src/gossip_promises.rs index ed56126845a..9538622c0dc 100644 --- a/protocols/gossipsub/src/gossip_promises.rs +++ b/protocols/gossipsub/src/gossip_promises.rs @@ -85,9 +85,9 @@ impl GossipPromises { let count = result.entry(*peer_id).or_insert(0); *count += 1; tracing::debug!( - "[Penalty] The peer {} broke the promise to deliver message {} in time!", - peer_id, - msg + peer=%peer_id, + message=%msg, + "[Penalty] The peer broke the promise to deliver message in time!" ); false } else { diff --git a/protocols/gossipsub/src/handler.rs b/protocols/gossipsub/src/handler.rs index 1cd7f26b554..015d7d3c6d9 100644 --- a/protocols/gossipsub/src/handler.rs +++ b/protocols/gossipsub/src/handler.rs @@ -426,7 +426,7 @@ impl ConnectionHandler for Handler { } }, Handler::Disabled(_) => { - tracing::debug!("Handler is disabled. Dropping message {:?}", message); + tracing::debug!(?message, "Handler is disabled. Dropping message"); } } } diff --git a/protocols/gossipsub/src/mcache.rs b/protocols/gossipsub/src/mcache.rs index 024caa27954..ef4a93bc936 100644 --- a/protocols/gossipsub/src/mcache.rs +++ b/protocols/gossipsub/src/mcache.rs @@ -86,7 +86,7 @@ impl MessageCache { entry.insert((msg, HashSet::default())); self.history[0].push(cache_entry); - tracing::trace!("Put message {:?} in mcache", message_id); + tracing::trace!(message=?message_id, "Put message in mcache"); true } } @@ -191,12 +191,12 @@ impl MessageCache { // application has to ensure that Gossipsub::validate_message gets called for // each received message within the cache timeout time." tracing::debug!( - "The message with id {} got removed from the cache without being validated.", - &entry.mid + message=%&entry.mid, + "The message got removed from the cache without being validated." ); } } - tracing::trace!("Remove message from the cache: {}", &entry.mid); + tracing::trace!(message=%&entry.mid, "Remove message from the cache"); self.iwant_counts.remove(&entry.mid); } diff --git a/protocols/gossipsub/src/peer_score.rs b/protocols/gossipsub/src/peer_score.rs index 7120224015a..928dbffa102 100644 --- a/protocols/gossipsub/src/peer_score.rs +++ b/protocols/gossipsub/src/peer_score.rs @@ -274,11 +274,11 @@ impl PeerScore { metrics.register_score_penalty(Penalty::MessageDeficit); } tracing::debug!( - "[Penalty] The peer {} has a mesh message deliveries deficit of {} in topic\ - {} and will get penalized by {}", - peer_id, - deficit, - topic, + peer=%peer_id, + %topic, + %deficit, + "[Penalty] The peer has a mesh message deliveries deficit in topic\ + and will get penalized by {}", p3 * topic_params.mesh_message_deliveries_weight ); } @@ -326,9 +326,10 @@ impl PeerScore { metrics.register_score_penalty(Penalty::IPColocation); } tracing::debug!( - "[Penalty] The peer {} gets penalized because of too many peers with the ip {}. \ - The surplus is {}. ", - peer_id, ip, surplus + peer=%peer_id, + surplus_ip=%ip, + surplus=%surplus, + "[Penalty] The peer gets penalized because of too many peers with the same ip" ); score += p6 * self.params.ip_colocation_factor_weight; } @@ -347,8 +348,8 @@ impl PeerScore { pub(crate) fn add_penalty(&mut self, peer_id: &PeerId, count: usize) { if let Some(peer_stats) = self.peer_stats.get_mut(peer_id) { tracing::debug!( - "[Penalty] Behavioral penalty for peer {}, count = {}.", - peer_id, + peer=%peer_id, + "[Penalty] Behavioral penalty for peer, count = {}.", count ); peer_stats.behaviour_penalty += count as f64; @@ -445,7 +446,7 @@ impl PeerScore { /// Adds a new ip to a peer, if the peer is not yet known creates a new peer_stats entry for it pub(crate) fn add_ip(&mut self, peer_id: &PeerId, ip: IpAddr) { - tracing::trace!("Add ip for peer {}, ip: {}", peer_id, ip); + tracing::trace!(peer=%peer_id, %ip, "Add ip for peer"); let peer_stats = self.peer_stats.entry(*peer_id).or_default(); // Mark the peer as connected (currently the default is connected, but we don't want to @@ -462,20 +463,20 @@ impl PeerScore { if let Some(peer_stats) = self.peer_stats.get_mut(peer_id) { peer_stats.known_ips.remove(ip); if let Some(peer_ids) = self.peer_ips.get_mut(ip) { - tracing::trace!("Remove ip for peer {}, ip: {}", peer_id, ip); + tracing::trace!(peer=%peer_id, %ip, "Remove ip for peer"); peer_ids.remove(peer_id); } else { tracing::trace!( - "No entry in peer_ips for ip {} which should get removed for peer {}", - ip, - peer_id + peer=%peer_id, + %ip, + "No entry in peer_ips for ip which should get removed for peer" ); } } else { tracing::trace!( - "No peer_stats for peer {} which should remove the ip {}", - peer_id, - ip + peer=%peer_id, + %ip, + "No peer_stats for peer which should remove the ip" ); } } @@ -594,7 +595,12 @@ impl PeerScore { // this should be the first delivery trace if record.status != DeliveryStatus::Unknown { - tracing::warn!("Unexpected delivery trace: Message from {} was first seen {}s ago and has a delivery status {:?}", from, record.first_seen.elapsed().as_secs(), record.status); + tracing::warn!( + peer=%from, + status=?record.status, + "Unexpected delivery trace: Message from peer was first seen {}s ago", + record.first_seen.elapsed().as_secs(), + ); return; } @@ -612,8 +618,8 @@ impl PeerScore { /// Similar to `reject_message` except does not require the message id or reason for an invalid message. pub(crate) fn reject_invalid_message(&mut self, from: &PeerId, topic_hash: &TopicHash) { tracing::debug!( - "[Penalty] Message from {} rejected because of ValidationError or SelfOrigin", - from + peer=%from, + "[Penalty] Message from peer rejected because of ValidationError or SelfOrigin" ); self.mark_invalid_message_delivery(from, topic_hash); @@ -779,9 +785,10 @@ impl PeerScore { peer_stats.stats_or_default_mut(topic_hash.clone(), &self.params) { tracing::debug!( - "[Penalty] Peer {} delivered an invalid message in topic {} and gets penalized \ + peer=%peer_id, + topic=%topic_hash, + "[Penalty] Peer delivered an invalid message in topic and gets penalized \ for it", - peer_id, topic_hash ); topic_stats.invalid_message_deliveries += 1f64; } diff --git a/protocols/gossipsub/src/protocol.rs b/protocols/gossipsub/src/protocol.rs index e8a8739be8c..dcd509f6aa9 100644 --- a/protocols/gossipsub/src/protocol.rs +++ b/protocols/gossipsub/src/protocol.rs @@ -338,9 +338,9 @@ impl Decoder for GossipsubCodec { None } else if seq_no.len() != 8 { tracing::debug!( - "Invalid sequence number length for received message. SeqNo: {:?} Size: {}", - seq_no, - seq_no.len() + sequence_number=?seq_no, + sequence_length=%seq_no.len(), + "Invalid sequence number length for received message" ); let message = RawMessage { source: None, // don't bother inform the application diff --git a/protocols/gossipsub/src/subscription_filter.rs b/protocols/gossipsub/src/subscription_filter.rs index cc8677d1c60..09c323d7904 100644 --- a/protocols/gossipsub/src/subscription_filter.rs +++ b/protocols/gossipsub/src/subscription_filter.rs @@ -21,7 +21,6 @@ use crate::types::Subscription; use crate::TopicHash; use std::collections::{BTreeSet, HashMap, HashSet}; -use tracing::debug; pub trait TopicSubscriptionFilter { /// Returns true iff the topic is of interest and we can subscribe to it. @@ -66,7 +65,7 @@ pub trait TopicSubscriptionFilter { if self.allow_incoming_subscription(s) { true } else { - debug!("Filtered incoming subscription {:?}", s); + tracing::debug!(subscription=?s, "Filtered incoming subscription"); false } }); From 97458ad5f7ccbb80032f3809778f850cd7b1cf00 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 21 Sep 2023 18:40:29 +0300 Subject: [PATCH 029/105] tracing improvements to kad and identify --- protocols/identify/src/behaviour.rs | 2 +- protocols/identify/src/handler.rs | 10 ++-- protocols/kad/src/behaviour.rs | 81 ++++++++++++++--------------- protocols/kad/src/handler.rs | 42 +++++++++------ 4 files changed, 72 insertions(+), 63 deletions(-) diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index 7cea27a9e65..0f008d182ed 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -183,7 +183,7 @@ impl Behaviour { { for p in peers { if !self.connected.contains_key(&p) { - tracing::debug!("Not pushing to {p} because we are not connected"); + tracing::debug!(peer=%p, "Not pushing to peer because we are not connected"); continue; } diff --git a/protocols/identify/src/handler.rs b/protocols/identify/src/handler.rs index 6a51d80a5c9..846ed71cbc9 100644 --- a/protocols/identify/src/handler.rs +++ b/protocols/identify/src/handler.rs @@ -156,9 +156,9 @@ impl Handler { future::Either::Right(fut) => { if self.inbound_identify_push.replace(fut).is_some() { tracing::warn!( - "New inbound identify push stream from {} while still \ - upgrading previous one. Replacing previous with new.", - self.remote_peer_id, + peer=%self.remote_peer_id, + "New inbound identify push stream from peer while still \ + upgrading previous one. Replacing previous with new." ); } } @@ -372,8 +372,8 @@ impl ConnectionHandler for Handler { if protocols_changed && self.exchanged_one_periodic_identify { tracing::debug!( - "Supported listen protocols changed from [{before}] to [{after}], pushing to {}", - self.remote_peer_id + peer=%self.remote_peer_id, + "Supported listen protocols changed from [{before}] to [{after}], pushing to peer" ); let info = self.build_info(); diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index 9796d44396c..80a163653d5 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -574,7 +574,7 @@ where RoutingUpdate::Success } kbucket::InsertResult::Full => { - tracing::debug!("Bucket full. Peer not added to routing table: {}", peer); + tracing::debug!(%peer, "Bucket full. Peer not added to routing table"); RoutingUpdate::Failed } kbucket::InsertResult::Pending { disconnected } => { @@ -1092,13 +1092,13 @@ where let local_id = self.kbuckets.local_key().preimage(); let others_iter = peers.filter(|p| &p.node_id != local_id); if let Some(query) = self.queries.get_mut(query_id) { - tracing::trace!("Request to {:?} in query {:?} succeeded.", source, query_id); + tracing::trace!(peer=%source, query=?query_id, "Request to peer in query succeeded."); for peer in others_iter.clone() { tracing::trace!( - "Peer {:?} reported by {:?} in query {:?}.", - peer, - source, - query_id + ?peer, + %source, + query=?query_id, + "Peer reported by source in query" ); let addrs = peer.multiaddrs.iter().cloned().collect(); query.inner.addresses.insert(peer.node_id, addrs); @@ -1288,8 +1288,8 @@ where } kbucket::InsertResult::Full => { tracing::debug!( - "Bucket full. Peer not added to routing table: {}", - peer + %peer, + "Bucket full. Peer not added to routing table" ); let address = addresses.first().clone(); self.queued_events.push_back(ToSwarm::GenerateEvent( @@ -1327,7 +1327,7 @@ where /// Handles a finished (i.e. successful) query. fn query_finished(&mut self, q: Query) -> Option { let query_id = q.id(); - tracing::trace!("Query {:?} finished.", query_id); + tracing::trace!(query=?query_id, "Query finished."); let result = q.into_result(); match result.inner.info { QueryInfo::Bootstrap { @@ -1554,7 +1554,7 @@ where step: ProgressStep::first_and_last(), }), PutRecordContext::Replicate => { - tracing::debug!("Record replicated: {:?}", record.key); + tracing::debug!(record=?record.key, "Record replicated"); None } } @@ -1565,7 +1565,7 @@ where /// Handles a query that timed out. fn query_timeout(&mut self, query: Query) -> Option { let query_id = query.id(); - tracing::trace!("Query {:?} timed out.", query_id); + tracing::trace!(query=?query_id, "Query timed out."); let result = query.into_result(); match result.inner.info { QueryInfo::Bootstrap { @@ -1771,8 +1771,8 @@ where KademliaStoreInserts::Unfiltered => match self.store.put(record.clone()) { Ok(()) => { tracing::debug!( - "Record stored: {:?}; {} bytes", - record.key, + record=?record.key, + "Record stored: {} bytes", record.value.len() ); self.queued_events.push_back(ToSwarm::GenerateEvent( @@ -1874,9 +1874,9 @@ where // The error passed in should rather be a dedicated enum. if addrs.remove(address).is_ok() { tracing::debug!( - "Address '{}' removed from peer '{}' due to error.", - address, - peer_id + peer=%peer_id, + %address, + "Address removed from peer due to error." ); } else { // Despite apparently having no reachable address (any longer), @@ -1889,9 +1889,9 @@ where // `KBucketsTable` and takes effect through `KBucketsTable::take_applied_pending` // within `Kademlia::poll`. tracing::debug!( - "Last remaining address '{}' of peer '{}' is unreachable.", - address, - peer_id, + peer=%peer_id, + %address, + "Last remaining address of peer is unreachable." ) } } @@ -1958,27 +1958,26 @@ where if let Some(addrs) = self.kbuckets.entry(&kbucket::Key::from(peer)).value() { if addrs.replace(old, new) { tracing::debug!( - "Address '{}' replaced with '{}' for peer '{}'.", - old, - new, - peer + %peer, + old_address=%old, + new_address=%new, + "Old address replaced with new address for peer." ); } else { tracing::debug!( - "Address '{}' not replaced with '{}' for peer '{}' as old address wasn't \ - present.", - old, - new, - peer + %peer, + old_address=%old, + new_address=%new, + "Old address not replaced with new address for peer as old address wasn't present.", ); } } else { tracing::debug!( - "Address '{}' not replaced with '{}' for peer '{}' as peer is not present in the \ - routing table.", - old, - new, - peer + %peer, + old_address=%old, + new_address=%new, + "Old address not replaced with new address for peer as peer is not present in the \ + routing table." ); } @@ -2276,9 +2275,9 @@ where KademliaHandlerEvent::QueryError { query_id, error } => { tracing::debug!( - "Request to {:?} in query {:?} failed with {:?}", - source, - query_id, + peer=%source, + query=?query_id, + "Request to peer in query failed with {:?}", error ); // If the query to which the error relates is still active, @@ -2367,7 +2366,7 @@ where *step = step.next(); } else { - tracing::trace!("Record with key {:?} not found at {}", key, source); + tracing::trace!(record=?key, %source, "Record not found at source"); if let KademliaCaching::Enabled { max_peers } = self.caching { let source_key = kbucket::Key::from(source); let target_key = kbucket::Key::from(key.clone()); @@ -2409,12 +2408,12 @@ where let finished = query.try_finish(peers.iter()); if !finished { tracing::debug!( - "PutRecord query ({:?}) reached quorum ({}/{}) with response \ - from peer {} but could not yet finish.", - query_id, + peer=%source, + query=?query_id, + "PutRecord query reached quorum ({}/{}) with response \ + from peer but could not yet finish.", peers.len(), quorum, - source, ); } } diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index b70406b6d45..b44fc9de992 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -481,12 +481,16 @@ impl KademliaHandler { match &endpoint { ConnectedPoint::Dialer { .. } => { tracing::debug!( - "Operating in {mode}-mode on new outbound connection to {remote_peer_id}" + peer=%remote_peer_id, + mode=%mode, + "Operating in mode on new outbound connection to peer" ); } ConnectedPoint::Listener { .. } => { tracing::debug!( - "Operating in {mode}-mode on new inbound connection to {remote_peer_id}" + peer=%remote_peer_id, + mode=%mode, + "Operating in mode on new inbound connection to peer" ); } } @@ -566,15 +570,15 @@ impl KademliaHandler { }) { *s = InboundSubstreamState::Cancelled; tracing::debug!( - "New inbound substream to {:?} exceeds inbound substream limit. \ - Removed older substream waiting to be reused.", - self.remote_peer_id, + peer=?self.remote_peer_id, + "New inbound substream to peer exceeds inbound substream limit. \ + Removed older substream waiting to be reused." ) } else { tracing::warn!( - "New inbound substream to {:?} exceeds inbound substream limit. \ - No older substream waiting to be reused. Dropping new substream.", - self.remote_peer_id, + peer=?self.remote_peer_id, + "New inbound substream to peer exceeds inbound substream limit. \ + No older substream waiting to be reused. Dropping new substream." ); return; } @@ -704,11 +708,17 @@ impl ConnectionHandler for KademliaHandler { match &self.endpoint { ConnectedPoint::Dialer { .. } => { tracing::debug!( - "Now operating in {new_mode}-mode on outbound connection with {peer}" + %peer, + mode=%new_mode, + "Now operating in mode on outbound connection with peer" ) } ConnectedPoint::Listener { local_addr, .. } => { - tracing::debug!("Now operating in {new_mode}-mode on inbound connection with {peer} assuming that one of our external addresses routes to {local_addr}") + tracing::debug!( + %peer, + mode=%new_mode, + local_address=%local_addr, + "Now operating in mode on inbound connection with peer assuming that one of our external addresses routes to the local address") } } @@ -808,18 +818,18 @@ impl ConnectionHandler for KademliaHandler { (true, ProtocolStatus::Confirmed | ProtocolStatus::Reported) => {} (true, _) => { tracing::debug!( - "Remote {} now supports our kademlia protocol on connection {}", - self.remote_peer_id, - self.connection_id, + peer=%self.remote_peer_id, + connection=%self.connection_id, + "Remote peer now supports our kademlia protocol on connection" ); self.protocol_status = ProtocolStatus::Confirmed; } (false, ProtocolStatus::Confirmed | ProtocolStatus::Reported) => { tracing::debug!( - "Remote {} no longer supports our kademlia protocol on connection {}", - self.remote_peer_id, - self.connection_id, + peer=%self.remote_peer_id, + connection=%self.connection_id, + "Remote peer no longer supports our kademlia protocol on connection" ); self.protocol_status = ProtocolStatus::NotSupported; From 2a42e73edd36839cc591aceeb6c4bd72bc06e48d Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 21 Sep 2023 18:47:26 +0300 Subject: [PATCH 030/105] mdns tracing improvements --- protocols/mdns/src/behaviour.rs | 6 +++--- protocols/mdns/src/behaviour/iface.rs | 26 +++++++++++------------ protocols/mdns/src/behaviour/iface/dns.rs | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/protocols/mdns/src/behaviour.rs b/protocols/mdns/src/behaviour.rs index fa31004537f..c4896fc1bfa 100644 --- a/protocols/mdns/src/behaviour.rs +++ b/protocols/mdns/src/behaviour.rs @@ -280,7 +280,7 @@ where } Ok(IfEvent::Down(inet)) => { if self.iface_states.contains_key(&inet.addr()) { - tracing::info!("dropping instance {}", inet.addr()); + tracing::info!(instance=%inet.addr(), "dropping instance"); self.iface_states.remove(&inet.addr()); } } @@ -300,7 +300,7 @@ where { *cur_expires = cmp::max(*cur_expires, expiration); } else { - tracing::info!("discovered: {} {}", peer, addr); + tracing::info!(%peer, address=%addr, "discovered peer on address"); self.discovered_nodes.push((peer, addr.clone(), expiration)); discovered.push((peer, addr)); } @@ -316,7 +316,7 @@ where let mut expired = Vec::new(); self.discovered_nodes.retain(|(peer, addr, expiration)| { if *expiration <= now { - tracing::info!("expired: {} {}", peer, addr); + tracing::info!(%peer, address=%addr, "expired peer on address"); expired.push((*peer, addr.clone())); return false; } diff --git a/protocols/mdns/src/behaviour/iface.rs b/protocols/mdns/src/behaviour/iface.rs index 408db2ee763..90d28651bd3 100644 --- a/protocols/mdns/src/behaviour/iface.rs +++ b/protocols/mdns/src/behaviour/iface.rs @@ -102,7 +102,7 @@ where { /// Builds a new [`InterfaceState`]. pub(crate) fn new(addr: IpAddr, config: Config, local_peer_id: PeerId) -> io::Result { - tracing::info!("creating instance on iface {}", addr); + tracing::info!(address=%addr, "creating instance on iface address"); let recv_socket = match addr { IpAddr::V4(addr) => { let socket = Socket::new(Domain::IPV4, Type::DGRAM, Some(socket2::Protocol::UDP))?; @@ -184,7 +184,7 @@ where loop { // 1st priority: Low latency: Create packet ASAP after timeout. if Pin::new(&mut self.timeout).poll_next(cx).is_ready() { - tracing::trace!("sending query on iface {}", self.addr); + tracing::trace!(address=%self.addr, "sending query on iface"); self.send_buffer.push_back(build_query()); tracing::trace!("tick on {:#?} {:#?}", self.addr, self.probe_state); @@ -209,11 +209,11 @@ where SocketAddr::new(self.multicast_addr, 5353), ) { Poll::Ready(Ok(_)) => { - tracing::trace!("sent packet on iface {}", self.addr); + tracing::trace!(address=%self.addr, "sent packet on iface address"); continue; } Poll::Ready(Err(err)) => { - tracing::error!("error sending packet on iface {} {}", self.addr, err); + tracing::error!(address=%self.addr, "error sending packet on iface address {}", err); continue; } Poll::Pending => { @@ -234,9 +234,9 @@ where { Poll::Ready(Ok(Ok(Some(MdnsPacket::Query(query))))) => { tracing::trace!( - "received query from {} on {}", - query.remote_addr(), - self.addr + address=%self.addr, + remote_address=%query.remote_addr(), + "received query from remote address on address" ); self.send_buffer.extend(build_query_response( @@ -249,9 +249,9 @@ where } Poll::Ready(Ok(Ok(Some(MdnsPacket::Response(response))))) => { tracing::trace!( - "received response from {} on {}", - response.remote_addr(), - self.addr + address=%self.addr, + remote_address=%response.remote_addr(), + "received response from remote address on address" ); self.discovered @@ -266,9 +266,9 @@ where } Poll::Ready(Ok(Ok(Some(MdnsPacket::ServiceDiscovery(disc))))) => { tracing::trace!( - "received service discovery from {} on {}", - disc.remote_addr(), - self.addr + address=%self.addr, + remote_address=%disc.remote_addr(), + "received service discovery from remote address on address" ); self.send_buffer diff --git a/protocols/mdns/src/behaviour/iface/dns.rs b/protocols/mdns/src/behaviour/iface/dns.rs index 70fca5a0d47..61fd5d329b9 100644 --- a/protocols/mdns/src/behaviour/iface/dns.rs +++ b/protocols/mdns/src/behaviour/iface/dns.rs @@ -134,7 +134,7 @@ pub(crate) fn build_query_response<'a>( records.push(txt_record); } Err(e) => { - tracing::warn!("Excluding address {} from response: {:?}", addr, e); + tracing::warn!(address=%addr, "Excluding address from response: {:?}", e); } } From 6a7fbfe1744fc1db10e12b3f8667339e2a740d0b Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 21 Sep 2023 18:50:26 +0300 Subject: [PATCH 031/105] perf tracing improvements --- protocols/perf/src/bin/perf.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protocols/perf/src/bin/perf.rs b/protocols/perf/src/bin/perf.rs index 35b38048f79..9f763170fe5 100644 --- a/protocols/perf/src/bin/perf.rs +++ b/protocols/perf/src/bin/perf.rs @@ -122,7 +122,7 @@ async fn server(server_address: SocketAddr) -> Result<()> { loop { match swarm.next().await.unwrap() { SwarmEvent::NewListenAddr { address, .. } => { - tracing::info!("Listening on {address}"); + tracing::info!(%address, "Listening on address"); } SwarmEvent::IncomingConnection { .. } => {} e @ SwarmEvent::IncomingConnectionError { .. } => { @@ -131,7 +131,7 @@ async fn server(server_address: SocketAddr) -> Result<()> { SwarmEvent::ConnectionEstablished { peer_id, endpoint, .. } => { - tracing::info!("Established connection to {:?} via {:?}", peer_id, endpoint); + tracing::info!(peer=%peer_id, ?endpoint, "Established connection to peer via endpoint"); } SwarmEvent::ConnectionClosed { .. } => {} SwarmEvent::Behaviour(()) => { From 8ec399a1798662675b1042af577351c0318a36d4 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 21 Sep 2023 18:59:18 +0300 Subject: [PATCH 032/105] the rest of the protocols --- protocols/rendezvous/src/server.rs | 4 +++- protocols/request-response/src/handler.rs | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/protocols/rendezvous/src/server.rs b/protocols/rendezvous/src/server.rs index 78b68c3cf13..6e2ba0aa08b 100644 --- a/protocols/rendezvous/src/server.rs +++ b/protocols/rendezvous/src/server.rs @@ -196,7 +196,9 @@ impl NetworkBehaviour for Behaviour { error, }) => { tracing::warn!( - "Inbound request {request_id} with peer {peer} failed: {error}" + %peer, + request=%request_id, + "Inbound request with peer failed: {error}" ); continue; diff --git a/protocols/request-response/src/handler.rs b/protocols/request-response/src/handler.rs index b20e3017444..02bb560e98d 100644 --- a/protocols/request-response/src/handler.rs +++ b/protocols/request-response/src/handler.rs @@ -149,10 +149,10 @@ where .push_back(Event::OutboundUnsupportedProtocols(info)); } StreamUpgradeError::Apply(e) => { - tracing::debug!("outbound stream {info} failed: {e}"); + tracing::debug!(request=%info, "outbound stream request failed: {e}"); } StreamUpgradeError::Io(e) => { - tracing::debug!("outbound stream {info} failed: {e}"); + tracing::debug!(request=%info, "outbound stream failed: {e}"); } } } @@ -163,7 +163,7 @@ where ::InboundProtocol, >, ) { - tracing::debug!("inbound stream {info} failed: {error}"); + tracing::debug!(request=%info, "inbound stream failed: {error}"); } } From a7236290f209196a633577f16cf6311f95d4911b Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 21 Sep 2023 19:17:13 +0300 Subject: [PATCH 033/105] remove tracing from core crate --- Cargo.lock | 2 +- core/Cargo.toml | 2 +- core/src/transport/choice.rs | 49 +++++++++++++++---------------- core/src/transport/global_only.rs | 13 ++++---- core/src/upgrade/apply.rs | 9 +++--- 5 files changed, 36 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 91ded9c7fe1..f780d51fd56 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2480,7 +2480,6 @@ dependencies = [ "libp2p-identity", "libp2p-mplex", "libp2p-noise", - "log", "multiaddr", "multihash", "multistream-select", @@ -2494,6 +2493,7 @@ dependencies = [ "serde", "smallvec", "thiserror", + "tracing", "unsigned-varint", "void", ] diff --git a/core/Cargo.toml b/core/Cargo.toml index a3912f0f5e4..6ca6f9830c2 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -17,7 +17,6 @@ futures = { version = "0.3.28", features = ["executor", "thread-pool"] } futures-timer = "3" instant = "0.1.12" libp2p-identity = { workspace = true, features = ["peerid", "ed25519"] } -log = "0.4" multiaddr = { workspace = true } multihash = { workspace = true } multistream-select = { workspace = true } @@ -30,6 +29,7 @@ rw-stream-sink = { workspace = true } serde = { version = "1", optional = true, features = ["derive"] } smallvec = "1.11.0" thiserror = "1.0" +tracing = { version = "0.1.37", features = ["log"] } unsigned-varint = "0.7" void = "1" diff --git a/core/src/transport/choice.rs b/core/src/transport/choice.rs index 8d3bfdecb79..aa3acfc3231 100644 --- a/core/src/transport/choice.rs +++ b/core/src/transport/choice.rs @@ -22,7 +22,6 @@ use crate::either::EitherFuture; use crate::transport::{ListenerId, Transport, TransportError, TransportEvent}; use either::Either; use futures::future; -use log::{debug, trace}; use multiaddr::Multiaddr; use std::{pin::Pin, task::Context, task::Poll}; @@ -52,16 +51,16 @@ where id: ListenerId, addr: Multiaddr, ) -> Result<(), TransportError> { - trace!( - "Attempting to listen on {} using {}", - addr, + tracing::trace!( + address=%addr, + "Attempting to listen on address using {}", std::any::type_name::() ); let addr = match self.0.listen_on(id, addr) { Err(TransportError::MultiaddrNotSupported(addr)) => { - debug!( - "Failed to listen on {} using {}", - addr, + tracing::debug!( + address=%addr, + "Failed to listen on address using {}", std::any::type_name::() ); addr @@ -69,16 +68,16 @@ where res => return res.map_err(|err| err.map(Either::Left)), }; - trace!( - "Attempting to listen on {} using {}", - addr, + tracing::trace!( + address=%addr, + "Attempting to listen on address using {}", std::any::type_name::() ); let addr = match self.1.listen_on(id, addr) { Err(TransportError::MultiaddrNotSupported(addr)) => { - debug!( - "Failed to listen on {} using {}", - addr, + tracing::debug!( + address=%addr, + "Failed to listen on address using {}", std::any::type_name::() ); addr @@ -94,17 +93,17 @@ where } fn dial(&mut self, addr: Multiaddr) -> Result> { - trace!( - "Attempting to dial {} using {}", - addr, + tracing::trace!( + address=%addr, + "Attempting to dial address using {}", std::any::type_name::() ); let addr = match self.0.dial(addr) { Ok(connec) => return Ok(EitherFuture::First(connec)), Err(TransportError::MultiaddrNotSupported(addr)) => { - debug!( - "Failed to dial {} using {}", - addr, + tracing::debug!( + address=%addr, + "Failed to dial address using {}", std::any::type_name::() ); addr @@ -114,17 +113,17 @@ where } }; - trace!( - "Attempting to dial {} using {}", - addr, + tracing::trace!( + address=%addr, + "Attempting to dial address using {}", std::any::type_name::() ); let addr = match self.1.dial(addr) { Ok(connec) => return Ok(EitherFuture::Second(connec)), Err(TransportError::MultiaddrNotSupported(addr)) => { - debug!( - "Failed to dial {} using {}", - addr, + tracing::debug!( + address=%addr, + "Failed to dial address using {}", std::any::type_name::() ); addr diff --git a/core/src/transport/global_only.rs b/core/src/transport/global_only.rs index 4f1fe8ab794..d6a262e3fa3 100644 --- a/core/src/transport/global_only.rs +++ b/core/src/transport/global_only.rs @@ -22,7 +22,6 @@ use crate::{ multiaddr::{Multiaddr, Protocol}, transport::{ListenerId, TransportError, TransportEvent}, }; -use log::debug; use std::{ pin::Pin, task::{Context, Poll}, @@ -292,20 +291,20 @@ impl crate::Transport for Transport { match addr.iter().next() { Some(Protocol::Ip4(a)) => { if !ipv4_global::is_global(a) { - debug!("Not dialing non global IP address {:?}.", a); + tracing::debug!(ip=?a, "Not dialing non global IP address."); return Err(TransportError::MultiaddrNotSupported(addr)); } self.inner.dial(addr) } Some(Protocol::Ip6(a)) => { if !ipv6_global::is_global(a) { - debug!("Not dialing non global IP address {:?}.", a); + tracing::debug!(ip=?a, "Not dialing non global IP address."); return Err(TransportError::MultiaddrNotSupported(addr)); } self.inner.dial(addr) } _ => { - debug!("Not dialing unsupported Multiaddress {:?}.", addr); + tracing::debug!(address=%addr, "Not dialing unsupported Multiaddress."); Err(TransportError::MultiaddrNotSupported(addr)) } } @@ -318,20 +317,20 @@ impl crate::Transport for Transport { match addr.iter().next() { Some(Protocol::Ip4(a)) => { if !ipv4_global::is_global(a) { - debug!("Not dialing non global IP address {:?}.", a); + tracing::debug!(ip=?a, "Not dialing non global IP address."); return Err(TransportError::MultiaddrNotSupported(addr)); } self.inner.dial_as_listener(addr) } Some(Protocol::Ip6(a)) => { if !ipv6_global::is_global(a) { - debug!("Not dialing non global IP address {:?}.", a); + tracing::debug!(ip=?a, "Not dialing non global IP address."); return Err(TransportError::MultiaddrNotSupported(addr)); } self.inner.dial_as_listener(addr) } _ => { - debug!("Not dialing unsupported Multiaddress {:?}.", addr); + tracing::debug!(address=%addr, "Not dialing unsupported Multiaddress"); Err(TransportError::MultiaddrNotSupported(addr)) } } diff --git a/core/src/upgrade/apply.rs b/core/src/upgrade/apply.rs index aefce686f01..15cb0348cf3 100644 --- a/core/src/upgrade/apply.rs +++ b/core/src/upgrade/apply.rs @@ -21,7 +21,6 @@ use crate::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade, UpgradeError}; use crate::{connection::ConnectedPoint, Negotiated}; use futures::{future::Either, prelude::*}; -use log::debug; use multistream_select::{self, DialerSelectFuture, ListenerSelectFuture}; use std::{mem, pin::Pin, task::Context, task::Poll}; @@ -141,11 +140,11 @@ where return Poll::Pending; } Poll::Ready(Ok(x)) => { - log::trace!("Upgraded inbound stream to {name}"); + tracing::trace!(upgrade=%name, "Upgraded inbound stream"); return Poll::Ready(Ok(x)); } Poll::Ready(Err(e)) => { - debug!("Failed to upgrade inbound stream to {name}"); + tracing::debug!(upgrade=%name, "Failed to upgrade inbound stream"); return Poll::Ready(Err(UpgradeError::Apply(e))); } } @@ -223,11 +222,11 @@ where return Poll::Pending; } Poll::Ready(Ok(x)) => { - log::trace!("Upgraded outbound stream to {name}",); + tracing::trace!(upgrade=%name, "Upgraded outbound stream"); return Poll::Ready(Ok(x)); } Poll::Ready(Err(e)) => { - debug!("Failed to upgrade outbound stream to {name}",); + tracing::debug!(upgrade=%name, "Failed to upgrade outbound stream",); return Poll::Ready(Err(UpgradeError::Apply(e))); } } From 8229030fe3b055e1bfd6fe2233bf211e0ea9ee8c Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 21 Sep 2023 19:18:34 +0300 Subject: [PATCH 034/105] removed log dependency from identity crate --- Cargo.lock | 2 +- identity/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f780d51fd56..00948374383 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2657,7 +2657,6 @@ dependencies = [ "ed25519-dalek", "hex-literal", "libsecp256k1", - "log", "multihash", "p256", "quick-protobuf", @@ -2670,6 +2669,7 @@ dependencies = [ "serde_json", "sha2 0.10.7", "thiserror", + "tracing", "void", "zeroize", ] diff --git a/identity/Cargo.toml b/identity/Cargo.toml index d8f4d9ef3ce..e7be940ed9f 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -16,7 +16,7 @@ asn1_der = { version = "0.7.6", optional = true } bs58 = { version = "0.5.0", optional = true } ed25519-dalek = { version = "2.0", optional = true, features = ["rand_core"] } libsecp256k1 = { version = "0.7.0", optional = true } -log = "0.4" +tracing = { version = "0.1.37", features = ["log"] } multihash = { version = "0.19.1", optional = true } p256 = { version = "0.13", default-features = false, features = ["ecdsa", "std", "pem"], optional = true } quick-protobuf = "0.8.1" From 0c0e13f931e3998bdbc2e95656bb9edb0e9e51b7 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 21 Sep 2023 19:28:46 +0300 Subject: [PATCH 035/105] swap log w/ trace for interop-tests --- Cargo.lock | 1 - interop-tests/Cargo.toml | 2 +- interop-tests/src/lib.rs | 14 +++++++------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 00948374383..c2483d03f05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2215,7 +2215,6 @@ dependencies = [ "libp2p-mplex", "libp2p-webrtc", "libp2p-webrtc-websys", - "log", "mime_guess", "rand 0.8.5", "redis", diff --git a/interop-tests/Cargo.toml b/interop-tests/Cargo.toml index 1966aee414d..936003ef459 100644 --- a/interop-tests/Cargo.toml +++ b/interop-tests/Cargo.toml @@ -13,8 +13,8 @@ anyhow = "1" either = "1.9.0" env_logger = "0.10.0" futures = "0.3.28" -log = "0.4" serde = { version = "1", features = ["derive"] } +tracing = { version = "0.1.37", features = ["log"] } rand = "0.8.5" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/interop-tests/src/lib.rs b/interop-tests/src/lib.rs index 40c06b57810..4f33480b502 100644 --- a/interop-tests/src/lib.rs +++ b/interop-tests/src/lib.rs @@ -45,7 +45,7 @@ pub async fn run_test( .idle_connection_timeout(Duration::from_secs(5)) .build(); - log::info!("Running ping test: {}", swarm.local_peer_id()); + tracing::info!(local_peer=%swarm.local_peer_id(), "Running ping test"); let mut maybe_id = None; @@ -70,7 +70,7 @@ pub async fn run_test( let handshake_start = Instant::now(); swarm.dial(other.parse::()?)?; - log::info!("Test instance, dialing multiaddress on: {}.", other); + tracing::info!("Test instance, dialing multiaddress on: {}.", other); let rtt = loop { if let Some(SwarmEvent::Behaviour(BehaviourEvent::Ping(ping::Event { @@ -78,7 +78,7 @@ pub async fn run_test( .. }))) = swarm.next().await { - log::info!("Ping successful: {rtt:?}"); + tracing::info!(?rtt, "Ping successful"); break rtt.as_micros() as f32 / 1000.; } }; @@ -97,9 +97,9 @@ pub async fn run_test( Some(id) => id, }; - log::info!( - "Test instance, listening for incoming connections on: {:?}.", - local_addr + tracing::info!( + address=%local_addr, + "Test instance, listening for incoming connections on address" ); loop { @@ -147,7 +147,7 @@ pub async fn run_test_wasm( base_url: &str, ) -> Result<(), JsValue> { let result = run_test(transport, ip, is_dialer, test_timeout_secs, base_url).await; - log::info!("Sending test result: {result:?}"); + tracing::info!("Sending test result: {result:?}"); reqwest::Client::new() .post(&format!("http://{}/results", base_url)) .json(&result.map_err(|e| e.to_string())) From eba436a03abc536cc534e7ba4a8012704e27fa84 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 21 Sep 2023 19:30:39 +0300 Subject: [PATCH 036/105] browser-webrtc example tracing --- Cargo.lock | 2 +- examples/browser-webrtc/Cargo.toml | 2 +- examples/browser-webrtc/src/main.rs | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c2483d03f05..ef1184fa2cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -674,7 +674,6 @@ dependencies = [ "libp2p", "libp2p-webrtc", "libp2p-webrtc-websys", - "log", "mime_guess", "rand 0.8.5", "rust-embed", @@ -682,6 +681,7 @@ dependencies = [ "tokio-util", "tower", "tower-http", + "tracing", "wasm-bindgen", "wasm-bindgen-futures", "wasm-logger", diff --git a/examples/browser-webrtc/Cargo.toml b/examples/browser-webrtc/Cargo.toml index 99263dde2b3..e78813dc08a 100644 --- a/examples/browser-webrtc/Cargo.toml +++ b/examples/browser-webrtc/Cargo.toml @@ -16,8 +16,8 @@ crate-type = ["cdylib"] anyhow = "1.0.72" env_logger = "0.10" futures = "0.3.28" -log = "0.4" rand = "0.8" +tracing = { version = "0.1.37", features = ["log"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] axum = "0.6.19" diff --git a/examples/browser-webrtc/src/main.rs b/examples/browser-webrtc/src/main.rs index 8a4034a436e..9339b186877 100644 --- a/examples/browser-webrtc/src/main.rs +++ b/examples/browser-webrtc/src/main.rs @@ -54,11 +54,11 @@ async fn main() -> anyhow::Result<()> { .iter() .any(|e| e == Protocol::Ip4(Ipv4Addr::LOCALHOST)) { - log::debug!("Ignoring localhost address to make sure the example works in Firefox"); + tracing::debug!("Ignoring localhost address to make sure the example works in Firefox"); continue; } - log::info!("Listening on: {address}"); + tracing::info!("Listening on: {address}"); break address; } @@ -72,7 +72,7 @@ async fn main() -> anyhow::Result<()> { loop { tokio::select! { swarm_event = swarm.next() => { - log::trace!("Swarm Event: {:?}", swarm_event) + tracing::trace!("Swarm Event: {:?}", swarm_event) }, _ = tokio::signal::ctrl_c() => { break; @@ -108,7 +108,7 @@ pub(crate) async fn serve(libp2p_transport: Multiaddr) { let addr = SocketAddr::new(listen_addr.into(), 8080); - log::info!("Serving client files at http://{addr}"); + tracing::info!("Serving client files at http://{addr}"); axum::Server::bind(&addr) .serve(server.into_make_service()) @@ -139,7 +139,7 @@ async fn get_index( /// Serves the static files generated by `wasm-pack`. async fn get_static_file(Path(path): Path) -> Result { - log::debug!("Serving static file: {path}"); + tracing::debug!("Serving static file: {path}"); let content = StaticFiles::get(&path).ok_or(StatusCode::NOT_FOUND)?.data; let content_type = mime_guess::from_path(path) From 863ad7ae08dc541d8bf1f046fac03231d6291477 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 21 Sep 2023 19:33:38 +0300 Subject: [PATCH 037/105] dcutr example tracing --- Cargo.lock | 1 - examples/dcutr/Cargo.toml | 1 - examples/dcutr/src/main.rs | 21 ++++++++++----------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ef1184fa2cc..4a1699a8e34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1237,7 +1237,6 @@ dependencies = [ "futures", "futures-timer", "libp2p", - "log", "tracing", "tracing-subscriber", ] diff --git a/examples/dcutr/Cargo.toml b/examples/dcutr/Cargo.toml index 2b7922a3510..cf3bc3eaefa 100644 --- a/examples/dcutr/Cargo.toml +++ b/examples/dcutr/Cargo.toml @@ -11,6 +11,5 @@ env_logger = "0.10.0" futures = "0.3.28" futures-timer = "3.0" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "dcutr", "identify", "macros", "noise", "ping", "quic", "relay", "rendezvous", "tcp", "tokio", "yamux"] } -log = "0.4" tracing = { version = "0.1.37", features = ["log"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/dcutr/src/main.rs b/examples/dcutr/src/main.rs index ec5d6784a72..230f760db1b 100644 --- a/examples/dcutr/src/main.rs +++ b/examples/dcutr/src/main.rs @@ -39,7 +39,6 @@ use libp2p::{ swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent}, tcp, yamux, PeerId, }; -use log::info; use std::error::Error; use std::str::FromStr; use tracing::level_filters::LevelFilter; @@ -190,7 +189,7 @@ fn main() -> Result<(), Box> { event = swarm.next() => { match event.unwrap() { SwarmEvent::NewListenAddr { address, .. } => { - info!("Listening on {:?}", address); + tracing::info!(%address, "Listening on address"); } event => panic!("{event:?}"), } @@ -217,14 +216,14 @@ fn main() -> Result<(), Box> { SwarmEvent::ConnectionEstablished { .. } => {} SwarmEvent::Behaviour(Event::Ping(_)) => {} SwarmEvent::Behaviour(Event::Identify(identify::Event::Sent { .. })) => { - info!("Told relay its public address."); + tracing::info!("Told relay its public address."); told_relay_observed_addr = true; } SwarmEvent::Behaviour(Event::Identify(identify::Event::Received { info: identify::Info { observed_addr, .. }, .. })) => { - info!("Relay told us our public address: {:?}", observed_addr); + tracing::info!(address=%observed_addr, "Relay told us our public address"); swarm.add_external_address(observed_addr); learned_observed_addr = true; } @@ -258,31 +257,31 @@ fn main() -> Result<(), Box> { loop { match swarm.next().await.unwrap() { SwarmEvent::NewListenAddr { address, .. } => { - info!("Listening on {:?}", address); + tracing::info!(%address, "Listening on address"); } SwarmEvent::Behaviour(Event::Relay( relay::client::Event::ReservationReqAccepted { .. }, )) => { assert!(opts.mode == Mode::Listen); - info!("Relay accepted our reservation request."); + tracing::info!("Relay accepted our reservation request."); } SwarmEvent::Behaviour(Event::Relay(event)) => { - info!("{:?}", event) + tracing::info!(?event) } SwarmEvent::Behaviour(Event::Dcutr(event)) => { - info!("{:?}", event) + tracing::info!(?event) } SwarmEvent::Behaviour(Event::Identify(event)) => { - info!("{:?}", event) + tracing::info!(?event) } SwarmEvent::Behaviour(Event::Ping(_)) => {} SwarmEvent::ConnectionEstablished { peer_id, endpoint, .. } => { - info!("Established connection to {:?} via {:?}", peer_id, endpoint); + tracing::info!(peer=%peer_id, endpoint=?endpoint, "Established connection to peer via endpoint"); } SwarmEvent::OutgoingConnectionError { peer_id, error, .. } => { - info!("Outgoing connection error to {:?}: {:?}", peer_id, error); + tracing::info!(peer=?peer_id, "Outgoing connection error to peer: {:?}", error); } _ => {} } From 06bfcd2416e73fa4db8dae5988f15a5af4391b7f Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 21 Sep 2023 19:34:32 +0300 Subject: [PATCH 038/105] memory-connection-limits tracing --- Cargo.lock | 4 ++-- misc/memory-connection-limits/Cargo.toml | 2 +- misc/memory-connection-limits/src/lib.rs | 2 +- misc/multistream-select/Cargo.toml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4a1699a8e34..c06527a82a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2746,10 +2746,10 @@ dependencies = [ "libp2p-swarm", "libp2p-swarm-derive", "libp2p-swarm-test", - "log", "memory-stats", "rand 0.8.5", "sysinfo", + "tracing", "void", ] @@ -3604,12 +3604,12 @@ dependencies = [ "env_logger 0.10.0", "futures", "futures_ringbuf", - "log", "pin-project", "quickcheck-ext", "rand 0.8.5", "rw-stream-sink", "smallvec", + "tracing", "unsigned-varint", ] diff --git a/misc/memory-connection-limits/Cargo.toml b/misc/memory-connection-limits/Cargo.toml index 6bfecfd2b0e..fbf034124dc 100644 --- a/misc/memory-connection-limits/Cargo.toml +++ b/misc/memory-connection-limits/Cargo.toml @@ -14,8 +14,8 @@ memory-stats = { version = "1", features = ["always_use_statm"] } libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true, features = ["peerid"] } -log = "0.4" sysinfo = "0.29" +tracing = { version = "0.1.37", features = ["log"] } void = "1" [dev-dependencies] diff --git a/misc/memory-connection-limits/src/lib.rs b/misc/memory-connection-limits/src/lib.rs index 33e40b11843..76e1a4a380a 100644 --- a/misc/memory-connection-limits/src/lib.rs +++ b/misc/memory-connection-limits/src/lib.rs @@ -127,7 +127,7 @@ impl Behaviour { let stats = match memory_stats::memory_stats() { Some(stats) => stats, None => { - log::warn!("Failed to retrieve process memory stats"); + tracing::warn!("Failed to retrieve process memory stats"); return; } }; diff --git a/misc/multistream-select/Cargo.toml b/misc/multistream-select/Cargo.toml index 711a80145e1..5f7290e4474 100644 --- a/misc/multistream-select/Cargo.toml +++ b/misc/multistream-select/Cargo.toml @@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] bytes = "1" futures = "0.3" -log = "0.4" +tracing = { version = "0.1.37", features = ["log"] } pin-project = "1.1.3" smallvec = "1.11.0" unsigned-varint = "0.7" From 988525020bf8862fe8322a2e57c03fce8e048374 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 21 Sep 2023 19:38:17 +0300 Subject: [PATCH 039/105] multistream-select tracing --- misc/multistream-select/src/dialer_select.rs | 12 ++++++------ misc/multistream-select/src/length_delimited.rs | 2 +- misc/multistream-select/src/listener_select.rs | 16 ++++++++-------- misc/multistream-select/src/negotiated.rs | 4 ++-- misc/multistream-select/src/protocol.rs | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/misc/multistream-select/src/dialer_select.rs b/misc/multistream-select/src/dialer_select.rs index af9f79d876a..fbf61ee0e71 100644 --- a/misc/multistream-select/src/dialer_select.rs +++ b/misc/multistream-select/src/dialer_select.rs @@ -131,7 +131,7 @@ where if let Err(err) = Pin::new(&mut io).start_send(Message::Protocol(p.clone())) { return Poll::Ready(Err(From::from(err))); } - log::debug!("Dialer: Proposed protocol: {}", p); + tracing::debug!(protocol=%p, "Dialer: Proposed protocol"); if this.protocols.peek().is_some() { *this.state = State::FlushProtocol { io, protocol } @@ -143,7 +143,7 @@ where // the dialer supports for this negotiation. Notably, // the dialer expects a regular `V1` response. Version::V1Lazy => { - log::debug!("Dialer: Expecting proposed protocol: {}", p); + tracing::debug!(protocol=%p, "Dialer: Expecting proposed protocol"); let hl = HeaderLine::from(Version::V1Lazy); let io = Negotiated::expecting(io.into_reader(), p, Some(hl)); return Poll::Ready(Ok((protocol, io))); @@ -180,14 +180,14 @@ where *this.state = State::AwaitProtocol { io, protocol }; } Message::Protocol(ref p) if p.as_ref() == protocol.as_ref() => { - log::debug!("Dialer: Received confirmation for protocol: {}", p); + tracing::debug!(protocol=%p, "Dialer: Received confirmation for protocol"); let io = Negotiated::completed(io.into_inner()); return Poll::Ready(Ok((protocol, io))); } Message::NotAvailable => { - log::debug!( - "Dialer: Received rejection of protocol: {}", - protocol.as_ref() + tracing::debug!( + protocol=%protocol.as_ref(), + "Dialer: Received rejection of protocol" ); let protocol = this.protocols.next().ok_or(NegotiationError::Failed)?; *this.state = State::SendProtocol { io, protocol } diff --git a/misc/multistream-select/src/length_delimited.rs b/misc/multistream-select/src/length_delimited.rs index cff2f4abc39..a2c36b05ece 100644 --- a/misc/multistream-select/src/length_delimited.rs +++ b/misc/multistream-select/src/length_delimited.rs @@ -170,7 +170,7 @@ where if (buf[*pos - 1] & 0x80) == 0 { // MSB is not set, indicating the end of the length prefix. let (len, _) = unsigned_varint::decode::u16(buf).map_err(|e| { - log::debug!("invalid length prefix: {}", e); + tracing::debug!("invalid length prefix: {}", e); io::Error::new(io::ErrorKind::InvalidData, "invalid length prefix") })?; diff --git a/misc/multistream-select/src/listener_select.rs b/misc/multistream-select/src/listener_select.rs index 5386114fab8..5738ef413de 100644 --- a/misc/multistream-select/src/listener_select.rs +++ b/misc/multistream-select/src/listener_select.rs @@ -52,7 +52,7 @@ where .filter_map(|n| match Protocol::try_from(n.as_ref()) { Ok(p) => Some((n, p)), Err(e) => { - log::warn!( + tracing::warn!( "Listener: Ignoring invalid protocol: {} due to {}", n.as_ref(), e @@ -186,7 +186,7 @@ where // the dialer also raises `NegotiationError::Failed` when finally // reading the `N/A` response. if let ProtocolError::InvalidMessage = &err { - log::trace!( + tracing::trace!( "Listener: Negotiation failed with invalid \ message after protocol rejection." ); @@ -194,7 +194,7 @@ where } if let ProtocolError::IoError(e) = &err { if e.kind() == std::io::ErrorKind::UnexpectedEof { - log::trace!( + tracing::trace!( "Listener: Negotiation failed with EOF \ after protocol rejection." ); @@ -228,10 +228,10 @@ where }); let message = if protocol.is_some() { - log::debug!("Listener: confirming protocol: {}", p); + tracing::debug!(protocol=%p, "Listener: confirming protocol"); Message::Protocol(p.clone()) } else { - log::debug!("Listener: rejecting protocol: {}", p.as_ref()); + tracing::debug!(protocol=%p.as_ref(), "Listener: rejecting protocol"); Message::NotAvailable }; @@ -287,9 +287,9 @@ where // Otherwise expect to receive another message. match protocol { Some(protocol) => { - log::debug!( - "Listener: sent confirmed protocol: {}", - protocol.as_ref() + tracing::debug!( + protocol=%protocol.as_ref(), + "Listener: sent confirmed protocol" ); let io = Negotiated::completed(io.into_inner()); return Poll::Ready(Ok((protocol, io))); diff --git a/misc/multistream-select/src/negotiated.rs b/misc/multistream-select/src/negotiated.rs index 941b60765ca..8eda11c0f9a 100644 --- a/misc/multistream-select/src/negotiated.rs +++ b/misc/multistream-select/src/negotiated.rs @@ -171,7 +171,7 @@ impl Negotiated { if let Message::Protocol(p) = &msg { if p.as_ref() == protocol.as_ref() { - log::debug!("Negotiated: Received confirmation for protocol: {}", p); + tracing::debug!(protocol=%p, "Negotiated: Received confirmation for protocol"); *this.state = State::Completed { io: io.into_inner(), }; @@ -317,7 +317,7 @@ where StateProj::Expecting { io, .. } => { let close_poll = io.poll_close(cx); if let Poll::Ready(Ok(())) = close_poll { - log::debug!("Stream closed. Confirmation from remote for optimstic protocol negotiation still pending.") + tracing::debug!("Stream closed. Confirmation from remote for optimstic protocol negotiation still pending.") } close_poll } diff --git a/misc/multistream-select/src/protocol.rs b/misc/multistream-select/src/protocol.rs index be2f3122da0..d5c2bfa773a 100644 --- a/misc/multistream-select/src/protocol.rs +++ b/misc/multistream-select/src/protocol.rs @@ -403,7 +403,7 @@ where return Poll::Ready(None); }; - log::trace!("Received message: {:?}", msg); + tracing::trace!(message=?msg, "Received message"); Poll::Ready(Some(Ok(msg))) } From 365e21d86aa1889dd5c4c50d7db6433e7948b678 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 21 Sep 2023 19:39:54 +0300 Subject: [PATCH 040/105] server tracing --- Cargo.lock | 2 +- misc/server/Cargo.toml | 2 +- misc/server/src/http_service.rs | 3 +-- misc/server/src/main.rs | 23 +++++++++++------------ 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c06527a82a8..b3a59aa3d7b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3047,12 +3047,12 @@ dependencies = [ "futures-timer", "hyper", "libp2p", - "log", "prometheus-client", "serde", "serde_derive", "serde_json", "tokio", + "tracing", "zeroize", ] diff --git a/misc/server/Cargo.toml b/misc/server/Cargo.toml index aa259ce8214..b81b8f743ec 100644 --- a/misc/server/Cargo.toml +++ b/misc/server/Cargo.toml @@ -18,10 +18,10 @@ futures = "0.3" futures-timer = "3" hyper = { version = "0.14", features = ["server", "tcp", "http1"] } libp2p = { workspace = true, features = ["autonat", "dns", "tokio", "noise", "tcp", "yamux", "identify", "kad", "ping", "relay", "metrics", "rsa", "macros", "quic"] } -log = "0.4" prometheus-client = "0.21.2" serde = "1.0.188" serde_derive = "1.0.125" serde_json = "1.0" tokio = { version = "1", features = ["rt-multi-thread", "macros"] } +tracing = { version = "0.1.37", features = ["log"] } zeroize = "1" diff --git a/misc/server/src/http_service.rs b/misc/server/src/http_service.rs index 1f5ebaff593..568eb6e4547 100644 --- a/misc/server/src/http_service.rs +++ b/misc/server/src/http_service.rs @@ -21,7 +21,6 @@ use hyper::http::StatusCode; use hyper::service::Service; use hyper::{Body, Method, Request, Response, Server}; -use log::info; use prometheus_client::encoding::text::encode; use prometheus_client::registry::Registry; use std::future::Future; @@ -38,7 +37,7 @@ pub(crate) async fn metrics_server( let addr = ([0, 0, 0, 0], 8888).into(); let server = Server::bind(&addr).serve(MakeMetricService::new(registry, metrics_path.clone())); - info!( + tracing::info!( "Metrics server on http://{}{}", server.local_addr(), metrics_path diff --git a/misc/server/src/main.rs b/misc/server/src/main.rs index 26737085d91..2d9ec032f19 100644 --- a/misc/server/src/main.rs +++ b/misc/server/src/main.rs @@ -17,7 +17,6 @@ use libp2p::swarm::{SwarmBuilder, SwarmEvent}; use libp2p::tcp; use libp2p::yamux; use libp2p::Transport; -use log::{debug, info, warn}; use prometheus_client::metrics::info::Info; use prometheus_client::registry::Registry; use std::error::Error; @@ -108,25 +107,25 @@ async fn main() -> Result<(), Box> { let mut swarm = SwarmBuilder::with_tokio_executor(transport, behaviour, local_peer_id).build(); if config.addresses.swarm.is_empty() { - warn!("No listen addresses configured."); + tracing::warn!("No listen addresses configured."); } for address in &config.addresses.swarm { match swarm.listen_on(address.clone()) { Ok(_) => {} Err(e @ libp2p::TransportError::MultiaddrNotSupported(_)) => { - warn!("Failed to listen on {address}, continuing anyways, {e}") + tracing::warn!("Failed to listen on {address}, continuing anyways, {e}") } Err(e) => return Err(e.into()), } } if config.addresses.append_announce.is_empty() { - warn!("No external addresses configured."); + tracing::warn!("No external addresses configured."); } for address in &config.addresses.append_announce { swarm.add_external_address(address.clone()) } - info!( + tracing::info!( "External addresses: {:?}", swarm.external_addresses().collect::>() ); @@ -141,7 +140,7 @@ async fn main() -> Result<(), Box> { ); tokio::spawn(async move { if let Err(e) = http_service::metrics_server(metric_registry, opt.metrics_path).await { - log::error!("Metrics server failed: {e}"); + tracing::error!("Metrics server failed: {e}"); } }); @@ -161,7 +160,7 @@ async fn main() -> Result<(), Box> { metrics.record(&event); match event { SwarmEvent::Behaviour(behaviour::BehaviourEvent::Identify(e)) => { - info!("{:?}", e); + tracing::info!("{:?}", e); metrics.record(&e); if let identify::Event::Received { @@ -186,24 +185,24 @@ async fn main() -> Result<(), Box> { } } SwarmEvent::Behaviour(behaviour::BehaviourEvent::Ping(e)) => { - debug!("{:?}", e); + tracing::debug!("{:?}", e); metrics.record(&e); } SwarmEvent::Behaviour(behaviour::BehaviourEvent::Kademlia(e)) => { - debug!("{:?}", e); + tracing::debug!("{:?}", e); metrics.record(&e); } SwarmEvent::Behaviour(behaviour::BehaviourEvent::Relay(e)) => { - info!("{:?}", e); + tracing::info!("{:?}", e); metrics.record(&e) } SwarmEvent::Behaviour(behaviour::BehaviourEvent::Autonat(e)) => { - info!("{:?}", e); + tracing::info!("{:?}", e); // TODO: Add metric recording for `NatStatus`. // metrics.record(&e) } SwarmEvent::NewListenAddr { address, .. } => { - info!("Listening on {address:?}"); + tracing::info!("Listening on {address:?}"); } _ => {} } From f523e0792d2850a26ea659f6c0052ca44174b82b Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 Sep 2023 13:35:51 +0300 Subject: [PATCH 041/105] muxer crate tracing --- Cargo.lock | 4 +- misc/webrtc-utils/Cargo.toml | 4 +- misc/webrtc-utils/src/sdp.rs | 2 +- misc/webrtc-utils/src/stream/drop_listener.rs | 2 +- muxers/mplex/Cargo.toml | 2 +- muxers/mplex/src/io.rs | 223 +++++++++++------- 6 files changed, 144 insertions(+), 93 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b3a59aa3d7b..a9fa97a3e63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2786,12 +2786,12 @@ dependencies = [ "libp2p-muxer-test-harness", "libp2p-plaintext", "libp2p-tcp", - "log", "nohash-hasher", "parking_lot", "quickcheck-ext", "rand 0.8.5", "smallvec", + "tracing", "unsigned-varint", ] @@ -3237,7 +3237,6 @@ dependencies = [ "libp2p-core", "libp2p-identity", "libp2p-noise", - "log", "quick-protobuf", "quick-protobuf-codec", "rand 0.8.5", @@ -3245,6 +3244,7 @@ dependencies = [ "sha2 0.10.7", "thiserror", "tinytemplate", + "tracing", "unsigned-varint", ] diff --git a/misc/webrtc-utils/Cargo.toml b/misc/webrtc-utils/Cargo.toml index 9fa13284a5c..a25c2ae1c8e 100644 --- a/misc/webrtc-utils/Cargo.toml +++ b/misc/webrtc-utils/Cargo.toml @@ -11,13 +11,13 @@ version = "0.1.0" publish = false # TEMP fix for https://github.com/obi1kenobi/cargo-semver-checks-action/issues/53. [dependencies] +asynchronous-codec = "0.6" bytes = "1" futures = "0.3" hex = "0.4" libp2p-core = { workspace = true } libp2p-identity = { workspace = true } libp2p-noise = { workspace = true } -log = "0.4.19" quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } rand = "0.8" @@ -25,7 +25,7 @@ serde = { version = "1.0", features = ["derive"] } sha2 = "0.10.7" thiserror = "1" tinytemplate = "1.2" -asynchronous-codec = "0.6" +tracing = { version = "0.1.37", features = ["log"] } [dev-dependencies] hex-literal = "0.4" diff --git a/misc/webrtc-utils/src/sdp.rs b/misc/webrtc-utils/src/sdp.rs index 7c4facaf27e..0796548f449 100644 --- a/misc/webrtc-utils/src/sdp.rs +++ b/misc/webrtc-utils/src/sdp.rs @@ -34,7 +34,7 @@ pub fn answer(addr: SocketAddr, server_fingerprint: Fingerprint, client_ufrag: & client_ufrag, ); - log::trace!("Created SDP answer: {answer}"); + tracing::trace!(%answer, "Created SDP answer"); answer } diff --git a/misc/webrtc-utils/src/stream/drop_listener.rs b/misc/webrtc-utils/src/stream/drop_listener.rs index b638ea84b09..9745e3d4364 100644 --- a/misc/webrtc-utils/src/stream/drop_listener.rs +++ b/misc/webrtc-utils/src/stream/drop_listener.rs @@ -79,7 +79,7 @@ where return Poll::Ready(Ok(())); } Poll::Ready(Err(Canceled)) => { - log::info!("Stream dropped without graceful close, sending Reset"); + tracing::info!("Stream dropped without graceful close, sending Reset"); *state = State::SendingReset { stream }; continue; } diff --git a/muxers/mplex/Cargo.toml b/muxers/mplex/Cargo.toml index 7a98fd1350b..6ad55a284f6 100644 --- a/muxers/mplex/Cargo.toml +++ b/muxers/mplex/Cargo.toml @@ -16,11 +16,11 @@ futures = "0.3.28" asynchronous-codec = "0.6" libp2p-core = { workspace = true } libp2p-identity = { workspace = true } -log = "0.4" nohash-hasher = "0.2" parking_lot = "0.12" rand = "0.8" smallvec = "1.11.0" +tracing = { version = "0.1.37", features = ["log"] } unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } [dev-dependencies] diff --git a/muxers/mplex/src/io.rs b/muxers/mplex/src/io.rs index 8002ad383d6..67d3bd0b5aa 100644 --- a/muxers/mplex/src/io.rs +++ b/muxers/mplex/src/io.rs @@ -24,7 +24,6 @@ use asynchronous_codec::Framed; use bytes::Bytes; use futures::task::{waker_ref, ArcWake, AtomicWaker, WakerRef}; use futures::{prelude::*, ready, stream::Fuse}; -use log::{debug, trace}; use nohash_hasher::{IntMap, IntSet}; use parking_lot::Mutex; use smallvec::SmallVec; @@ -117,7 +116,7 @@ where /// Creates a new multiplexed I/O stream. pub(crate) fn new(io: C, config: MplexConfig) -> Self { let id = ConnectionId(rand::random()); - debug!("New multiplexed connection: {}", id); + tracing::debug!(connection=%id, "New multiplexed connection"); Multiplexed { id, config, @@ -254,9 +253,11 @@ where // Check the stream limits. if self.substreams.len() >= self.config.max_substreams { - debug!( - "{}: Maximum number of substreams reached ({})", - self.id, self.config.max_substreams + tracing::debug!( + connection=%self.id, + total_substreams=%self.substreams.len(), + max_substreams=%self.config.max_substreams, + "Maximum number of substreams reached" ); self.notifier_open.register(cx.waker()); return Poll::Pending; @@ -276,11 +277,11 @@ where buf: Default::default(), }, ); - debug!( - "{}: New outbound substream: {} (total {})", - self.id, - stream_id, - self.substreams.len() + tracing::debug!( + connection=%self.id, + substream=%stream_id, + total_substreams=%self.substreams.len(), + "New outbound substream" ); // The flush is delayed and the `Open` frame may be sent // together with other frames in the same transport packet. @@ -348,7 +349,11 @@ where if self.check_max_pending_frames().is_err() { return; } - trace!("{}: Pending close for stream {}", self.id, id); + tracing::trace!( + connection=%self.id, + substream=%id, + "Pending close for substream" + ); self.pending_frames .push_front(Frame::Close { stream_id: id }); } @@ -356,7 +361,11 @@ where if self.check_max_pending_frames().is_err() { return; } - trace!("{}: Pending reset for stream {}", self.id, id); + tracing::trace!( + connection=%self.id, + substream=%id, + "Pending reset for substream" + ); self.pending_frames .push_front(Frame::Reset { stream_id: id }); } @@ -476,11 +485,11 @@ where frame @ Frame::Open { .. } => { if let Some(id) = self.on_open(frame.remote_id())? { self.open_buffer.push_front(id); - trace!( - "{}: Buffered new inbound stream {} (total: {})", - self.id, - id, - self.open_buffer.len() + tracing::trace!( + connection=%self.id, + inbound_stream=%id, + inbound_buffer_len=%self.open_buffer.len(), + "Buffered new inbound stream" ); self.notifier_read.wake_next_stream(); } @@ -516,7 +525,11 @@ where self.guard_open()?; ready!(self.poll_flush(cx))?; - trace!("{}: Flushed substream {}", self.id, id); + tracing::trace!( + connection=%self.id, + substream=%id, + "Flushed substream" + ); Poll::Ready(Ok(())) } @@ -554,7 +567,11 @@ where self.substreams.insert(id, SubstreamState::Open { buf }); Poll::Pending } else { - debug!("{}: Closed substream {} (half-close)", self.id, id); + tracing::debug!( + connection=%self.id, + substream=%id, + "Closed substream (half-close)" + ); self.substreams .insert(id, SubstreamState::SendClosed { buf }); Poll::Ready(Ok(())) @@ -569,7 +586,11 @@ where .insert(id, SubstreamState::RecvClosed { buf }); Poll::Pending } else { - debug!("{}: Closed substream {}", self.id, id); + tracing::debug!( + connection=%self.id, + substream=%id, + "Closed substream" + ); self.substreams.insert(id, SubstreamState::Closed { buf }); Poll::Ready(Ok(())) } @@ -589,7 +610,7 @@ where match ready!(self.io.poll_ready_unpin(&mut Context::from_waker(&waker))) { Ok(()) => { let frame = frame(); - trace!("{}: Sending {:?}", self.id, frame); + tracing::trace!(connection=%self.id, ?frame, "Sending frame"); match self.io.start_send_unpin(frame) { Ok(()) => Poll::Ready(Ok(())), Err(e) => Poll::Ready(self.on_error(e)), @@ -618,7 +639,11 @@ where // Perform any pending flush before reading. if let Some(id) = &stream_id { if self.pending_flush_open.contains(id) { - trace!("{}: Executing pending flush for {}.", self.id, id); + tracing::trace!( + connection=%self.id, + substream=%id, + "Executing pending flush for substream" + ); ready!(self.poll_flush(cx))?; self.pending_flush_open = Default::default(); } @@ -634,9 +659,9 @@ where if !self.notifier_read.wake_read_stream(*blocked_id) { // No task dedicated to the blocked stream woken, so schedule // this task again to have a chance at progress. - trace!( - "{}: No task to read from blocked stream. Waking current task.", - self.id + tracing::trace!( + connection=%self.id, + "No task to read from blocked stream. Waking current task." ); cx.waker().clone().wake(); } else if let Some(id) = stream_id { @@ -664,7 +689,7 @@ where }; match ready!(self.io.poll_next_unpin(&mut Context::from_waker(&waker))) { Some(Ok(frame)) => { - trace!("{}: Received {:?}", self.id, frame); + tracing::trace!(connection=%self.id, ?frame, "Received frame"); Poll::Ready(Ok(frame)) } Some(Err(e)) => Poll::Ready(self.on_error(e)), @@ -677,9 +702,10 @@ where let id = id.into_local(); if self.substreams.contains_key(&id) { - debug!( - "{}: Received unexpected `Open` frame for open substream {}", - self.id, id + tracing::debug!( + connection=%self.id, + substream=%id, + "Received unexpected `Open` frame for open substream", ); return self.on_error(io::Error::new( io::ErrorKind::Other, @@ -688,12 +714,17 @@ where } if self.substreams.len() >= self.config.max_substreams { - debug!( - "{}: Maximum number of substreams exceeded: {}", - self.id, self.config.max_substreams + tracing::debug!( + connection=%self.id, + max_substreams=%self.config.max_substreams, + "Maximum number of substreams exceeded" ); self.check_max_pending_frames()?; - debug!("{}: Pending reset for new stream {}", self.id, id); + tracing::debug!( + connection=%self.id, + substream=%id, + "Pending reset for new substream" + ); self.pending_frames .push_front(Frame::Reset { stream_id: id }); return Ok(None); @@ -706,11 +737,11 @@ where }, ); - debug!( - "{}: New inbound substream: {} (total {})", - self.id, - id, - self.substreams.len() + tracing::debug!( + connection=%self.id, + substream=%id, + total_substreams=%self.substreams.len(), + "New inbound substream" ); Ok(Some(id)) @@ -721,23 +752,27 @@ where if let Some(state) = self.substreams.remove(&id) { match state { SubstreamState::Closed { .. } => { - trace!( - "{}: Ignoring reset for mutually closed substream {}.", - self.id, - id + tracing::trace!( + connection=%self.id, + substream=%id, + "Ignoring reset for mutually closed substream" ); } SubstreamState::Reset { .. } => { - trace!( - "{}: Ignoring redundant reset for already reset substream {}", - self.id, - id + tracing::trace!( + connection=%self.id, + substream=%id, + "Ignoring redundant reset for already reset substream" ); } SubstreamState::RecvClosed { buf } | SubstreamState::SendClosed { buf } | SubstreamState::Open { buf } => { - debug!("{}: Substream {} reset by remote.", self.id, id); + tracing::debug!( + connection=%self.id, + substream=%id, + "Substream reset by remote" + ); self.substreams.insert(id, SubstreamState::Reset { buf }); // Notify tasks interested in reading from that stream, // so they may read the EOF. @@ -745,10 +780,10 @@ where } } } else { - trace!( - "{}: Ignoring `Reset` for unknown substream {}. Possibly dropped earlier.", - self.id, - id + tracing::trace!( + connection=%self.id, + substream=%id, + "Ignoring `Reset` for unknown substream, possibly dropped earlier" ); } } @@ -758,32 +793,36 @@ where if let Some(state) = self.substreams.remove(&id) { match state { SubstreamState::RecvClosed { .. } | SubstreamState::Closed { .. } => { - debug!( - "{}: Ignoring `Close` frame for closed substream {}", - self.id, id + tracing::debug!( + connection=%self.id, + substream=%id, + "Ignoring `Close` frame for closed substream" ); self.substreams.insert(id, state); } SubstreamState::Reset { buf } => { - debug!( - "{}: Ignoring `Close` frame for already reset substream {}", - self.id, id + tracing::debug!( + connection=%self.id, + substream=%id, + "Ignoring `Close` frame for already reset substream" ); self.substreams.insert(id, SubstreamState::Reset { buf }); } SubstreamState::SendClosed { buf } => { - debug!( - "{}: Substream {} closed by remote (SendClosed -> Closed).", - self.id, id + tracing::debug!( + connection=%self.id, + substream=%id, + "Substream closed by remote (SendClosed -> Closed)" ); self.substreams.insert(id, SubstreamState::Closed { buf }); // Notify tasks interested in reading, so they may read the EOF. self.notifier_read.wake_read_stream(id); } SubstreamState::Open { buf } => { - debug!( - "{}: Substream {} closed by remote (Open -> RecvClosed)", - self.id, id + tracing::debug!( + connection=%self.id, + substream=%id, + "Substream closed by remote (Open -> RecvClosed)" ); self.substreams .insert(id, SubstreamState::RecvClosed { buf }); @@ -792,10 +831,10 @@ where } } } else { - trace!( - "{}: Ignoring `Close` for unknown substream {}. Possibly dropped earlier.", - self.id, - id + tracing::trace!( + connection=%self.id, + substream=%id, + "Ignoring `Close` for unknown substream, possibly dropped earlier." ); } } @@ -829,7 +868,11 @@ where /// Records a fatal error for the multiplexed I/O stream. fn on_error(&mut self, e: io::Error) -> io::Result { - debug!("{}: Multiplexed connection failed: {:?}", self.id, e); + tracing::debug!( + connection=%self.id, + "Multiplexed connection failed: {:?}", + e + ); self.status = Status::Err(io::Error::new(e.kind(), e.to_string())); self.pending_frames = Default::default(); self.substreams = Default::default(); @@ -872,11 +915,11 @@ where let state = if let Some(state) = self.substreams.get_mut(&id) { state } else { - trace!( - "{}: Dropping data {:?} for unknown substream {}", - self.id, - data, - id + tracing::trace!( + connection=%self.id, + substream=%id, + data=?data, + "Dropping data for unknown substream" ); return Ok(()); }; @@ -884,33 +927,41 @@ where let buf = if let Some(buf) = state.recv_buf_open() { buf } else { - trace!( - "{}: Dropping data {:?} for closed or reset substream {}", - self.id, - data, - id + tracing::trace!( + connection=%self.id, + substream=%id, + data=?data, + "Dropping data for closed or reset substream", ); return Ok(()); }; debug_assert!(buf.len() <= self.config.max_buffer_len); - trace!( - "{}: Buffering {:?} for stream {} (total: {})", - self.id, - data, - id, - buf.len() + 1 + tracing::trace!( + connection=%self.id, + substream=%id, + data=?data, + data_buffer=%buf.len() + 1, + "Buffering data for substream" ); buf.push(data); self.notifier_read.wake_read_stream(id); if buf.len() > self.config.max_buffer_len { - debug!("{}: Frame buffer of stream {} is full.", self.id, id); + tracing::debug!( + connection=%self.id, + substream=%id, + "Frame buffer of substream is full" + ); match self.config.max_buffer_behaviour { MaxBufferBehaviour::ResetStream => { let buf = buf.clone(); self.check_max_pending_frames()?; self.substreams.insert(id, SubstreamState::Reset { buf }); - debug!("{}: Pending reset for stream {}", self.id, id); + tracing::debug!( + connection=%self.id, + substream=%id, + "Pending reset for stream" + ); self.pending_frames .push_front(Frame::Reset { stream_id: id }); } From 2df883f5bfdf09366943dba1897a947ed668c899 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 Sep 2023 13:38:16 +0300 Subject: [PATCH 042/105] yamux, test harness tracing --- Cargo.lock | 5 ++--- muxers/test-harness/Cargo.toml | 2 +- muxers/test-harness/src/lib.rs | 8 ++++---- muxers/yamux/Cargo.toml | 2 +- muxers/yamux/src/lib.rs | 5 ++++- protocols/autonat/Cargo.toml | 1 - 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a9fa97a3e63..bdf93f2a5e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2442,7 +2442,6 @@ dependencies = [ "libp2p-request-response", "libp2p-swarm", "libp2p-swarm-test", - "log", "quick-protobuf", "rand 0.8.5", "tracing", @@ -2803,7 +2802,7 @@ dependencies = [ "futures-timer", "futures_ringbuf", "libp2p-core", - "log", + "tracing", ] [[package]] @@ -3324,8 +3323,8 @@ dependencies = [ "futures", "libp2p-core", "libp2p-muxer-test-harness", - "log", "thiserror", + "tracing", "yamux", ] diff --git a/muxers/test-harness/Cargo.toml b/muxers/test-harness/Cargo.toml index af73de33f8c..70b6aa3b3d6 100644 --- a/muxers/test-harness/Cargo.toml +++ b/muxers/test-harness/Cargo.toml @@ -10,6 +10,6 @@ license = "MIT" [dependencies] libp2p-core = { workspace = true } futures = "0.3.28" -log = "0.4" futures-timer = "3.0.2" futures_ringbuf = "0.4.0" +tracing = { version = "0.1.37", features = ["log"] } diff --git a/muxers/test-harness/src/lib.rs b/muxers/test-harness/src/lib.rs index 544e057c108..d7116243867 100644 --- a/muxers/test-harness/src/lib.rs +++ b/muxers/test-harness/src/lib.rs @@ -148,20 +148,20 @@ async fn run( loop { match futures::future::select(dialer.next(), listener.next()).await { Either::Left((Some(Event::SetupComplete), _)) => { - log::info!("Dialer opened outbound stream"); + tracing::info!("Dialer opened outbound stream"); } Either::Left((Some(Event::ProtocolComplete), _)) => { - log::info!("Dialer completed protocol"); + tracing::info!("Dialer completed protocol"); dialer_complete = true } Either::Left((Some(Event::Timeout), _)) => { panic!("Dialer protocol timed out"); } Either::Right((Some(Event::SetupComplete), _)) => { - log::info!("Listener received inbound stream"); + tracing::info!("Listener received inbound stream"); } Either::Right((Some(Event::ProtocolComplete), _)) => { - log::info!("Listener completed protocol"); + tracing::info!("Listener completed protocol"); listener_complete = true } Either::Right((Some(Event::Timeout), _)) => { diff --git a/muxers/yamux/Cargo.toml b/muxers/yamux/Cargo.toml index 11b94ac9738..4917bb0717d 100644 --- a/muxers/yamux/Cargo.toml +++ b/muxers/yamux/Cargo.toml @@ -15,7 +15,7 @@ futures = "0.3.28" libp2p-core = { workspace = true } thiserror = "1.0" yamux = "0.12" -log = "0.4" +tracing = { version = "0.1.37", features = ["log"] } [dev-dependencies] async-std = { version = "1.7.0", features = ["attributes"] } diff --git a/muxers/yamux/src/lib.rs b/muxers/yamux/src/lib.rs index 12e5dd8c1ff..9a28c243d7e 100644 --- a/muxers/yamux/src/lib.rs +++ b/muxers/yamux/src/lib.rs @@ -121,7 +121,10 @@ where let inbound_stream = ready!(this.poll_inner(cx))?; if this.inbound_stream_buffer.len() >= MAX_BUFFERED_INBOUND_STREAMS { - log::warn!("dropping {} because buffer is full", inbound_stream.0); + tracing::warn!( + stream=%inbound_stream.0, + "dropping stream because buffer is full" + ); drop(inbound_stream); } else { this.inbound_stream_buffer.push_back(inbound_stream); diff --git a/protocols/autonat/Cargo.toml b/protocols/autonat/Cargo.toml index 423cce8eab9..813ad6abfac 100644 --- a/protocols/autonat/Cargo.toml +++ b/protocols/autonat/Cargo.toml @@ -19,7 +19,6 @@ libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } libp2p-request-response = { workspace = true } libp2p-identity = { workspace = true } -log = "0.4" quick-protobuf = "0.8" rand = "0.8" tracing = "0.1.37" From b45c345cfc4af41c0b479b59b5f0aea354d3e13d Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 Sep 2023 13:43:51 +0300 Subject: [PATCH 043/105] autonat tracing, plus remove unwrap --- protocols/autonat/src/behaviour/as_server.rs | 50 ++++++++++++-------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/protocols/autonat/src/behaviour/as_server.rs b/protocols/autonat/src/behaviour/as_server.rs index 09c70a27e93..21ef577bea3 100644 --- a/protocols/autonat/src/behaviour/as_server.rs +++ b/protocols/autonat/src/behaviour/as_server.rs @@ -111,9 +111,9 @@ impl<'a> HandleInnerEvent for AsServer<'a> { let probe_id = self.probe_id.next(); match self.resolve_inbound_request(peer, request) { Ok(addrs) => { - log::debug!( - "Inbound dial request from Peer {} with dial-back addresses {:?}.", - peer, + tracing::debug!( + %peer, + "Inbound dial request from peer with dial-back addresses {:?}", addrs ); @@ -141,10 +141,10 @@ impl<'a> HandleInnerEvent for AsServer<'a> { ]) } Err((status_text, error)) => { - log::debug!( - "Reject inbound dial request from peer {}: {}.", - peer, - status_text + tracing::debug!( + %peer, + status=%status_text, + "Reject inbound dial request from peer" ); let response = DialResponse { @@ -168,10 +168,10 @@ impl<'a> HandleInnerEvent for AsServer<'a> { error, request_id, } => { - log::debug!( - "Inbound Failure {} when on dial-back request from peer {}.", - error, - peer + tracing::debug!( + %peer, + "Inbound Failure {} when on dial-back request from peer", + error ); let probe_id = match self.ongoing_inbound.get(&peer) { @@ -207,10 +207,10 @@ impl<'a> AsServer<'a> { return None; } - log::debug!( - "Dial-back to peer {} succeeded at addr {:?}.", - peer, - address + tracing::debug!( + %peer, + %address, + "Dial-back to peer succeeded at address" ); let (probe_id, _, _, channel) = self.ongoing_inbound.remove(peer).unwrap(); @@ -233,11 +233,21 @@ impl<'a> AsServer<'a> { error: &DialError, ) -> Option { let (probe_id, _, _, channel) = peer.and_then(|p| self.ongoing_inbound.remove(&p))?; - log::debug!( - "Dial-back to peer {} failed with error {:?}.", - peer.unwrap(), - error - ); + + match peer { + Some(p) => + tracing::debug!( + peer=%p, + "Dial-back to peer failed with error {:?}", + error + ), + None => + tracing::debug!( + "Dial-back to non existent peer failed with error {:?}", + error + ), + }; + let response_error = ResponseError::DialError; let response = DialResponse { result: Err(response_error.clone()), From 186cd05ae7520625baf0d13bb31df453d01b81fe Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 Sep 2023 13:46:23 +0300 Subject: [PATCH 044/105] keypair tracing fix --- identity/src/keypair.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/identity/src/keypair.rs b/identity/src/keypair.rs index ac6edec8936..8fc1815836c 100644 --- a/identity/src/keypair.rs +++ b/identity/src/keypair.rs @@ -610,7 +610,7 @@ impl TryFrom for PublicKey { )?), #[cfg(not(feature = "ed25519"))] proto::KeyType::Ed25519 => { - log::debug!("support for ed25519 was disabled at compile-time"); + tracing::debug!("support for ed25519 was disabled at compile-time"); Err(DecodingError::missing_feature("ed25519")) } #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] @@ -623,7 +623,7 @@ impl TryFrom for PublicKey { } #[cfg(any(not(feature = "rsa"), target_arch = "wasm32"))] proto::KeyType::RSA => { - log::debug!("support for RSA was disabled at compile-time"); + tracing::debug!("support for RSA was disabled at compile-time"); Err(DecodingError::missing_feature("rsa")) } #[cfg(feature = "secp256k1")] @@ -633,7 +633,7 @@ impl TryFrom for PublicKey { })?), #[cfg(not(feature = "secp256k1"))] proto::KeyType::Secp256k1 => { - log::debug!("support for secp256k1 was disabled at compile-time"); + tracing::debug!("support for secp256k1 was disabled at compile-time"); Err(DecodingError::missing_feature("secp256k1")) } #[cfg(feature = "ecdsa")] @@ -644,7 +644,7 @@ impl TryFrom for PublicKey { )?), #[cfg(not(feature = "ecdsa"))] proto::KeyType::ECDSA => { - log::debug!("support for ECDSA was disabled at compile-time"); + tracing::debug!("support for ECDSA was disabled at compile-time"); Err(DecodingError::missing_feature("ecdsa")) } } From 7b7e4afbf1e1929b9531dc40b3e4b1bbace2d4ee Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 Sep 2023 14:18:12 +0300 Subject: [PATCH 045/105] upnp and a few other crates tracing --- Cargo.lock | 11 +- protocols/dcutr/Cargo.toml | 1 - protocols/floodsub/Cargo.toml | 1 - protocols/gossipsub/Cargo.toml | 1 - protocols/gossipsub/tests/smoke.rs | 3 +- protocols/identify/Cargo.toml | 1 - protocols/kad/Cargo.toml | 1 - protocols/kad/src/protocol.rs | 2 +- protocols/mdns/Cargo.toml | 1 - protocols/perf/Cargo.toml | 1 - protocols/ping/Cargo.toml | 1 - protocols/relay/src/behaviour/handler.rs | 4 +- protocols/relay/src/priv_client/handler.rs | 25 +++-- protocols/relay/src/protocol/outbound_hop.rs | 7 +- protocols/rendezvous/Cargo.toml | 1 - protocols/upnp/Cargo.toml | 4 +- protocols/upnp/src/behaviour.rs | 107 ++++++++++--------- 17 files changed, 82 insertions(+), 90 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bdf93f2a5e8..a7c51fdae50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2519,7 +2519,6 @@ dependencies = [ "libp2p-swarm-test", "libp2p-tcp", "libp2p-yamux", - "log", "quick-protobuf", "quick-protobuf-codec", "rand 0.8.5", @@ -2571,7 +2570,6 @@ dependencies = [ "libp2p-core", "libp2p-identity", "libp2p-swarm", - "log", "quick-protobuf", "quick-protobuf-codec", "rand 0.8.5", @@ -2604,7 +2602,6 @@ dependencies = [ "libp2p-swarm", "libp2p-swarm-test", "libp2p-yamux", - "log", "prometheus-client", "quick-protobuf", "quick-protobuf-codec", @@ -2633,7 +2630,6 @@ dependencies = [ "libp2p-identity", "libp2p-swarm", "libp2p-swarm-test", - "log", "lru", "quick-protobuf", "quick-protobuf-codec", @@ -2692,7 +2688,6 @@ dependencies = [ "libp2p-swarm", "libp2p-swarm-test", "libp2p-yamux", - "log", "quick-protobuf", "quick-protobuf-codec", "quickcheck-ext", @@ -2724,7 +2719,6 @@ dependencies = [ "libp2p-swarm-test", "libp2p-tcp", "libp2p-yamux", - "log", "rand 0.8.5", "smallvec", "socket2 0.5.4", @@ -2851,7 +2845,6 @@ dependencies = [ "libp2p-tcp", "libp2p-tls", "libp2p-yamux", - "log", "rand 0.8.5", "serde", "serde_json", @@ -2875,7 +2868,6 @@ dependencies = [ "libp2p-identity", "libp2p-swarm", "libp2p-swarm-test", - "log", "quickcheck-ext", "rand 0.8.5", "tracing", @@ -2999,7 +2991,6 @@ dependencies = [ "libp2p-swarm-test", "libp2p-tcp", "libp2p-yamux", - "log", "quick-protobuf", "quick-protobuf-codec", "rand 0.8.5", @@ -3178,8 +3169,8 @@ dependencies = [ "igd-next", "libp2p-core", "libp2p-swarm", - "log", "tokio", + "tracing", "void", ] diff --git a/protocols/dcutr/Cargo.toml b/protocols/dcutr/Cargo.toml index 28c0968e8be..a8c10ef8909 100644 --- a/protocols/dcutr/Cargo.toml +++ b/protocols/dcutr/Cargo.toml @@ -19,7 +19,6 @@ instant = "0.1.12" libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true } -log = "0.4" quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } thiserror = "1.0" diff --git a/protocols/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml index 7c6cf8da8dc..06874983350 100644 --- a/protocols/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -18,7 +18,6 @@ futures = "0.3.28" libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true } -log = "0.4" quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } rand = "0.8" diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 77bfb37d429..50c10aa25e2 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -28,7 +28,6 @@ instant = "0.1.12" libp2p-core = { workspace = true } libp2p-identity = { workspace = true } libp2p-swarm = { workspace = true } -log = "0.4.20" quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } rand = "0.8" diff --git a/protocols/gossipsub/tests/smoke.rs b/protocols/gossipsub/tests/smoke.rs index e4e4c90d768..26db5ccbea5 100644 --- a/protocols/gossipsub/tests/smoke.rs +++ b/protocols/gossipsub/tests/smoke.rs @@ -25,7 +25,6 @@ use libp2p_gossipsub as gossipsub; use libp2p_gossipsub::{MessageAuthenticity, ValidationMode}; use libp2p_swarm::Swarm; use libp2p_swarm_test::SwarmExt as _; -use log::debug; use quickcheck::{QuickCheck, TestResult}; use rand::{seq::SliceRandom, SeedableRng}; use std::{task::Poll, time::Duration}; @@ -136,7 +135,7 @@ fn multi_hop_propagation() { return TestResult::discard(); } - debug!("number nodes: {:?}, seed: {:?}", num_nodes, seed); + tracing::debug!(number_of_nodes=%num_nodes, seed=%seed); async_std::task::block_on(async move { let mut graph = Graph::new_connected(num_nodes as usize, seed).await; diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index ddb132c5367..55aca6f3dca 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -17,7 +17,6 @@ futures-timer = "3.0.2" libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true } -log = "0.4.20" lru = "0.11.1" quick-protobuf-codec = { workspace = true } quick-protobuf = "0.8" diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index 544cf7019b7..7ff0a40e6ec 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -17,7 +17,6 @@ either = "1.9" fnv = "1.0" asynchronous-codec = "0.6" futures = "0.3.28" -log = "0.4" libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } quick-protobuf = "0.8" diff --git a/protocols/kad/src/protocol.rs b/protocols/kad/src/protocol.rs index 24b24789091..a5919f45f5e 100644 --- a/protocols/kad/src/protocol.rs +++ b/protocols/kad/src/protocol.rs @@ -106,7 +106,7 @@ impl TryFrom for KadPeer { match Multiaddr::try_from(addr) { Ok(a) => addrs.push(a), Err(e) => { - log::debug!("Unable to parse multiaddr: {e}"); + tracing::debug!("Unable to parse multiaddr: {e}"); } }; } diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index 9feef85dbef..ca858c6e8c0 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -18,7 +18,6 @@ if-watch = "3.0.1" libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true } -log = "0.4.20" rand = "0.8.3" smallvec = "1.11.0" socket2 = { version = "0.5.4", features = ["all"] } diff --git a/protocols/perf/Cargo.toml b/protocols/perf/Cargo.toml index 6362f7d0a06..8741e2b8c13 100644 --- a/protocols/perf/Cargo.toml +++ b/protocols/perf/Cargo.toml @@ -26,7 +26,6 @@ libp2p-request-response = { workspace = true } libp2p-swarm = { workspace = true, features = ["macros", "tokio"] } libp2p-tcp = { workspace = true, features = ["tokio"] } libp2p-yamux = { workspace = true } -log = "0.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index 80acdc112bb..6f90c7473ed 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -18,7 +18,6 @@ instant = "0.1.12" libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true } -log = "0.4.20" rand = "0.8" void = "1.0" tracing = "0.1.37" diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index 1bd9a7f8ad7..33c8ffea068 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -436,7 +436,7 @@ impl Handler { ) .is_err() { - log::warn!("Dropping inbound stream because we are at capacity") + tracing::warn!("Dropping inbound stream because we are at capacity") } } @@ -454,7 +454,7 @@ impl Handler { .try_push(outbound_stop::connect(stream, stop_command, tx).map(Either::Right)) .is_err() { - log::warn!("Dropping outbound stream because we are at capacity") + tracing::warn!("Dropping outbound stream because we are at capacity") } } diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs index 25488ac3041..78572ff099a 100644 --- a/protocols/relay/src/priv_client/handler.rs +++ b/protocols/relay/src/priv_client/handler.rs @@ -274,11 +274,13 @@ impl Handler { src_peer_id, circuit.deny(proto::Status::NO_RESERVATION), ) { - Err(PushError::BeyondCapacity(_)) => log::warn!( - "Dropping inbound circuit request to be denied from {src_peer_id} due to exceeding limit." + Err(PushError::BeyondCapacity(_)) => tracing::warn!( + peer=%src_peer_id, + "Dropping inbound circuit request to be denied from peer due to exceeding limit" ), - Err(PushError::ReplacedFuture(_)) => log::warn!( - "Dropping existing inbound circuit request to be denied from {src_peer_id} in favor of new one." + Err(PushError::ReplacedFuture(_)) => tracing::warn!( + peer=%src_peer_id, + "Dropping existing inbound circuit request to be denied from peer in favor of new one" ), Ok(()) => {} } @@ -471,7 +473,10 @@ impl ConnectionHandler for Handler { )); } Poll::Ready((src_peer_id, Err(Timeout { .. }))) => { - log::warn!("Dropping inbound circuit request to be denied from {:?} due to exceeding limit.", src_peer_id); + tracing::warn!( + peer=%src_peer_id, + "Dropping inbound circuit request to be denied from peer due to exceeding limit." + ); } Poll::Pending => {} } @@ -526,7 +531,7 @@ impl ConnectionHandler for Handler { .try_push(inbound_stop::handle_open_circuit(stream)) .is_err() { - log::warn!("Dropping inbound stream because we are at capacity") + tracing::warn!("Dropping inbound stream because we are at capacity") } } ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound { @@ -546,7 +551,7 @@ impl ConnectionHandler for Handler { ) .is_err() { - log::warn!("Dropping outbound stream because we are at capacity") + tracing::warn!("Dropping outbound stream because we are at capacity") } } outbound_hop::OutboundStreamInfo::CircuitConnection(cmd) => { @@ -566,7 +571,7 @@ impl ConnectionHandler for Handler { ) .is_err() { - log::warn!("Dropping outbound stream because we are at capacity") + tracing::warn!("Dropping outbound stream because we are at capacity") } } } @@ -663,12 +668,12 @@ impl Reservation { if let Err(e) = to_listener .start_send(pending_msgs.pop_front().expect("Called !is_empty().")) { - debug!("Failed to sent pending message to listener: {:?}", e); + tracing::debug!("Failed to sent pending message to listener: {:?}", e); *self = Reservation::None; } } Poll::Ready(Err(e)) => { - debug!("Channel to listener failed: {:?}", e); + tracing::debug!("Channel to listener failed: {:?}", e); *self = Reservation::None; } Poll::Pending => {} diff --git a/protocols/relay/src/protocol/outbound_hop.rs b/protocols/relay/src/protocol/outbound_hop.rs index adad0e23711..223d01455a2 100644 --- a/protocols/relay/src/protocol/outbound_hop.rs +++ b/protocols/relay/src/protocol/outbound_hop.rs @@ -24,7 +24,6 @@ use asynchronous_codec::{Framed, FramedParts}; use futures::channel::{mpsc, oneshot}; use futures::prelude::*; use futures_timer::Delay; -use log::debug; use thiserror::Error; use void::Void; @@ -265,10 +264,10 @@ pub(crate) async fn handle_connection_message_response( })) { Ok(()) => Ok(Ok(Some(Circuit { limit }))), Err(_) => { - debug!( + tracing::debug!( + peer=%remote_peer_id, "Oneshot to `client::transport::Dial` future dropped. \ - Dropping established relayed connection to {:?}.", - remote_peer_id, + Dropping established relayed connection to peer" ); Ok(Ok(None)) diff --git a/protocols/rendezvous/Cargo.toml b/protocols/rendezvous/Cargo.toml index 88e48ad98b4..1ee7ac616f9 100644 --- a/protocols/rendezvous/Cargo.toml +++ b/protocols/rendezvous/Cargo.toml @@ -21,7 +21,6 @@ libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true } libp2p-request-response = { workspace = true } -log = "0.4" quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } rand = "0.8" diff --git a/protocols/upnp/Cargo.toml b/protocols/upnp/Cargo.toml index ab20496aa4b..14bb840946a 100644 --- a/protocols/upnp/Cargo.toml +++ b/protocols/upnp/Cargo.toml @@ -16,9 +16,9 @@ futures-timer = "3.0.2" igd-next = "0.14.2" libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } -log = "0.4.19" -void = "1.0.2" tokio = { version = "1.29", default-features = false, features = ["rt"], optional = true } +tracing = { version = "0.1.37", features = ["log"] } +void = "1.0.2" [features] tokio = ["igd-next/aio_tokio", "dep:tokio"] diff --git a/protocols/upnp/src/behaviour.rs b/protocols/upnp/src/behaviour.rs index f582e96e1e7..b6790ed772a 100644 --- a/protocols/upnp/src/behaviour.rs +++ b/protocols/upnp/src/behaviour.rs @@ -175,9 +175,9 @@ impl MappingList { mapping: mapping.clone(), duration, }) { - log::debug!( - "could not request port mapping for {} on the gateway: {}", - mapping.multiaddr, + tracing::debug!( + multiaddress=%mapping.multiaddr, + "could not request port mapping for multiaddress on the gateway: {}", err ); } @@ -190,9 +190,9 @@ impl MappingList { mapping: mapping.clone(), duration, }) { - log::debug!( - "could not request port mapping for {} on the gateway: {}", - mapping.multiaddr, + tracing::debug!( + multiaddress=%mapping.multiaddr, + "could not request port mapping for multiaddress on the gateway: {}", err ); } @@ -261,7 +261,7 @@ impl NetworkBehaviour for Behaviour { let (addr, protocol) = match multiaddr_to_socketaddr_protocol(multiaddr.clone()) { Ok(addr_port) => addr_port, Err(()) => { - log::debug!("multiaddress not supported for UPnP {multiaddr}"); + tracing::debug!("multiaddress not supported for UPnP {multiaddr}"); return; } }; @@ -271,7 +271,11 @@ impl NetworkBehaviour for Behaviour { .iter() .find(|(mapping, _state)| mapping.internal_addr.port() == addr.port()) { - log::debug!("port from multiaddress {multiaddr} is already being mapped to another multiaddr: {}", mapping.multiaddr); + tracing::debug!( + multiaddress=%multiaddr, + mapped_multiaddress=%mapping.multiaddr, + "port from multiaddress is already being mapped" + ); return; } @@ -302,9 +306,9 @@ impl NetworkBehaviour for Behaviour { mapping: mapping.clone(), duration, }) { - log::debug!( - "could not request port mapping for {} on the gateway: {}", - mapping.multiaddr, + tracing::debug!( + multiaddress=%mapping.multiaddr, + "could not request port mapping for multiaddress on the gateway: {}", err ); } @@ -312,14 +316,17 @@ impl NetworkBehaviour for Behaviour { self.mappings.insert(mapping, MappingState::Pending); } GatewayState::GatewayNotFound => { - log::debug!( - "network gateway not found, UPnP port mapping of {multiaddr} discarded" + tracing::debug!( + multiaddres=%multiaddr, + "network gateway not found, UPnP port mapping of multiaddres discarded" ); } GatewayState::NonRoutableGateway(addr) => { - log::debug!( - "the network gateway is not exposed to the public network, \ - it's ip is {addr}. UPnP port mapping of {multiaddr} discarded" + tracing::debug!( + multiaddress=%multiaddr, + network_gateway_ip=%addr, + "the network gateway is not exposed to the public network. / + UPnP port mapping of multiaddress discarded" ); } }; @@ -334,9 +341,9 @@ impl NetworkBehaviour for Behaviour { .sender .try_send(GatewayRequest::RemoveMapping(mapping.clone())) { - log::debug!( - "could not request port removal for {} on the gateway: {}", - mapping.multiaddr, + tracing::debug!( + multiaddress=%mapping.multiaddr, + "could not request port removal for multiaddress on the gateway: {}", err ); } @@ -388,9 +395,9 @@ impl NetworkBehaviour for Behaviour { if !is_addr_global(gateway.external_addr) { self.state = GatewayState::NonRoutableGateway(gateway.external_addr); - log::debug!( - "the gateway is not routable, its address is {}", - gateway.external_addr + tracing::debug!( + gateway_address=%gateway.external_addr, + "the gateway is not routable" ); return Poll::Ready(ToSwarm::GenerateEvent( Event::NonRoutableGateway, @@ -399,7 +406,7 @@ impl NetworkBehaviour for Behaviour { self.state = GatewayState::Available(gateway); } Err(err) => { - log::debug!("could not find gateway: {err}"); + tracing::debug!("could not find gateway: {err}"); self.state = GatewayState::GatewayNotFound; return Poll::Ready(ToSwarm::GenerateEvent(Event::GatewayNotFound)); } @@ -427,20 +434,20 @@ impl NetworkBehaviour for Behaviour { self.pending_events.push_back(Event::NewExternalAddr( external_multiaddr.clone(), )); - log::debug!( - "succcessfully mapped UPnP {} for {} protocol", - mapping.internal_addr, - mapping.protocol + tracing::debug!( + address=%mapping.internal_addr, + protocol=%mapping.protocol, + "successfully mapped UPnP for protocol" ); return Poll::Ready(ToSwarm::ExternalAddrConfirmed( external_multiaddr, )); } MappingState::Active(_) => { - log::debug!( - "succcessfully renewed UPnP mapping {} for {} protocol", - mapping.internal_addr, - mapping.protocol + tracing::debug!( + address=%mapping.internal_addr, + protocol=%mapping.protocol, + "successfully renewed UPnP mapping for protocol" ); } _ => unreachable!(), @@ -453,10 +460,10 @@ impl NetworkBehaviour for Behaviour { .expect("mapping should exist") { MappingState::Active(_) => { - log::debug!( - "failed to remap UPnP mapped {} for {} protocol: {err}", - mapping.internal_addr, - mapping.protocol + tracing::debug!( + address=%mapping.internal_addr, + protocol=%mapping.protocol, + "failed to remap UPnP mapped for protocol: {err}" ); let external_multiaddr = mapping.external_addr(gateway.external_addr); @@ -468,10 +475,10 @@ impl NetworkBehaviour for Behaviour { )); } MappingState::Pending => { - log::debug!( - "failed to map upnp mapped {} for {} protocol: {err}", - mapping.internal_addr, - mapping.protocol + tracing::debug!( + address=%mapping.internal_addr, + protocol=%mapping.protocol, + "failed to map UPnP mapped for protocol: {err}" ); } _ => { @@ -480,28 +487,28 @@ impl NetworkBehaviour for Behaviour { } } GatewayEvent::Removed(mapping) => { - log::debug!( - "succcessfully removed UPnP mapping {} for {} protocol", - mapping.internal_addr, - mapping.protocol + tracing::debug!( + address=%mapping.internal_addr, + protocol=%mapping.protocol, + "successfully removed UPnP mapping for protocol" ); self.mappings .remove(&mapping) .expect("mapping should exist"); } GatewayEvent::RemovalFailure(mapping, err) => { - log::debug!( - "could not remove UPnP mapping {} for {} protocol: {err}", - mapping.internal_addr, - mapping.protocol + tracing::debug!( + address=%mapping.internal_addr, + protocol=%mapping.protocol, + "could not remove UPnP mapping for protocol: {err}" ); if let Err(err) = gateway .sender .try_send(GatewayRequest::RemoveMapping(mapping.clone())) { - log::debug!( - "could not request port removal for {} on the gateway: {}", - mapping.multiaddr, + tracing::debug!( + multiaddress=%mapping.multiaddr, + "could not request port removal for multiaddress on the gateway: {}", err ); } From d50fed5a00de522ef2f821ceb0fd37e82116c226 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 Sep 2023 14:34:23 +0300 Subject: [PATCH 046/105] swarm tracing --- Cargo.lock | 1 - swarm/Cargo.toml | 9 ++-- swarm/src/behaviour/external_addresses.rs | 8 +++- swarm/src/connection.rs | 8 ++-- swarm/src/connection/pool.rs | 8 ++-- swarm/src/handler/multi.rs | 8 ++-- swarm/src/handler/one_shot.rs | 2 +- swarm/src/lib.rs | 58 ++++++++++++++--------- 8 files changed, 58 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a7c51fdae50..45d3b2c23f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3067,7 +3067,6 @@ dependencies = [ "libp2p-swarm-derive", "libp2p-swarm-test", "libp2p-yamux", - "log", "multistream-select", "once_cell", "quickcheck-ext", diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 5561ae9c765..1ea9b7defe5 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -15,19 +15,18 @@ either = "1.9.0" fnv = "1.0" futures = "0.3.28" futures-timer = "3.0.2" +getrandom = { version = "0.2.9", features = ["js"], optional = true } # Explicit dependency to be used in `wasm-bindgen` feature instant = "0.1.12" libp2p-core = { workspace = true } libp2p-identity = { workspace = true } libp2p-swarm-derive = { workspace = true, optional = true } -log = "0.4" +multistream-select = { workspace = true } +once_cell = "1.18.0" rand = "0.8" smallvec = "1.11.0" +tracing = "0.1.37" void = "1" wasm-bindgen-futures = { version = "0.4.37", optional = true } -getrandom = { version = "0.2.9", features = ["js"], optional = true } # Explicit dependency to be used in `wasm-bindgen` feature -once_cell = "1.18.0" -multistream-select = { workspace = true } -tracing = "0.1.37" [target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies] async-std = { version = "1.6.2", optional = true } diff --git a/swarm/src/behaviour/external_addresses.rs b/swarm/src/behaviour/external_addresses.rs index 307f0f938dd..3b60f499650 100644 --- a/swarm/src/behaviour/external_addresses.rs +++ b/swarm/src/behaviour/external_addresses.rs @@ -37,7 +37,7 @@ impl ExternalAddresses { self.addresses.remove(pos); self.push_front(addr); - log::debug!("Refreshed external address {addr}"); + tracing::debug!(address=%addr, "Refreshed external address"); return false; // No changes to our external addresses. } @@ -47,7 +47,11 @@ impl ExternalAddresses { if self.addresses.len() > MAX_LOCAL_EXTERNAL_ADDRS { let expired = self.addresses.pop().expect("list to be not empty"); - log::debug!("Removing previously confirmed external address {expired} because we reached the limit of {MAX_LOCAL_EXTERNAL_ADDRS} addresses"); + tracing::debug!( + external_address=%expired, + address_limit=%MAX_LOCAL_EXTERNAL_ADDRS, + "Removing previously confirmed external address because we reached the address limit" + ); } return true; diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index c4c24e636fd..d7acf9a5a89 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -337,15 +337,15 @@ where continue; } Poll::Ready(Some((_, Err(StreamUpgradeError::Io(e))))) => { - log::debug!("failed to upgrade inbound stream: {e}"); + tracing::debug!("failed to upgrade inbound stream: {e}"); continue; } Poll::Ready(Some((_, Err(StreamUpgradeError::NegotiationFailed)))) => { - log::debug!("no protocol could be agreed upon for inbound stream"); + tracing::debug!("no protocol could be agreed upon for inbound stream"); continue; } Poll::Ready(Some((_, Err(StreamUpgradeError::Timeout)))) => { - log::debug!("inbound stream upgrade timed out"); + tracing::debug!("inbound stream upgrade timed out"); continue; } } @@ -522,7 +522,7 @@ impl StreamUpgrade { { let effective_version = match version_override { Some(version_override) if version_override != upgrade::Version::default() => { - log::debug!( + tracing::debug!( "Substream upgrade protocol override: {:?} -> {:?}", upgrade::Version::default(), version_override diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index b97fb1498d1..8b185b65f01 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -693,10 +693,10 @@ where if let Err(error) = check_peer_id() { self.executor.spawn(poll_fn(move |cx| { if let Err(e) = ready!(muxer.poll_close_unpin(cx)) { - log::debug!( - "Failed to close connection {:?} to peer {}: {:?}", - id, - obtained_peer_id, + tracing::debug!( + peer=%obtained_peer_id, + connection=%id, + "Failed to close connection to peer: {:?}", e ); } diff --git a/swarm/src/handler/multi.rs b/swarm/src/handler/multi.rs index ced94f1213c..de3a0834648 100644 --- a/swarm/src/handler/multi.rs +++ b/swarm/src/handler/multi.rs @@ -162,7 +162,7 @@ where }, )); } else { - log::error!("FullyNegotiatedOutbound: no handler for key") + tracing::error!("FullyNegotiatedOutbound: no handler for key") } } ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound { @@ -179,7 +179,7 @@ where )); } } else { - log::error!("FullyNegotiatedInbound: no handler for key") + tracing::error!("FullyNegotiatedInbound: no handler for key") } } ConnectionEvent::AddressChange(AddressChange { new_address }) => { @@ -199,7 +199,7 @@ where error, })); } else { - log::error!("DialUpgradeError: no handler for protocol") + tracing::error!("DialUpgradeError: no handler for protocol") } } ConnectionEvent::ListenUpgradeError(listen_upgrade_error) => { @@ -226,7 +226,7 @@ where if let Some(h) = self.handlers.get_mut(&key) { h.on_behaviour_event(event) } else { - log::error!("on_behaviour_event: no handler for key") + tracing::error!("on_behaviour_event: no handler for key") } } diff --git a/swarm/src/handler/one_shot.rs b/swarm/src/handler/one_shot.rs index 439d3f47ee3..6f514b3faa4 100644 --- a/swarm/src/handler/one_shot.rs +++ b/swarm/src/handler/one_shot.rs @@ -215,7 +215,7 @@ where } ConnectionEvent::DialUpgradeError(DialUpgradeError { error, .. }) => { if self.pending_error.is_none() { - log::debug!("DialUpgradeError: {error}"); + tracing::debug!("DialUpgradeError: {error}"); self.keep_alive = KeepAlive::No; } } diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index e9f08d4c14c..a3c272888f8 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -458,7 +458,11 @@ where let num_addresses = addresses.len(); if num_addresses > 0 { - log::debug!("discarding {num_addresses} addresses from `NetworkBehaviour` because `DialOpts::extend_addresses_through_behaviour is `false` for connection {connection_id:?}") + tracing::debug!( + connection=%connection_id, + discarded_addresses_count=%num_addresses, + "discarding addresses from `NetworkBehaviour` because `DialOpts::extend_addresses_through_behaviour is `false` for connection" + ) } } } @@ -742,11 +746,11 @@ where self.pool .spawn_connection(id, peer_id, &endpoint, connection, handler); - log::debug!( - "Connection established: {:?} {:?}; Total (peer): {}.", - peer_id, - endpoint, - num_established, + tracing::debug!( + peer=%peer_id, + ?endpoint, + total_peers=%num_established, + "Connection established" ); let failed_addresses = concurrent_dial_errors .as_ref() @@ -792,9 +796,9 @@ where })); if let Some(peer) = peer { - log::debug!("Connection attempt to {:?} failed with {:?}.", peer, error,); + tracing::debug!(%peer, "Connection attempt to peer failed with {:?}.", error,); } else { - log::debug!("Connection attempt to unknown peer failed with {:?}", error); + tracing::debug!("Connection attempt to unknown peer failed with {:?}", error); } return Some(SwarmEvent::OutgoingConnectionError { @@ -811,7 +815,7 @@ where } => { let error = error.into(); - log::debug!("Incoming connection failed: {:?}", error); + tracing::debug!("Incoming connection failed: {:?}", error); self.behaviour .on_swarm_event(FromSwarm::ListenFailure(ListenFailure { local_addr: &local_addr, @@ -835,17 +839,17 @@ where .. } => { if let Some(error) = error.as_ref() { - log::debug!( - "Connection closed with error {:?}: {:?}; Total (peer): {}.", + tracing::debug!( + total_peers=%remaining_established_connection_ids.len(), + "Connection closed with error {:?}: {:?}", error, connected, - remaining_established_connection_ids.len() ); } else { - log::debug!( - "Connection closed: {:?}; Total (peer): {}.", - connected, - remaining_established_connection_ids.len() + tracing::debug!( + total_peers=%remaining_established_connection_ids.len(), + "Connection closed: {:?}", + connected ); } let peer_id = connected.peer_id; @@ -953,7 +957,11 @@ where listener_id, listen_addr, } => { - log::debug!("Listener {:?}; New address: {:?}", listener_id, listen_addr); + tracing::debug!( + listener=?listener_id, + address=%listen_addr, + "New listener address" + ); let addrs = self.listened_addrs.entry(listener_id).or_default(); if !addrs.contains(&listen_addr) { addrs.push(listen_addr.clone()) @@ -972,10 +980,10 @@ where listener_id, listen_addr, } => { - log::debug!( - "Listener {:?}; Expired address {:?}.", - listener_id, - listen_addr + tracing::debug!( + listener=?listener_id, + address=%listen_addr, + "Expired listener address" ); if let Some(addrs) = self.listened_addrs.get_mut(&listener_id) { addrs.retain(|a| a != &listen_addr); @@ -994,7 +1002,11 @@ where listener_id, reason, } => { - log::debug!("Listener {:?}; Closed by {:?}.", listener_id, reason); + tracing::debug!( + listener=?listener_id, + "Listener closed by {:?}.", + reason + ); let addrs = self.listened_addrs.remove(&listener_id).unwrap_or_default(); for addr in addrs.iter() { self.behaviour.on_swarm_event(FromSwarm::ExpiredListenAddr( @@ -1532,7 +1544,7 @@ where /// Builds a `Swarm` with the current configuration. pub fn build(self) -> Swarm { - log::info!("Local peer id: {}", self.local_peer_id); + tracing::info!(local_peer_id=%self.local_peer_id); Swarm { local_peer_id: self.local_peer_id, transport: self.transport, From 9e6072009997d4829179b3985cfe607b61a8079e Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 Sep 2023 14:41:24 +0300 Subject: [PATCH 047/105] swarm test tracing --- Cargo.lock | 2 +- swarm-test/Cargo.toml | 2 +- swarm-test/src/lib.rs | 32 ++++++++++++++++++++------------ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 45d3b2c23f4..684b7d6db44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3103,8 +3103,8 @@ dependencies = [ "libp2p-swarm", "libp2p-tcp", "libp2p-yamux", - "log", "rand 0.8.5", + "tracing", ] [[package]] diff --git a/swarm-test/Cargo.toml b/swarm-test/Cargo.toml index 67753b1c522..332c5e124bc 100644 --- a/swarm-test/Cargo.toml +++ b/swarm-test/Cargo.toml @@ -20,6 +20,6 @@ libp2p-swarm = { workspace = true } libp2p-tcp = { workspace = true, features = ["async-io"] } libp2p-yamux = { workspace = true } futures = "0.3.28" -log = "0.4.20" rand = "0.8.5" +tracing = "0.1.37" futures-timer = "3.0.2" diff --git a/swarm-test/src/lib.rs b/swarm-test/src/lib.rs index 819db33ba88..c679ad81904 100644 --- a/swarm-test/src/lib.rs +++ b/swarm-test/src/lib.rs @@ -249,10 +249,16 @@ where listener_done = true; } Either::Left((other, _)) => { - log::debug!("Ignoring event from dialer {:?}", other); + tracing::debug!( + dialer=?other, + "Ignoring event from dialer" + ); } Either::Right((other, _)) => { - log::debug!("Ignoring event from listener {:?}", other); + tracing::debug!( + listener=?other, + "Ignoring event from listener" + ); } } @@ -270,7 +276,10 @@ where endpoint, peer_id, .. } => (endpoint.get_remote_address() == &addr).then_some(peer_id), other => { - log::debug!("Ignoring event from dialer {:?}", other); + tracing::debug!( + dialer=?other, + "Ignoring event from dialer" + ); None } }) @@ -301,9 +310,9 @@ where listener_id, } => (listener_id == memory_addr_listener_id).then_some(address), other => { - log::debug!( - "Ignoring {:?} while waiting for listening to succeed", - other + tracing::debug!( + ignored=?other, + "Ignoring while waiting for listening to succeed" ); None } @@ -324,9 +333,9 @@ where listener_id, } => (listener_id == tcp_addr_listener_id).then_some(address), other => { - log::debug!( - "Ignoring {:?} while waiting for listening to succeed", - other + tracing::debug!( + ignored=?other, + "Ignoring while waiting for listening to succeed" ); None } @@ -350,8 +359,7 @@ where { Either::Left(((), _)) => panic!("Swarm did not emit an event within 10s"), Either::Right((event, _)) => { - log::trace!("Swarm produced: {:?}", event); - + tracing::trace!(swarm_event=?event); event } } @@ -367,7 +375,7 @@ where async fn loop_on_next(mut self) { while let Some(event) = self.next().await { - log::trace!("Swarm produced: {:?}", event); + tracing::trace!(swarm_event=?event); } } } From 317e0dc1c12ce994b8660ff1bd800679c3ffab9c Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 Sep 2023 14:42:17 +0300 Subject: [PATCH 048/105] cargo fmt --- examples/browser-webrtc/src/main.rs | 4 +++- muxers/mplex/src/io.rs | 6 +++--- protocols/autonat/src/behaviour/as_server.rs | 22 +++++++++----------- protocols/gossipsub/src/peer_score.rs | 2 +- protocols/relay/src/priv_client/handler.rs | 8 +++---- swarm/src/lib.rs | 2 +- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/examples/browser-webrtc/src/main.rs b/examples/browser-webrtc/src/main.rs index 9339b186877..339ac87e79f 100644 --- a/examples/browser-webrtc/src/main.rs +++ b/examples/browser-webrtc/src/main.rs @@ -54,7 +54,9 @@ async fn main() -> anyhow::Result<()> { .iter() .any(|e| e == Protocol::Ip4(Ipv4Addr::LOCALHOST)) { - tracing::debug!("Ignoring localhost address to make sure the example works in Firefox"); + tracing::debug!( + "Ignoring localhost address to make sure the example works in Firefox" + ); continue; } diff --git a/muxers/mplex/src/io.rs b/muxers/mplex/src/io.rs index 67d3bd0b5aa..0ba67f0acdc 100644 --- a/muxers/mplex/src/io.rs +++ b/muxers/mplex/src/io.rs @@ -640,8 +640,8 @@ where if let Some(id) = &stream_id { if self.pending_flush_open.contains(id) { tracing::trace!( - connection=%self.id, - substream=%id, + connection=%self.id, + substream=%id, "Executing pending flush for substream" ); ready!(self.poll_flush(cx))?; @@ -870,7 +870,7 @@ where fn on_error(&mut self, e: io::Error) -> io::Result { tracing::debug!( connection=%self.id, - "Multiplexed connection failed: {:?}", + "Multiplexed connection failed: {:?}", e ); self.status = Status::Err(io::Error::new(e.kind(), e.to_string())); diff --git a/protocols/autonat/src/behaviour/as_server.rs b/protocols/autonat/src/behaviour/as_server.rs index 21ef577bea3..8ba070d4669 100644 --- a/protocols/autonat/src/behaviour/as_server.rs +++ b/protocols/autonat/src/behaviour/as_server.rs @@ -233,19 +233,17 @@ impl<'a> AsServer<'a> { error: &DialError, ) -> Option { let (probe_id, _, _, channel) = peer.and_then(|p| self.ongoing_inbound.remove(&p))?; - + match peer { - Some(p) => - tracing::debug!( - peer=%p, - "Dial-back to peer failed with error {:?}", - error - ), - None => - tracing::debug!( - "Dial-back to non existent peer failed with error {:?}", - error - ), + Some(p) => tracing::debug!( + peer=%p, + "Dial-back to peer failed with error {:?}", + error + ), + None => tracing::debug!( + "Dial-back to non existent peer failed with error {:?}", + error + ), }; let response_error = ResponseError::DialError; diff --git a/protocols/gossipsub/src/peer_score.rs b/protocols/gossipsub/src/peer_score.rs index 928dbffa102..bb808d7a094 100644 --- a/protocols/gossipsub/src/peer_score.rs +++ b/protocols/gossipsub/src/peer_score.rs @@ -598,7 +598,7 @@ impl PeerScore { tracing::warn!( peer=%from, status=?record.status, - "Unexpected delivery trace: Message from peer was first seen {}s ago", + "Unexpected delivery trace: Message from peer was first seen {}s ago", record.first_seen.elapsed().as_secs(), ); return; diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs index 78572ff099a..5ad43a980ad 100644 --- a/protocols/relay/src/priv_client/handler.rs +++ b/protocols/relay/src/priv_client/handler.rs @@ -270,10 +270,10 @@ impl Handler { fn insert_to_deny_futs(&mut self, circuit: inbound_stop::Circuit) { let src_peer_id = circuit.src_peer_id(); - match self.circuit_deny_futs.try_push( - src_peer_id, - circuit.deny(proto::Status::NO_RESERVATION), - ) { + match self + .circuit_deny_futs + .try_push(src_peer_id, circuit.deny(proto::Status::NO_RESERVATION)) + { Err(PushError::BeyondCapacity(_)) => tracing::warn!( peer=%src_peer_id, "Dropping inbound circuit request to be denied from peer due to exceeding limit" diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index a3c272888f8..f736d96fe4a 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -1004,7 +1004,7 @@ where } => { tracing::debug!( listener=?listener_id, - "Listener closed by {:?}.", + "Listener closed by {:?}.", reason ); let addrs = self.listened_addrs.remove(&listener_id).unwrap_or_default(); From 76c8f06ffcf258848b606064b4ab3a35358d84a1 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 Sep 2023 16:48:07 +0300 Subject: [PATCH 049/105] tracing cleanup --- core/src/transport/global_only.rs | 10 +++++----- protocols/gossipsub/src/behaviour.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/transport/global_only.rs b/core/src/transport/global_only.rs index d6a262e3fa3..c87affd2ecc 100644 --- a/core/src/transport/global_only.rs +++ b/core/src/transport/global_only.rs @@ -291,20 +291,20 @@ impl crate::Transport for Transport { match addr.iter().next() { Some(Protocol::Ip4(a)) => { if !ipv4_global::is_global(a) { - tracing::debug!(ip=?a, "Not dialing non global IP address."); + tracing::debug!(ip=?a, "Not dialing non global IP address"); return Err(TransportError::MultiaddrNotSupported(addr)); } self.inner.dial(addr) } Some(Protocol::Ip6(a)) => { if !ipv6_global::is_global(a) { - tracing::debug!(ip=?a, "Not dialing non global IP address."); + tracing::debug!(ip=?a, "Not dialing non global IP address"); return Err(TransportError::MultiaddrNotSupported(addr)); } self.inner.dial(addr) } _ => { - tracing::debug!(address=%addr, "Not dialing unsupported Multiaddress."); + tracing::debug!(address=%addr, "Not dialing unsupported Multiaddress"); Err(TransportError::MultiaddrNotSupported(addr)) } } @@ -317,14 +317,14 @@ impl crate::Transport for Transport { match addr.iter().next() { Some(Protocol::Ip4(a)) => { if !ipv4_global::is_global(a) { - tracing::debug!(ip=?a, "Not dialing non global IP address."); + tracing::debug!(ip=?a, "Not dialing non global IP address"); return Err(TransportError::MultiaddrNotSupported(addr)); } self.inner.dial_as_listener(addr) } Some(Protocol::Ip6(a)) => { if !ipv6_global::is_global(a) { - tracing::debug!(ip=?a, "Not dialing non global IP address."); + tracing::debug!(ip=?a, "Not dialing non global IP address"); return Err(TransportError::MultiaddrNotSupported(addr)); } self.inner.dial_as_listener(addr) diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 7c47d329a2f..25defa1fc6f 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -526,7 +526,7 @@ where /// Returns [`Ok(true)`] if the subscription worked. Returns [`Ok(false)`] if we were already /// subscribed. pub fn subscribe(&mut self, topic: &Topic) -> Result { - tracing::debug!(%topic, "Subscribing to topic:"); + tracing::debug!(%topic, "Subscribing to topic"); let topic_hash = topic.hash(); if !self.subscription_filter.can_subscribe(&topic_hash) { return Err(SubscriptionError::NotAllowed); From 886297b602d4bedca553b6987ec7fcbd3c02f9d5 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 Sep 2023 16:55:53 +0300 Subject: [PATCH 050/105] remove '.' from tracing messages --- examples/dcutr/src/main.rs | 4 ++-- misc/multistream-select/src/negotiated.rs | 2 +- misc/server/src/main.rs | 4 ++-- protocols/autonat/src/behaviour/as_client.rs | 6 +++--- protocols/autonat/src/protocol.rs | 6 +++--- protocols/gossipsub/src/behaviour.rs | 6 +++--- protocols/kad/src/behaviour.rs | 6 +++--- protocols/relay/src/behaviour/handler.rs | 4 ++-- transports/webrtc/src/tokio/transport.rs | 2 +- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/dcutr/src/main.rs b/examples/dcutr/src/main.rs index 230f760db1b..b7a7df9be8d 100644 --- a/examples/dcutr/src/main.rs +++ b/examples/dcutr/src/main.rs @@ -216,7 +216,7 @@ fn main() -> Result<(), Box> { SwarmEvent::ConnectionEstablished { .. } => {} SwarmEvent::Behaviour(Event::Ping(_)) => {} SwarmEvent::Behaviour(Event::Identify(identify::Event::Sent { .. })) => { - tracing::info!("Told relay its public address."); + tracing::info!("Told relay its public address"); told_relay_observed_addr = true; } SwarmEvent::Behaviour(Event::Identify(identify::Event::Received { @@ -263,7 +263,7 @@ fn main() -> Result<(), Box> { relay::client::Event::ReservationReqAccepted { .. }, )) => { assert!(opts.mode == Mode::Listen); - tracing::info!("Relay accepted our reservation request."); + tracing::info!("Relay accepted our reservation request"); } SwarmEvent::Behaviour(Event::Relay(event)) => { tracing::info!(?event) diff --git a/misc/multistream-select/src/negotiated.rs b/misc/multistream-select/src/negotiated.rs index 8eda11c0f9a..a24014a4f5f 100644 --- a/misc/multistream-select/src/negotiated.rs +++ b/misc/multistream-select/src/negotiated.rs @@ -317,7 +317,7 @@ where StateProj::Expecting { io, .. } => { let close_poll = io.poll_close(cx); if let Poll::Ready(Ok(())) = close_poll { - tracing::debug!("Stream closed. Confirmation from remote for optimstic protocol negotiation still pending.") + tracing::debug!("Stream closed. Confirmation from remote for optimstic protocol negotiation still pending") } close_poll } diff --git a/misc/server/src/main.rs b/misc/server/src/main.rs index 2d9ec032f19..b8de28d6a88 100644 --- a/misc/server/src/main.rs +++ b/misc/server/src/main.rs @@ -107,7 +107,7 @@ async fn main() -> Result<(), Box> { let mut swarm = SwarmBuilder::with_tokio_executor(transport, behaviour, local_peer_id).build(); if config.addresses.swarm.is_empty() { - tracing::warn!("No listen addresses configured."); + tracing::warn!("No listen addresses configured"); } for address in &config.addresses.swarm { match swarm.listen_on(address.clone()) { @@ -120,7 +120,7 @@ async fn main() -> Result<(), Box> { } if config.addresses.append_announce.is_empty() { - tracing::warn!("No external addresses configured."); + tracing::warn!("No external addresses configured"); } for address in &config.addresses.append_announce { swarm.add_external_address(address.clone()) diff --git a/protocols/autonat/src/behaviour/as_client.rs b/protocols/autonat/src/behaviour/as_client.rs index c5ad7fe09db..034b1593f1f 100644 --- a/protocols/autonat/src/behaviour/as_client.rs +++ b/protocols/autonat/src/behaviour/as_client.rs @@ -276,13 +276,13 @@ impl<'a> AsClient<'a> { ) -> Result { let _ = self.last_probe.insert(Instant::now()); if addresses.is_empty() { - tracing::debug!("Outbound dial-back request aborted: No dial-back addresses."); + tracing::debug!("Outbound dial-back request aborted: No dial-back addresses"); return Err(OutboundProbeError::NoAddresses); } let server = match self.random_server() { Some(s) => s, None => { - tracing::debug!("Outbound dial-back request aborted: No qualified server."); + tracing::debug!("Outbound dial-back request aborted: No qualified server"); return Err(OutboundProbeError::NoServer); } }; @@ -294,7 +294,7 @@ impl<'a> AsClient<'a> { }, ); self.throttled_servers.push((server, Instant::now())); - tracing::debug!(peer=%server, "Send dial-back request to peer."); + tracing::debug!(peer=%server, "Send dial-back request to peer"); self.ongoing_outbound.insert(request_id, probe_id); Ok(server) } diff --git a/protocols/autonat/src/protocol.rs b/protocols/autonat/src/protocol.rs index 46defef19cd..0851e0ccdad 100644 --- a/protocols/autonat/src/protocol.rs +++ b/protocols/autonat/src/protocol.rs @@ -115,7 +115,7 @@ impl DialRequest { { (peer_id, addrs) } else { - tracing::debug!("Received malformed dial message."); + tracing::debug!("Received malformed dial message"); return Err(io::Error::new( io::ErrorKind::InvalidData, "invalid dial message", @@ -200,7 +200,7 @@ impl TryFrom for ResponseError { proto::ResponseStatus::E_BAD_REQUEST => Ok(ResponseError::BadRequest), proto::ResponseStatus::E_INTERNAL_ERROR => Ok(ResponseError::InternalError), proto::ResponseStatus::OK => { - tracing::debug!("Received response with status code OK but expected error."); + tracing::debug!("Received response with status code OK but expected error"); Err(io::Error::new( io::ErrorKind::InvalidData, "invalid response error type", @@ -249,7 +249,7 @@ impl DialResponse { result: Err(ResponseError::try_from(status)?), }, _ => { - tracing::debug!("Received malformed response message."); + tracing::debug!("Received malformed response message"); return Err(io::Error::new( io::ErrorKind::InvalidData, "invalid dial response message", diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 25defa1fc6f..db436277a0f 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -533,7 +533,7 @@ where } if self.mesh.get(&topic_hash).is_some() { - tracing::debug!(%topic, "Topic is already in the mesh."); + tracing::debug!(%topic, "Topic is already in the mesh"); return Ok(false); } @@ -1825,7 +1825,7 @@ where } if !self.duplicate_cache.insert(msg_id.clone()) { - tracing::debug!(message=%msg_id, "Message already received, ignoring."); + tracing::debug!(message=%msg_id, "Message already received, ignoring"); if let Some((peer_score, ..)) = &mut self.peer_score { peer_score.duplicated_message(propagation_source, &msg_id, &message.topic); } @@ -2568,7 +2568,7 @@ where }, ); - tracing::debug!("Gossiping IHAVE to {} peers.", to_msg_peers.len()); + tracing::debug!("Gossiping IHAVE to {} peers", to_msg_peers.len()); for peer in to_msg_peers { let mut peer_message_ids = message_ids.clone(); diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index 80a163653d5..d62c9cd391f 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -1092,7 +1092,7 @@ where let local_id = self.kbuckets.local_key().preimage(); let others_iter = peers.filter(|p| &p.node_id != local_id); if let Some(query) = self.queries.get_mut(query_id) { - tracing::trace!(peer=%source, query=?query_id, "Request to peer in query succeeded."); + tracing::trace!(peer=%source, query=?query_id, "Request to peer in query succeeded"); for peer in others_iter.clone() { tracing::trace!( ?peer, @@ -1327,7 +1327,7 @@ where /// Handles a finished (i.e. successful) query. fn query_finished(&mut self, q: Query) -> Option { let query_id = q.id(); - tracing::trace!(query=?query_id, "Query finished."); + tracing::trace!(query=?query_id, "Query finished"); let result = q.into_result(); match result.inner.info { QueryInfo::Bootstrap { @@ -1565,7 +1565,7 @@ where /// Handles a query that timed out. fn query_timeout(&mut self, query: Query) -> Option { let query_id = query.id(); - tracing::trace!(query=?query_id, "Query timed out."); + tracing::trace!(query=?query_id, "Query timed out"); let result = query.into_result(); match result.inner.info { QueryInfo::Bootstrap { diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index 33c8ffea068..ce254cf1ed7 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -537,7 +537,7 @@ impl ConnectionHandler for Handler { )) .is_some() { - tracing::warn!("Dropping existing deny/accept future in favor of new one.") + tracing::warn!("Dropping existing deny/accept future in favor of new one") } } In::DenyReservationReq { @@ -551,7 +551,7 @@ impl ConnectionHandler for Handler { )) .is_some() { - tracing::warn!("Dropping existing deny/accept future in favor of new one.") + tracing::warn!("Dropping existing deny/accept future in favor of new one") } } In::NegotiateOutboundConnect { diff --git a/transports/webrtc/src/tokio/transport.rs b/transports/webrtc/src/tokio/transport.rs index 4b3f15d5978..29a5e3901ac 100644 --- a/transports/webrtc/src/tokio/transport.rs +++ b/transports/webrtc/src/tokio/transport.rs @@ -238,7 +238,7 @@ impl ListenStream { /// terminate the stream. fn close(&mut self, reason: Result<(), Error>) { match self.report_closed { - Some(_) => log::debug!("Listener was already closed."), + Some(_) => log::debug!("Listener was already closed"), None => { // Report the listener event as closed. let _ = self From 913ec2898f452f7119e8d4443403194b8fae4b22 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 Sep 2023 17:02:34 +0300 Subject: [PATCH 051/105] tracing dns crate, plus alphabatize dependancies --- Cargo.lock | 4 ++-- transports/dns/Cargo.toml | 8 ++++---- transports/dns/src/lib.rs | 22 +++++++++++----------- transports/noise/Cargo.toml | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 684b7d6db44..c43ed2af299 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2552,10 +2552,10 @@ dependencies = [ "futures", "libp2p-core", "libp2p-identity", - "log", "parking_lot", "smallvec", "tokio", + "tracing", "trust-dns-resolver", ] @@ -2810,7 +2810,6 @@ dependencies = [ "futures_ringbuf", "libp2p-core", "libp2p-identity", - "log", "multiaddr", "multihash", "once_cell", @@ -2821,6 +2820,7 @@ dependencies = [ "snow", "static_assertions", "thiserror", + "tracing", "x25519-dalek 1.1.1", "zeroize", ] diff --git a/transports/dns/Cargo.toml b/transports/dns/Cargo.toml index 77c8e57e3ff..2b041df9a62 100644 --- a/transports/dns/Cargo.toml +++ b/transports/dns/Cargo.toml @@ -11,15 +11,15 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] +async-std-resolver = { version = "0.23", optional = true } async-trait = "0.1.72" +futures = "0.3.28" libp2p-core = { workspace = true } libp2p-identity = { workspace = true } -log = "0.4.20" -futures = "0.3.28" -async-std-resolver = { version = "0.23", optional = true } parking_lot = "0.12.0" -trust-dns-resolver = { version = "0.23", default-features = false, features = ["system-config"] } smallvec = "1.11.0" +tracing = { version = "0.1.37", features = ["log"] } +trust-dns-resolver = { version = "0.23", default-features = false, features = ["system-config"] } [dev-dependencies] env_logger = "0.10" diff --git a/transports/dns/src/lib.rs b/transports/dns/src/lib.rs index 61d1f4fed91..ab0c98859f6 100644 --- a/transports/dns/src/lib.rs +++ b/transports/dns/src/lib.rs @@ -278,7 +278,7 @@ where ) }) { if dns_lookups == MAX_DNS_LOOKUPS { - log::debug!("Too many DNS lookups. Dropping unresolved {}.", addr); + tracing::debug!(address=%addr, "Too many DNS lookups, dropping unresolved address"); last_err = Some(DnsErr::TooManyLookups); // There may still be fully resolved addresses in `unresolved`, // so keep going until `unresolved` is empty. @@ -295,13 +295,13 @@ where last_err = Some(e); } Ok(Resolved::One(ip)) => { - log::trace!("Resolved {} -> {}", name, ip); + tracing::trace!(protocol=%name, resolved=%ip); let addr = addr.replace(i, |_| Some(ip)).expect("`i` is a valid index"); unresolved.push(addr); } Ok(Resolved::Many(ips)) => { for ip in ips { - log::trace!("Resolved {} -> {}", name, ip); + tracing::trace!(protocol=%name, resolved=%ip); let addr = addr.replace(i, |_| Some(ip)).expect("`i` is a valid index"); unresolved.push(addr); @@ -315,14 +315,14 @@ where if a.ends_with(&suffix) { if n < MAX_TXT_RECORDS { n += 1; - log::trace!("Resolved {} -> {}", name, a); + tracing::trace!(protocol=%name, resolved=%a); let addr = prefix.iter().chain(a.iter()).collect::(); unresolved.push(addr); } else { - log::debug!( - "Too many TXT records. Dropping resolved {}.", - a + tracing::debug!( + resolved=%a, + "Too many TXT records, dropping resolved" ); } } @@ -331,7 +331,7 @@ where } } else { // We have a fully resolved address, so try to dial it. - log::debug!("Dialing {}", addr); + tracing::debug!(address=%addr, "Dialing address"); let transport = inner.clone(); let dial = match role_override { @@ -355,12 +355,12 @@ where match result { Ok(out) => return Ok(out), Err(err) => { - log::debug!("Dial error: {:?}.", err); + tracing::debug!("Dial error: {:?}.", err); if unresolved.is_empty() { return Err(err); } if dial_attempts == MAX_DIAL_ATTEMPTS { - log::debug!( + tracing::debug!( "Aborting dialing after {} attempts.", MAX_DIAL_ATTEMPTS ); @@ -538,7 +538,7 @@ fn resolve<'a, E: 'a + Send, R: Resolver>( match parse_dnsaddr_txt(chars) { Err(e) => { // Skip over seemingly invalid entries. - log::debug!("Invalid TXT record: {:?}", e); + tracing::debug!("Invalid TXT record: {:?}", e); } Ok(a) => { addrs.push(a); diff --git a/transports/noise/Cargo.toml b/transports/noise/Cargo.toml index cb0a3be2f2a..2c05f16ecf5 100644 --- a/transports/noise/Cargo.toml +++ b/transports/noise/Cargo.toml @@ -14,7 +14,6 @@ curve25519-dalek = "4.1.0" futures = "0.3.28" libp2p-core = { workspace = true } libp2p-identity = { workspace = true, features = ["ed25519"] } -log = "0.4" multiaddr = { workspace = true } multihash = { workspace = true } once_cell = "1.18.0" @@ -23,6 +22,7 @@ rand = "0.8.3" sha2 = "0.10.7" static_assertions = "1" thiserror = "1.0.48" +tracing = { version = "0.1.37", features = ["log"] } x25519-dalek = "1.1.0" zeroize = "1" From a227415a5f02d94b678c38b4752a3dd335c89915 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 Sep 2023 17:12:17 +0300 Subject: [PATCH 052/105] noise crate tracing --- transports/noise/src/io.rs | 11 ++++----- transports/noise/src/io/framed.rs | 41 +++++++++++++++---------------- transports/noise/tests/smoke.rs | 3 +-- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/transports/noise/src/io.rs b/transports/noise/src/io.rs index ee184695696..9d4c5b999e6 100644 --- a/transports/noise/src/io.rs +++ b/transports/noise/src/io.rs @@ -26,7 +26,6 @@ use bytes::Bytes; use framed::{NoiseFramed, MAX_FRAME_LEN}; use futures::prelude::*; use futures::ready; -use log::trace; use std::{ cmp::min, fmt, io, @@ -75,10 +74,10 @@ impl AsyncRead for Output { if len > 0 { let n = min(len - off, buf.len()); buf[..n].copy_from_slice(&self.recv_buffer[off..off + n]); - trace!("read: copied {}/{} bytes", off + n, len); + tracing::trace!(copied_bytes=%(off + n), total_bytes=%len, "read: copied"); self.recv_offset += n; if len == self.recv_offset { - trace!("read: frame consumed"); + tracing::trace!("read: frame consumed"); // Drop the existing view so `NoiseFramed` can reuse // the buffer when polling for the next frame below. self.recv_buffer = Bytes::new(); @@ -111,7 +110,7 @@ impl AsyncWrite for Output { // The MAX_FRAME_LEN is the maximum buffer size before a frame must be sent. if this.send_offset == MAX_FRAME_LEN { - trace!("write: sending {} bytes", MAX_FRAME_LEN); + tracing::trace!(bytes=%MAX_FRAME_LEN, "write: sending"); ready!(io.as_mut().poll_ready(cx))?; io.as_mut().start_send(frame_buf)?; this.send_offset = 0; @@ -123,7 +122,7 @@ impl AsyncWrite for Output { let n = min(MAX_FRAME_LEN - off, buf.len()); this.send_buffer[off..off + n].copy_from_slice(&buf[..n]); this.send_offset += n; - trace!("write: buffered {} bytes", this.send_offset); + tracing::trace!(bytes=%this.send_offset, "write: buffered"); Poll::Ready(Ok(n)) } @@ -136,7 +135,7 @@ impl AsyncWrite for Output { // Check if there is still one more frame to send. if this.send_offset > 0 { ready!(io.as_mut().poll_ready(cx))?; - trace!("flush: sending {} bytes", this.send_offset); + tracing::trace!(bytes= %this.send_offset, "flush: sending"); io.as_mut().start_send(frame_buf)?; this.send_offset = 0; } diff --git a/transports/noise/src/io/framed.rs b/transports/noise/src/io/framed.rs index d7fa79fc815..4dd5a367f1f 100644 --- a/transports/noise/src/io/framed.rs +++ b/transports/noise/src/io/framed.rs @@ -26,7 +26,6 @@ use crate::{protocol::PublicKey, Error}; use bytes::{Bytes, BytesMut}; use futures::prelude::*; use futures::ready; -use log::{debug, trace}; use std::{ fmt, io, pin::Pin, @@ -176,7 +175,7 @@ where fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { let this = Pin::into_inner(self); loop { - trace!("read state: {:?}", this.read_state); + tracing::trace!(read_state=?this.read_state); match this.read_state { ReadState::Ready => { this.read_state = ReadState::ReadLen { @@ -188,7 +187,7 @@ where let n = match read_frame_len(&mut this.io, cx, &mut buf, &mut off) { Poll::Ready(Ok(Some(n))) => n, Poll::Ready(Ok(None)) => { - trace!("read: eof"); + tracing::trace!("read: eof"); this.read_state = ReadState::Eof(Ok(())); return Poll::Ready(None); } @@ -198,9 +197,9 @@ where return Poll::Pending; } }; - trace!("read: frame len = {}", n); + tracing::trace!(frame_length=%n, "read"); if n == 0 { - trace!("read: empty frame"); + tracing::trace!("read: empty frame"); this.read_state = ReadState::Ready; continue; } @@ -219,22 +218,22 @@ where Err(e) => return Poll::Ready(Some(Err(e))), } }; - trace!("read: {}/{} bytes", *off + n, len); + tracing::trace!(read_bytes=%(*off + n), total_bytes=%len, "read"); if n == 0 { - trace!("read: eof"); + tracing::trace!("read: eof"); this.read_state = ReadState::Eof(Err(())); return Poll::Ready(Some(Err(io::ErrorKind::UnexpectedEof.into()))); } *off += n; if len == *off { - trace!("read: decrypting {} bytes", len); + tracing::trace!(bytes=%len, "read: decrypting bytes"); this.decrypt_buffer.resize(len, 0); if let Ok(n) = this .session .read_message(&this.read_buffer, &mut this.decrypt_buffer) { this.decrypt_buffer.truncate(n); - trace!("read: payload len = {} bytes", n); + tracing::trace!(payload_bytes=%n, "read"); this.read_state = ReadState::Ready; // Return an immutable view into the current buffer. // If the view is dropped before the next frame is @@ -243,18 +242,18 @@ where let view = this.decrypt_buffer.split().freeze(); return Poll::Ready(Some(Ok(view))); } else { - debug!("read: decryption error"); + tracing::debug!("read: decryption error"); this.read_state = ReadState::DecErr; return Poll::Ready(Some(Err(io::ErrorKind::InvalidData.into()))); } } } ReadState::Eof(Ok(())) => { - trace!("read: eof"); + tracing::trace!("read: eof"); return Poll::Ready(None); } ReadState::Eof(Err(())) => { - trace!("read: eof (unexpected)"); + tracing::trace!("read: eof (unexpected)"); return Poll::Ready(Some(Err(io::ErrorKind::UnexpectedEof.into()))); } ReadState::DecErr => { @@ -275,17 +274,17 @@ where fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { let this = Pin::into_inner(self); loop { - trace!("write state {:?}", this.write_state); + tracing::trace!(write_state=?this.write_state); match this.write_state { WriteState::Ready => { return Poll::Ready(Ok(())); } WriteState::WriteLen { len, buf, mut off } => { - trace!("write: frame len ({}, {:?}, {}/2)", len, buf, off); + tracing::trace!("write: frame len ({}, {:?}, {}/2)", len, buf, off); match write_frame_len(&mut this.io, cx, &buf, &mut off) { Poll::Ready(Ok(true)) => (), Poll::Ready(Ok(false)) => { - trace!("write: eof"); + tracing::trace!("write: eof"); this.write_state = WriteState::Eof; return Poll::Ready(Err(io::ErrorKind::WriteZero.into())); } @@ -307,19 +306,19 @@ where } }; if n == 0 { - trace!("write: eof"); + tracing::trace!("write: eof"); this.write_state = WriteState::Eof; return Poll::Ready(Err(io::ErrorKind::WriteZero.into())); } *off += n; - trace!("write: {}/{} bytes written", *off, len); + tracing::trace!(writen_bytes=%*off, total_bytes=%len, "write"); if len == *off { - trace!("write: finished with {} bytes", len); + tracing::trace!(total_bytes=%len, "write: finished"); this.write_state = WriteState::Ready; } } WriteState::Eof => { - trace!("write: eof"); + tracing::trace!("write: eof"); return Poll::Ready(Err(io::ErrorKind::WriteZero.into())); } WriteState::EncErr => return Poll::Ready(Err(io::ErrorKind::InvalidData.into())), @@ -339,7 +338,7 @@ where .write_message(frame, &mut this.write_buffer[..]) { Ok(n) => { - trace!("write: cipher text len = {} bytes", n); + tracing::trace!(cipher_text_bytes=%n, "write: cipher text"); this.write_buffer.truncate(n); this.write_state = WriteState::WriteLen { len: n, @@ -349,7 +348,7 @@ where Ok(()) } Err(e) => { - log::error!("encryption error: {:?}", e); + tracing::error!("encryption error: {:?}", e); this.write_state = WriteState::EncErr; Err(io::ErrorKind::InvalidData.into()) } diff --git a/transports/noise/tests/smoke.rs b/transports/noise/tests/smoke.rs index 6d1723ec7d6..f7f0a32ebcf 100644 --- a/transports/noise/tests/smoke.rs +++ b/transports/noise/tests/smoke.rs @@ -23,7 +23,6 @@ use libp2p_core::transport::{MemoryTransport, Transport}; use libp2p_core::{upgrade, InboundUpgrade, OutboundUpgrade}; use libp2p_identity as identity; use libp2p_noise as noise; -use log::info; use quickcheck::*; use std::{convert::TryInto, io}; @@ -85,7 +84,7 @@ fn xx() { Err(e) => panic!("error reading len: {e}"), } }; - info!("server: reading message ({} bytes)", len); + tracing::info!(bytes=%len, "server: reading message"); let mut server_buffer = vec![0; len.try_into().unwrap()]; server_session .read_exact(&mut server_buffer) From 8f75357a2f89860db30f3f00dae67277be36fe3b Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 Sep 2023 17:14:34 +0300 Subject: [PATCH 053/105] plaintext crate tracing --- Cargo.lock | 2 +- transports/plaintext/Cargo.toml | 2 +- transports/plaintext/src/handshake.rs | 15 +++++++-------- transports/plaintext/src/lib.rs | 5 ++--- transports/plaintext/tests/smoke.rs | 7 +++---- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c43ed2af299..180c46161ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2885,10 +2885,10 @@ dependencies = [ "futures_ringbuf", "libp2p-core", "libp2p-identity", - "log", "quick-protobuf", "quickcheck-ext", "rand 0.8.5", + "tracing", "unsigned-varint", ] diff --git a/transports/plaintext/Cargo.toml b/transports/plaintext/Cargo.toml index 1f15004d3f4..fff1831392c 100644 --- a/transports/plaintext/Cargo.toml +++ b/transports/plaintext/Cargo.toml @@ -16,8 +16,8 @@ bytes = "1" futures = "0.3.28" libp2p-core = { workspace = true } libp2p-identity = { workspace = true } -log = "0.4.20" quick-protobuf = "0.8" +tracing = { version = "0.1.37", features = ["log"] } unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } [dev-dependencies] diff --git a/transports/plaintext/src/handshake.rs b/transports/plaintext/src/handshake.rs index 46dd6119d92..14a281eb826 100644 --- a/transports/plaintext/src/handshake.rs +++ b/transports/plaintext/src/handshake.rs @@ -26,7 +26,6 @@ use asynchronous_codec::{Framed, FramedParts}; use bytes::{Bytes, BytesMut}; use futures::prelude::*; use libp2p_identity::{PeerId, PublicKey}; -use log::{debug, trace}; use quick_protobuf::{BytesReader, MessageRead, MessageWrite, Writer}; use std::io::{Error as IoError, ErrorKind as IoErrorKind}; use unsigned_varint::codec::UviBytes; @@ -104,27 +103,27 @@ where // The handshake messages all start with a variable-length integer indicating the size. let mut framed_socket = Framed::new(socket, UviBytes::default()); - trace!("starting handshake"); + tracing::trace!("starting handshake"); let context = HandshakeContext::new(config); - trace!("sending exchange to remote"); + tracing::trace!("sending exchange to remote"); framed_socket .send(BytesMut::from(&context.state.exchange_bytes[..])) .await?; - trace!("receiving the remote's exchange"); + tracing::trace!("receiving the remote's exchange"); let context = match framed_socket.next().await { Some(p) => context.with_remote(p?)?, None => { - debug!("unexpected eof while waiting for remote's exchange"); + tracing::debug!("unexpected eof while waiting for remote's exchange"); let err = IoError::new(IoErrorKind::BrokenPipe, "unexpected eof"); return Err(err.into()); } }; - trace!( - "received exchange from remote; pubkey = {:?}", - context.state.public_key + tracing::trace!( + public_key=?context.state.public_key, + "received exchange from remote" ); let FramedParts { diff --git a/transports/plaintext/src/lib.rs b/transports/plaintext/src/lib.rs index 76e70a025b7..3f65d5c84fe 100644 --- a/transports/plaintext/src/lib.rs +++ b/transports/plaintext/src/lib.rs @@ -31,7 +31,6 @@ use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; use libp2p_identity as identity; use libp2p_identity::PeerId; use libp2p_identity::PublicKey; -use log::debug; use std::{ io, iter, pin::Pin, @@ -93,9 +92,9 @@ impl PlainText2Config { where T: AsyncRead + AsyncWrite + Send + Unpin + 'static, { - debug!("Starting plaintext handshake."); + tracing::debug!("Starting plaintext handshake."); let (socket, remote, read_buffer) = handshake::handshake(socket, self).await?; - debug!("Finished plaintext handshake."); + tracing::debug!("Finished plaintext handshake."); Ok(( remote.peer_id, diff --git a/transports/plaintext/tests/smoke.rs b/transports/plaintext/tests/smoke.rs index 7147ed56686..fb51b1991c9 100644 --- a/transports/plaintext/tests/smoke.rs +++ b/transports/plaintext/tests/smoke.rs @@ -22,7 +22,6 @@ use futures::io::{AsyncReadExt, AsyncWriteExt}; use libp2p_core::InboundUpgrade; use libp2p_identity as identity; use libp2p_plaintext::PlainText2Config; -use log::debug; use quickcheck::QuickCheck; #[test] @@ -62,18 +61,18 @@ fn variable_msg_length() { assert_eq!(received_client_id, client_id.public().to_peer_id()); let client_fut = async { - debug!("Client: writing message."); + tracing::debug!("Client: writing message."); client_channel .write_all(&msg_to_send) .await .expect("no error"); - debug!("Client: flushing channel."); + tracing::debug!("Client: flushing channel."); client_channel.flush().await.expect("no error"); }; let server_fut = async { let mut server_buffer = vec![0; msg_to_receive.len()]; - debug!("Server: reading message."); + tracing::debug!("Server: reading message."); server_channel .read_exact(&mut server_buffer) .await From 27c49ee30f6bc975a5894053d26e056afadd1f52 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 Sep 2023 17:17:23 +0300 Subject: [PATCH 054/105] pnet crate tracing --- Cargo.lock | 2 +- transports/pnet/Cargo.toml | 2 +- transports/pnet/src/crypt_writer.rs | 3 +-- transports/pnet/src/lib.rs | 9 ++++----- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 180c46161ed..40c172159f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2904,13 +2904,13 @@ dependencies = [ "libp2p-tcp", "libp2p-websocket", "libp2p-yamux", - "log", "pin-project", "quickcheck-ext", "rand 0.8.5", "salsa20", "sha3", "tokio", + "tracing", ] [[package]] diff --git a/transports/pnet/Cargo.toml b/transports/pnet/Cargo.toml index 5861bf2d987..efc9749a702 100644 --- a/transports/pnet/Cargo.toml +++ b/transports/pnet/Cargo.toml @@ -12,9 +12,9 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.28" -log = "0.4.20" salsa20 = "0.10" sha3 = "0.10" +tracing = { version = "0.1.37", features = ["log"] } rand = "0.8" pin-project = "1.1.3" diff --git a/transports/pnet/src/crypt_writer.rs b/transports/pnet/src/crypt_writer.rs index c5993548239..06f932fbe71 100644 --- a/transports/pnet/src/crypt_writer.rs +++ b/transports/pnet/src/crypt_writer.rs @@ -23,7 +23,6 @@ use futures::{ ready, task::{Context, Poll}, }; -use log::trace; use pin_project::pin_project; use salsa20::{cipher::StreamCipher, XSalsa20}; use std::{fmt, pin::Pin}; @@ -120,7 +119,7 @@ impl AsyncWrite for CryptWriter { let res = Pin::new(&mut *this.buf).poll_write(cx, buf); if let Poll::Ready(Ok(count)) = res { this.cipher.apply_keystream(&mut this.buf[0..count]); - trace!("encrypted {} bytes", count); + tracing::trace!(bytes=%count, "encrypted bytes"); } else { debug_assert!(false); }; diff --git a/transports/pnet/src/lib.rs b/transports/pnet/src/lib.rs index 15f42556c62..eee6f7dd430 100644 --- a/transports/pnet/src/lib.rs +++ b/transports/pnet/src/lib.rs @@ -29,7 +29,6 @@ mod crypt_writer; use crypt_writer::CryptWriter; use futures::prelude::*; -use log::trace; use pin_project::pin_project; use rand::RngCore; use salsa20::{ @@ -209,7 +208,7 @@ impl PnetConfig { where TSocket: AsyncRead + AsyncWrite + Send + Unpin + 'static, { - trace!("exchanging nonces"); + tracing::trace!("exchanging nonces"); let mut local_nonce = [0u8; NONCE_SIZE]; let mut remote_nonce = [0u8; NONCE_SIZE]; rand::thread_rng().fill_bytes(&mut local_nonce); @@ -222,7 +221,7 @@ impl PnetConfig { .read_exact(&mut remote_nonce) .await .map_err(PnetError::HandshakeError)?; - trace!("setting up ciphers"); + tracing::trace!("setting up ciphers"); let write_cipher = XSalsa20::new(&self.key.0.into(), &local_nonce.into()); let read_cipher = XSalsa20::new(&self.key.0.into(), &remote_nonce.into()); Ok(PnetOutput::new(socket, write_cipher, read_cipher)) @@ -256,9 +255,9 @@ impl AsyncRead for PnetOutput { let this = self.project(); let result = this.inner.get_pin_mut().poll_read(cx, buf); if let Poll::Ready(Ok(size)) = &result { - trace!("read {} bytes", size); + tracing::trace!(bytes=%size, "read bytes"); this.read_cipher.apply_keystream(&mut buf[..*size]); - trace!("decrypted {} bytes", size); + tracing::trace!(bytes=%size, "decrypted bytes"); } result } From 73b9c58d675f2a5f2e6417317d58f5c9afba9c48 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 Sep 2023 17:21:32 +0300 Subject: [PATCH 055/105] added quic tracing --- Cargo.lock | 2 +- transports/quic/Cargo.toml | 2 +- transports/quic/src/transport.rs | 17 ++++++++++++++--- transports/quic/tests/smoke.rs | 11 +++++++++-- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 40c172159f3..5887e92894f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2930,7 +2930,6 @@ dependencies = [ "libp2p-tcp", "libp2p-tls", "libp2p-yamux", - "log", "parking_lot", "quickcheck", "quinn", @@ -2939,6 +2938,7 @@ dependencies = [ "socket2 0.5.4", "thiserror", "tokio", + "tracing", ] [[package]] diff --git a/transports/quic/Cargo.toml b/transports/quic/Cargo.toml index 671032a845d..7178a062ac7 100644 --- a/transports/quic/Cargo.toml +++ b/transports/quic/Cargo.toml @@ -17,13 +17,13 @@ if-watch = "3.0.1" libp2p-core = { workspace = true } libp2p-tls = { workspace = true } libp2p-identity = { workspace = true } -log = "0.4" parking_lot = "0.12.0" quinn = { version = "0.10.2", default-features = false, features = ["tls-rustls", "futures-io"] } rand = "0.8.5" rustls = { version = "0.21.7", default-features = false } thiserror = "1.0.48" tokio = { version = "1.32.0", default-features = false, features = ["net", "rt", "time"], optional = true } +tracing = { version = "0.1.37", features = ["log"] } socket2 = "0.5.4" [features] diff --git a/transports/quic/src/transport.rs b/transports/quic/src/transport.rs index 16ffbc5a163..4826ff6d68e 100644 --- a/transports/quic/src/transport.rs +++ b/transports/quic/src/transport.rs @@ -346,7 +346,12 @@ impl Transport for GenTransport

{ .expect("hole punch connection sender is never dropped before receiver") .await?; if inbound_peer_id != peer_id { - log::warn!("expected inbound connection from {socket_addr} to resolve to {peer_id} but got {inbound_peer_id}"); + tracing::warn!( + peer=%peer_id, + inbound_peer=%inbound_peer_id, + socket_address=%socket_addr, + "expected inbound connection from socket_address to resolve to peer but got inbound peer" + ); } Ok((inbound_peer_id, connection)) } @@ -525,7 +530,10 @@ impl Listener

{ if let Some(listen_addr) = ip_to_listenaddr(&endpoint_addr, inet.addr(), self.version) { - log::debug!("New listen address: {listen_addr}"); + tracing::debug!( + address=%listen_addr, + "New listen address" + ); self.listening_addresses.insert(inet.addr()); return Poll::Ready(TransportEvent::NewAddress { listener_id: self.listener_id, @@ -537,7 +545,10 @@ impl Listener

{ if let Some(listen_addr) = ip_to_listenaddr(&endpoint_addr, inet.addr(), self.version) { - log::debug!("Expired listen address: {listen_addr}"); + tracing::debug!( + address=%listen_addr, + "Expired listen address" + ); self.listening_addresses.remove(&inet.addr()); return Poll::Ready(TransportEvent::AddressExpired { listener_id: self.listener_id, diff --git a/transports/quic/tests/smoke.rs b/transports/quic/tests/smoke.rs index 5581ceb744c..8915cc93bc8 100644 --- a/transports/quic/tests/smoke.rs +++ b/transports/quic/tests/smoke.rs @@ -580,7 +580,11 @@ fn prop( let (listeners_tx, mut listeners_rx) = mpsc::channel(number_listeners); - log::info!("Creating {number_streams} streams on {number_listeners} connections"); + tracing::info!( + stream_count=%number_streams, + connection_count=%number_listeners, + "Creating streams on connections" + ); // Spawn the listener nodes. for _ in 0..number_listeners { @@ -721,7 +725,10 @@ async fn open_outbound_streams( }); } - log::info!("Created {number_streams} streams"); + tracing::info!( + stream_count=%number_streams, + "Created streams + "); while future::poll_fn(|cx| connection.poll_unpin(cx)) .await From fc4bc3622886f2540ed582986ab624b5d0d88cd5 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 Sep 2023 17:26:06 +0300 Subject: [PATCH 056/105] tcp crate tracing --- Cargo.lock | 2 +- transports/quic/tests/smoke.rs | 4 ++-- transports/tcp/Cargo.toml | 2 +- transports/tcp/src/lib.rs | 20 ++++++++++++-------- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5887e92894f..a79a6c8ece7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3120,9 +3120,9 @@ dependencies = [ "libc", "libp2p-core", "libp2p-identity", - "log", "socket2 0.5.4", "tokio", + "tracing", ] [[package]] diff --git a/transports/quic/tests/smoke.rs b/transports/quic/tests/smoke.rs index 8915cc93bc8..3f47271ae6b 100644 --- a/transports/quic/tests/smoke.rs +++ b/transports/quic/tests/smoke.rs @@ -727,8 +727,8 @@ async fn open_outbound_streams( tracing::info!( stream_count=%number_streams, - "Created streams - "); + "Created streams" + ); while future::poll_fn(|cx| connection.poll_unpin(cx)) .await diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index 1714debada5..2a79a5aaaf0 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -18,9 +18,9 @@ if-watch = "3.0.1" libc = "0.2.148" libp2p-core = { workspace = true } libp2p-identity = { workspace = true } -log = "0.4.20" socket2 = { version = "0.5.4", features = ["all"] } tokio = { version = "1.32.0", default-features = false, features = ["net"], optional = true } +tracing = { version = "0.1.37", features = ["log"] } [features] tokio = ["dep:tokio", "if-watch/tokio"] diff --git a/transports/tcp/src/lib.rs b/transports/tcp/src/lib.rs index 5efdf16fff5..bbe052b531c 100644 --- a/transports/tcp/src/lib.rs +++ b/transports/tcp/src/lib.rs @@ -98,7 +98,7 @@ impl PortReuse { /// Has no effect if port reuse is disabled. fn register(&mut self, ip: IpAddr, port: Port) { if let PortReuse::Enabled { listen_addrs } = self { - log::trace!("Registering for port reuse: {}:{}", ip, port); + tracing::trace!(%ip, %port, "Registering for port reuse"); listen_addrs .write() .expect("`register()` and `unregister()` never panic while holding the lock") @@ -111,7 +111,7 @@ impl PortReuse { /// Has no effect if port reuse is disabled. fn unregister(&mut self, ip: IpAddr, port: Port) { if let PortReuse::Enabled { listen_addrs } = self { - log::trace!("Unregistering for port reuse: {}:{}", ip, port); + tracing::trace!(%ip, %port, "Unregistering for port reuse"); listen_addrs .write() .expect("`register()` and `unregister()` never panic while holding the lock") @@ -446,7 +446,7 @@ where } else { return Err(TransportError::MultiaddrNotSupported(addr)); }; - log::debug!("listening on {}", socket_addr); + tracing::debug!(address=%socket_addr, "listening on address"); let listener = self .do_listen(id, socket_addr) .map_err(TransportError::Other)?; @@ -472,14 +472,14 @@ where } else { return Err(TransportError::MultiaddrNotSupported(addr)); }; - log::debug!("dialing {}", socket_addr); + tracing::debug!(address=%socket_addr, "dialing address"); let socket = self .create_socket(socket_addr) .map_err(TransportError::Other)?; if let Some(addr) = self.port_reuse.local_dial_addr(&socket_addr.ip()) { - log::trace!("Binding dial socket to listen socket {}", addr); + tracing::trace!(address=%addr, "Binding dial socket to listen socket address"); socket.bind(&addr.into()).map_err(TransportError::Other)?; } @@ -677,7 +677,7 @@ where let ip = inet.addr(); if self.listen_addr.is_ipv4() == ip.is_ipv4() { let ma = ip_to_multiaddr(ip, my_listen_addr_port); - log::debug!("New listen address: {}", ma); + tracing::debug!(address=%ma, "New listen address"); self.port_reuse.register(ip, my_listen_addr_port); return Poll::Ready(TransportEvent::NewAddress { listener_id: self.listener_id, @@ -689,7 +689,7 @@ where let ip = inet.addr(); if self.listen_addr.is_ipv4() == ip.is_ipv4() { let ma = ip_to_multiaddr(ip, my_listen_addr_port); - log::debug!("Expired listen address: {}", ma); + tracing::debug!(address=%ma, "Expired listen address"); self.port_reuse.unregister(ip, my_listen_addr_port); return Poll::Ready(TransportEvent::AddressExpired { listener_id: self.listener_id, @@ -762,7 +762,11 @@ where let local_addr = ip_to_multiaddr(local_addr.ip(), local_addr.port()); let remote_addr = ip_to_multiaddr(remote_addr.ip(), remote_addr.port()); - log::debug!("Incoming connection from {} at {}", remote_addr, local_addr); + tracing::debug!( + remote_address=%remote_addr, + local_address=%local_addr, + "Incoming connection from remote at local" + ); return Poll::Ready(Some(TransportEvent::Incoming { listener_id: self.listener_id, From 49db0050ec8faa4f16b11279d2fa3403325420a8 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 Sep 2023 17:51:11 +0300 Subject: [PATCH 057/105] webrtc crate tracing --- Cargo.lock | 4 +-- protocols/relay/src/priv_client/handler.rs | 1 - transports/uds/Cargo.toml | 2 +- transports/uds/src/lib.rs | 7 ++--- transports/webrtc/Cargo.toml | 2 +- transports/webrtc/src/tokio/connection.rs | 32 +++++++++---------- transports/webrtc/src/tokio/sdp.rs | 2 +- transports/webrtc/src/tokio/transport.rs | 2 +- transports/webrtc/src/tokio/udp_mux.rs | 36 +++++++++++----------- transports/webrtc/src/tokio/upgrade.rs | 16 +++++----- transports/webrtc/tests/smoke.rs | 8 +++-- 11 files changed, 57 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a79a6c8ece7..508fed88d80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3154,9 +3154,9 @@ dependencies = [ "async-std", "futures", "libp2p-core", - "log", "tempfile", "tokio", + "tracing", ] [[package]] @@ -3200,7 +3200,6 @@ dependencies = [ "libp2p-identity", "libp2p-noise", "libp2p-webrtc-utils", - "log", "multihash", "quickcheck", "rand 0.8.5", @@ -3211,6 +3210,7 @@ dependencies = [ "tinytemplate", "tokio", "tokio-util", + "tracing", "webrtc", ] diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs index 5ad43a980ad..5619921bafa 100644 --- a/protocols/relay/src/priv_client/handler.rs +++ b/protocols/relay/src/priv_client/handler.rs @@ -41,7 +41,6 @@ use libp2p_swarm::{ ConnectionHandler, ConnectionHandlerEvent, KeepAlive, StreamProtocol, StreamUpgradeError, SubstreamProtocol, }; -use log::debug; use std::collections::VecDeque; use std::fmt; use std::task::{Context, Poll}; diff --git a/transports/uds/Cargo.toml b/transports/uds/Cargo.toml index d776ac3366d..aa5a72aab14 100644 --- a/transports/uds/Cargo.toml +++ b/transports/uds/Cargo.toml @@ -13,9 +13,9 @@ categories = ["network-programming", "asynchronous"] [dependencies] async-std = { version = "1.6.2", optional = true } libp2p-core = { workspace = true } -log = "0.4.20" futures = "0.3.28" tokio = { version = "1.32", default-features = false, features = ["net"], optional = true } +tracing = { version = "0.1.37", features = ["log"] } [dev-dependencies] tempfile = "3.8" diff --git a/transports/uds/src/lib.rs b/transports/uds/src/lib.rs index 3cd71552d18..075cbadb80a 100644 --- a/transports/uds/src/lib.rs +++ b/transports/uds/src/lib.rs @@ -49,7 +49,6 @@ use libp2p_core::{ transport::{TransportError, TransportEvent}, Transport, }; -use log::debug; use std::collections::VecDeque; use std::pin::Pin; use std::task::{Context, Poll}; @@ -104,7 +103,7 @@ macro_rules! codegen { stream::once({ let addr = addr.clone(); async move { - debug!("Now listening on {}", addr); + tracing::debug!(address=%addr, "Now listening on address"); Ok(TransportEvent::NewAddress { listener_id: id, listen_addr: addr, @@ -118,7 +117,7 @@ macro_rules! codegen { async move { let event = match listener.accept().await { Ok((stream, _)) => { - debug!("incoming connection on {}", addr); + tracing::debug!(address=%addr, "incoming connection on address"); TransportEvent::Incoming { upgrade: future::ok(stream), local_addr: addr.clone(), @@ -163,7 +162,7 @@ macro_rules! codegen { fn dial(&mut self, addr: Multiaddr) -> Result> { // TODO: Should we dial at all? if let Ok(path) = multiaddr_to_path(&addr) { - debug!("Dialing {}", addr); + tracing::debug!(address=%addr, "Dialing address"); Ok(async move { <$unix_stream>::connect(&path).await }.boxed()) } else { Err(TransportError::MultiaddrNotSupported(addr)) diff --git a/transports/webrtc/Cargo.toml b/transports/webrtc/Cargo.toml index 7cd16f2ceb2..62373345d5f 100644 --- a/transports/webrtc/Cargo.toml +++ b/transports/webrtc/Cargo.toml @@ -21,7 +21,6 @@ libp2p-core = { workspace = true } libp2p-noise = { workspace = true } libp2p-identity = { workspace = true } libp2p-webrtc-utils = { workspace = true } -log = "0.4" multihash = { workspace = true } rand = "0.8" rcgen = "0.11.1" @@ -31,6 +30,7 @@ thiserror = "1" tinytemplate = "1.2" tokio = { version = "1.32", features = ["net"], optional = true} tokio-util = { version = "0.7", features = ["compat"], optional = true } +tracing = { version = "0.1.37", features = ["log"] } webrtc = { version = "0.9.0", optional = true } [features] diff --git a/transports/webrtc/src/tokio/connection.rs b/transports/webrtc/src/tokio/connection.rs index 29983d720b5..3bcc4c3193e 100644 --- a/transports/webrtc/src/tokio/connection.rs +++ b/transports/webrtc/src/tokio/connection.rs @@ -101,7 +101,7 @@ impl Connection { tx: Arc>>>, ) { rtc_conn.on_data_channel(Box::new(move |data_channel: Arc| { - log::debug!("Incoming data channel {}", data_channel.id()); + tracing::debug!(channel=%data_channel.id(), "Incoming data channel"); let tx = tx.clone(); @@ -109,7 +109,7 @@ impl Connection { data_channel.on_open({ let data_channel = data_channel.clone(); Box::new(move || { - log::debug!("Data channel {} open", data_channel.id()); + tracing::debug!(channel=%data_channel.id(), "Data channel open"); Box::pin(async move { let data_channel = data_channel.clone(); @@ -118,7 +118,7 @@ impl Connection { Ok(detached) => { let mut tx = tx.lock().await; if let Err(e) = tx.try_send(detached.clone()) { - log::error!("Can't send data channel {}: {}", id, e); + tracing::error!(channel=%id, "Can't send data channel: {}", e); // We're not accepting data channels fast enough => // close this channel. // @@ -126,16 +126,16 @@ impl Connection { // during the negotiation process, but it's not // possible with the current API. if let Err(e) = detached.close().await { - log::error!( - "Failed to close data channel {}: {}", - id, + tracing::error!( + channel=%id, + "Failed to close data channel: {}", e ); } } } Err(e) => { - log::error!("Can't detach data channel {}: {}", id, e); + tracing::error!(channel=%id, "Can't detach data channel: {}", e); } }; }) @@ -156,7 +156,7 @@ impl StreamMuxer for Connection { ) -> Poll> { match ready!(self.incoming_data_channels_rx.poll_next_unpin(cx)) { Some(detached) => { - log::trace!("Incoming stream {}", detached.stream_identifier()); + tracing::trace!(stream=%detached.stream_identifier(), "Incoming stream"); let (stream, drop_listener) = Stream::new(detached); self.drop_listeners.push(drop_listener); @@ -185,7 +185,7 @@ impl StreamMuxer for Connection { match ready!(self.drop_listeners.poll_next_unpin(cx)) { Some(Ok(())) => {} Some(Err(e)) => { - log::debug!("a DropListener failed: {e}") + tracing::debug!("a DropListener failed: {e}") } None => { self.no_drop_listeners_waker = Some(cx.waker().clone()); @@ -208,7 +208,7 @@ impl StreamMuxer for Connection { // No need to hold the lock during the DTLS handshake. drop(peer_conn); - log::trace!("Opening data channel {}", data_channel.id()); + tracing::trace!(channel=%data_channel.id(), "Opening data channel"); let (tx, rx) = oneshot::channel::>(); @@ -226,7 +226,7 @@ impl StreamMuxer for Connection { Ok(detached) => { self.outbound_fut = None; - log::trace!("Outbound stream {}", detached.stream_identifier()); + tracing::trace!(stream=%detached.stream_identifier(), "Outbound stream"); let (stream, drop_listener) = Stream::new(detached); self.drop_listeners.push(drop_listener); @@ -244,7 +244,7 @@ impl StreamMuxer for Connection { } fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - log::debug!("Closing connection"); + tracing::debug!("Closing connection"); let peer_conn = self.peer_conn.clone(); let fut = self.close_fut.get_or_insert(Box::pin(async move { @@ -275,7 +275,7 @@ pub(crate) async fn register_data_channel_open_handler( data_channel.on_open({ let data_channel = data_channel.clone(); Box::new(move || { - log::debug!("Data channel {} open", data_channel.id()); + tracing::debug!(channel=%data_channel.id(), "Data channel open"); Box::pin(async move { let data_channel = data_channel.clone(); @@ -283,14 +283,14 @@ pub(crate) async fn register_data_channel_open_handler( match data_channel.detach().await { Ok(detached) => { if let Err(e) = data_channel_tx.send(detached.clone()) { - log::error!("Can't send data channel {}: {:?}", id, e); + tracing::error!(channel=%id, "Can't send data channel: {:?}", e); if let Err(e) = detached.close().await { - log::error!("Failed to close data channel {}: {}", id, e); + tracing::error!(channel=%id, "Failed to close data channel: {}", e); } } } Err(e) => { - log::error!("Can't detach data channel {}: {}", id, e); + tracing::error!(channel=%id, "Can't detach data channel: {}", e); } }; }) diff --git a/transports/webrtc/src/tokio/sdp.rs b/transports/webrtc/src/tokio/sdp.rs index e49345a01b2..8549a864dcc 100644 --- a/transports/webrtc/src/tokio/sdp.rs +++ b/transports/webrtc/src/tokio/sdp.rs @@ -49,7 +49,7 @@ pub(crate) fn offer(addr: SocketAddr, client_ufrag: &str) -> RTCSessionDescripti client_ufrag, ); - log::trace!("Created SDP offer: {offer}"); + tracing::trace!(offer=%offer, "Created SDP offer"); RTCSessionDescription::offer(offer).unwrap() } diff --git a/transports/webrtc/src/tokio/transport.rs b/transports/webrtc/src/tokio/transport.rs index 29a5e3901ac..b50e44fe4ba 100644 --- a/transports/webrtc/src/tokio/transport.rs +++ b/transports/webrtc/src/tokio/transport.rs @@ -238,7 +238,7 @@ impl ListenStream { /// terminate the stream. fn close(&mut self, reason: Result<(), Error>) { match self.report_closed { - Some(_) => log::debug!("Listener was already closed"), + Some(_) => tracing::debug!("Listener was already closed"), None => { // Report the listener event as closed. let _ = self diff --git a/transports/webrtc/src/tokio/udp_mux.rs b/transports/webrtc/src/tokio/udp_mux.rs index f978121d01c..20e04edaf72 100644 --- a/transports/webrtc/src/tokio/udp_mux.rs +++ b/transports/webrtc/src/tokio/udp_mux.rs @@ -175,7 +175,7 @@ impl UDPMuxNewAddr { None } Err(e) => { - log::debug!("{} (addr={})", e, addr); + tracing::debug!(address=%addr, "{}", e); None } } @@ -342,7 +342,7 @@ impl UDPMuxNewAddr { match self.conn_from_stun_message(read.filled(), &addr) { Some(Ok(s)) => Some(s), Some(Err(e)) => { - log::debug!("addr={}: Error when querying existing connections: {}", &addr, e); + tracing::debug!(address=%&addr, "Error when querying existing connections: {}", e); continue; } None => None, @@ -357,20 +357,20 @@ impl UDPMuxNewAddr { if !self.new_addrs.contains(&addr) { match ufrag_from_stun_message(read.filled(), false) { Ok(ufrag) => { - log::trace!( - "Notifying about new address addr={} from ufrag={}", - &addr, - ufrag - ); + tracing::trace!( + address=%&addr, + %ufrag, + "Notifying about new address from ufrag", + ); self.new_addrs.insert(addr); return Poll::Ready(UDPMuxEvent::NewAddr( NewAddr { addr, ufrag }, )); } Err(e) => { - log::debug!( - "Unknown address addr={} (non STUN packet: {})", - &addr, + tracing::debug!( + address=%&addr, + "Unknown address (non STUN packet: {})", e ); } @@ -384,10 +384,10 @@ impl UDPMuxNewAddr { async move { if let Err(err) = conn.write_packet(&packet, addr).await { - log::error!( - "Failed to write packet: {} (addr={})", + tracing::error!( + address=%addr, + "Failed to write packet: {}", err, - addr ); } } @@ -401,10 +401,10 @@ impl UDPMuxNewAddr { Poll::Pending => {} Poll::Ready(Err(err)) if err.kind() == ErrorKind::TimedOut => {} Poll::Ready(Err(err)) if err.kind() == ErrorKind::ConnectionReset => { - log::debug!("ConnectionReset by remote client {err:?}") + tracing::debug!("ConnectionReset by remote client {err:?}") } Poll::Ready(Err(err)) => { - log::error!("Could not read udp packet: {}", err); + tracing::error!("Could not read udp packet: {}", err); return Poll::Ready(UDPMuxEvent::Error(err)); } } @@ -470,7 +470,7 @@ impl UDPMux for UdpMuxHandle { async fn remove_conn_by_ufrag(&self, ufrag: &str) { if let Err(e) = self.remove_sender.send(ufrag.to_owned()).await { - log::debug!("Failed to send message through channel: {:?}", e); + tracing::debug!("Failed to send message through channel: {:?}", e); } } } @@ -511,12 +511,12 @@ impl UDPMuxWriter for UdpMuxWriterHandle { { Ok(()) => {} Err(e) => { - log::debug!("Failed to send message through channel: {:?}", e); + tracing::debug!("Failed to send message through channel: {:?}", e); return; } } - log::debug!("Registered {} for {}", addr, conn.key()); + tracing::debug!(address=%addr, connection=%conn.key(), "Registered address for connection"); } async fn send_to(&self, buf: &[u8], target: &SocketAddr) -> Result { diff --git a/transports/webrtc/src/tokio/upgrade.rs b/transports/webrtc/src/tokio/upgrade.rs index 414fc2721d0..e9010eb56f6 100644 --- a/transports/webrtc/src/tokio/upgrade.rs +++ b/transports/webrtc/src/tokio/upgrade.rs @@ -49,18 +49,18 @@ pub(crate) async fn outbound( server_fingerprint: Fingerprint, id_keys: identity::Keypair, ) -> Result<(PeerId, Connection), Error> { - log::debug!("new outbound connection to {addr})"); + tracing::debug!(address=%addr, "new outbound connection to address"); let (peer_connection, ufrag) = new_outbound_connection(addr, config, udp_mux).await?; let offer = peer_connection.create_offer(None).await?; - log::debug!("created SDP offer for outbound connection: {:?}", offer.sdp); + tracing::debug!(offer=%offer.sdp, "created SDP offer for outbound connection"); peer_connection.set_local_description(offer).await?; let answer = sdp::answer(addr, server_fingerprint, &ufrag); - log::debug!( - "calculated SDP answer for outbound connection: {:?}", - answer + tracing::debug!( + ?answer, + "calculated SDP answer for outbound connection" ); peer_connection.set_remote_description(answer).await?; // This will start the gathering of ICE candidates. @@ -85,16 +85,16 @@ pub(crate) async fn inbound( remote_ufrag: String, id_keys: identity::Keypair, ) -> Result<(PeerId, Connection), Error> { - log::debug!("new inbound connection from {addr} (ufrag: {remote_ufrag})"); + tracing::debug!(address=%addr, ufrag=%remote_ufrag, "new inbound connection from address"); let peer_connection = new_inbound_connection(addr, config, udp_mux, &remote_ufrag).await?; let offer = sdp::offer(addr, &remote_ufrag); - log::debug!("calculated SDP offer for inbound connection: {:?}", offer); + tracing::debug!(?offer, "calculated SDP offer for inbound connection"); peer_connection.set_remote_description(offer).await?; let answer = peer_connection.create_answer(None).await?; - log::debug!("created SDP answer for inbound connection: {:?}", answer); + tracing::debug!(?answer, "created SDP answer for inbound connection"); peer_connection.set_local_description(answer).await?; // This will start the gathering of ICE candidates. let data_channel = create_substream_for_noise_handshake(&peer_connection).await?; diff --git a/transports/webrtc/tests/smoke.rs b/transports/webrtc/tests/smoke.rs index 8e56b99723d..f6a5c8116ef 100644 --- a/transports/webrtc/tests/smoke.rs +++ b/transports/webrtc/tests/smoke.rs @@ -102,7 +102,11 @@ fn prop(number_listeners: NonZeroU8, number_streams: NonZeroU8) -> quickcheck::T let (listeners_tx, mut listeners_rx) = mpsc::channel(number_listeners); - log::info!("Creating {number_streams} streams on {number_listeners} connections"); + tracing::info!( + stream_count=%number_streams, + connection_count=%number_listeners, + "Creating streams on connections" + ); // Spawn the listener nodes. for _ in 0..number_listeners { @@ -244,7 +248,7 @@ async fn open_outbound_streams( }); } - log::info!("Created {number_streams} streams"); + tracing::info!(stream_count=%number_streams, "Created streams"); while future::poll_fn(|cx| connection.poll_unpin(cx)) .await From 09359014325f8fd84f708536c400ba6a967e8ea8 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 Sep 2023 17:54:55 +0300 Subject: [PATCH 058/105] weebrtc-websys crate tracing --- Cargo.lock | 2 +- transports/webrtc-websys/Cargo.toml | 2 +- transports/webrtc-websys/src/connection.rs | 16 ++++++++-------- transports/webrtc-websys/src/sdp.rs | 2 +- .../src/stream/poll_data_channel.rs | 8 ++++---- transports/webrtc-websys/src/upgrade.rs | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 508fed88d80..43600e13bcf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3254,10 +3254,10 @@ dependencies = [ "libp2p-ping", "libp2p-swarm", "libp2p-webrtc-utils", - "log", "send_wrapper 0.6.0", "serde", "thiserror", + "tracing", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", diff --git a/transports/webrtc-websys/Cargo.toml b/transports/webrtc-websys/Cargo.toml index 9c595071815..e11bec0762c 100644 --- a/transports/webrtc-websys/Cargo.toml +++ b/transports/webrtc-websys/Cargo.toml @@ -22,10 +22,10 @@ libp2p-core = { workspace = true } libp2p-identity = { workspace = true } libp2p-noise = { workspace = true } libp2p-webrtc-utils = { workspace = true } -log = "0.4.19" send_wrapper = { version = "0.6.0", features = ["futures"] } serde = { version = "1.0", features = ["derive"] } thiserror = "1" +tracing = { version = "0.1.37", features = ["log"] } wasm-bindgen = { version = "0.2.87" } wasm-bindgen-futures = { version = "0.4.37" } web-sys = { version = "0.3.64", features = ["Document", "Location", "MessageEvent", "Navigator", "RtcCertificate", "RtcConfiguration", "RtcDataChannel", "RtcDataChannelEvent", "RtcDataChannelInit", "RtcDataChannelState", "RtcDataChannelType", "RtcPeerConnection", "RtcSdpType", "RtcSessionDescription", "RtcSessionDescriptionInit", "Window"] } diff --git a/transports/webrtc-websys/src/connection.rs b/transports/webrtc-websys/src/connection.rs index dfdebbc98c0..94554763be0 100644 --- a/transports/webrtc-websys/src/connection.rs +++ b/transports/webrtc-websys/src/connection.rs @@ -47,16 +47,16 @@ impl Connection { let (mut tx_ondatachannel, rx_ondatachannel) = mpsc::channel(4); // we may get more than one data channel opened on a single peer connection let ondatachannel_closure = Closure::new(move |ev: RtcDataChannelEvent| { - log::trace!("New data channel"); + tracing::trace!("New data channel"); if let Err(e) = tx_ondatachannel.try_send(ev.channel()) { if e.is_full() { - log::warn!("Remote is opening too many data channels, we can't keep up!"); + tracing::warn!("Remote is opening too many data channels, we can't keep up!"); return; } if e.is_disconnected() { - log::warn!("Receiver is gone, are we shutting down?"); + tracing::warn!("Receiver is gone, are we shutting down?"); } } }); @@ -90,7 +90,7 @@ impl Connection { /// if they are used. fn close_connection(&mut self) { if !self.closed { - log::trace!("connection::close_connection"); + tracing::trace!("connection::close_connection"); self.inner.inner.close(); self.closed = true; } @@ -121,7 +121,7 @@ impl StreamMuxer for Connection { } None => { // This only happens if the [`RtcPeerConnection::ondatachannel`] closure gets freed which means we are most likely shutting down the connection. - log::debug!("`Sender` for inbound data channels has been dropped"); + tracing::debug!("`Sender` for inbound data channels has been dropped"); Poll::Ready(Err(Error::Connection("connection closed".to_owned()))) } } @@ -131,7 +131,7 @@ impl StreamMuxer for Connection { mut self: Pin<&mut Self>, _: &mut Context<'_>, ) -> Poll> { - log::trace!("Creating outbound data channel"); + tracing::trace!("Creating outbound data channel"); let data_channel = self.inner.new_regular_data_channel(); let stream = self.new_stream_from_data_channel(data_channel); @@ -144,7 +144,7 @@ impl StreamMuxer for Connection { mut self: Pin<&mut Self>, _cx: &mut Context<'_>, ) -> Poll> { - log::trace!("connection::poll_close"); + tracing::trace!("connection::poll_close"); self.close_connection(); Poll::Ready(Ok(())) @@ -158,7 +158,7 @@ impl StreamMuxer for Connection { match ready!(self.drop_listeners.poll_next_unpin(cx)) { Some(Ok(())) => {} Some(Err(e)) => { - log::debug!("a DropListener failed: {e}") + tracing::debug!("a DropListener failed: {e}") } None => { self.no_drop_listeners_waker = Some(cx.waker().clone()); diff --git a/transports/webrtc-websys/src/sdp.rs b/transports/webrtc-websys/src/sdp.rs index 6f50262b988..439182ea4db 100644 --- a/transports/webrtc-websys/src/sdp.rs +++ b/transports/webrtc-websys/src/sdp.rs @@ -46,7 +46,7 @@ pub(crate) fn offer(offer: String, client_ufrag: &str) -> RtcSessionDescriptionI // remove any double \r\n let munged_sdp_offer = munged_sdp_offer.replace("\r\n\r\n", "\r\n"); - log::trace!("Created SDP offer: {munged_sdp_offer}"); + tracing::trace!(offer=%munged_sdp_offer, "Created SDP offer"); let mut offer_obj = RtcSessionDescriptionInit::new(RtcSdpType::Offer); offer_obj.sdp(&munged_sdp_offer); diff --git a/transports/webrtc-websys/src/stream/poll_data_channel.rs b/transports/webrtc-websys/src/stream/poll_data_channel.rs index 9c9b19cdb32..0ee4f7920c9 100644 --- a/transports/webrtc-websys/src/stream/poll_data_channel.rs +++ b/transports/webrtc-websys/src/stream/poll_data_channel.rs @@ -53,7 +53,7 @@ impl PollDataChannel { let open_waker = open_waker.clone(); move |_: RtcDataChannelEvent| { - log::trace!("DataChannel opened"); + tracing::trace!("DataChannel opened"); open_waker.wake(); } }); @@ -65,7 +65,7 @@ impl PollDataChannel { let write_waker = write_waker.clone(); move |_: Event| { - log::trace!("DataChannel available for writing (again)"); + tracing::trace!("DataChannel available for writing (again)"); write_waker.wake(); } }); @@ -76,7 +76,7 @@ impl PollDataChannel { let close_waker = close_waker.clone(); move |_: Event| { - log::trace!("DataChannel closed"); + tracing::trace!("DataChannel closed"); close_waker.wake(); } }); @@ -98,7 +98,7 @@ impl PollDataChannel { if read_buffer.len() + data.length() as usize > MAX_MSG_LEN { overloaded.store(true, Ordering::SeqCst); - log::warn!("Remote is overloading us with messages, resetting stream",); + tracing::warn!("Remote is overloading us with messages, resetting stream",); return; } diff --git a/transports/webrtc-websys/src/upgrade.rs b/transports/webrtc-websys/src/upgrade.rs index 092baed50c4..cc053835041 100644 --- a/transports/webrtc-websys/src/upgrade.rs +++ b/transports/webrtc-websys/src/upgrade.rs @@ -45,12 +45,12 @@ async fn outbound_inner( let local_fingerprint = rtc_peer_connection.local_fingerprint()?; - log::trace!("local_fingerprint: {:?}", local_fingerprint); - log::trace!("remote_fingerprint: {:?}", remote_fingerprint); + tracing::trace!(?local_fingerprint); + tracing::trace!(?remote_fingerprint); let peer_id = noise::outbound(id_keys, channel, remote_fingerprint, local_fingerprint).await?; - log::debug!("Remote peer identified as {peer_id}"); + tracing::debug!(peer=%peer_id, "Remote peer identified"); Ok((peer_id, Connection::new(rtc_peer_connection))) } From 8e8980f42846b9e8271ab65435a786bd7eaf9f08 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Sat, 23 Sep 2023 14:30:09 +0300 Subject: [PATCH 059/105] websocket crate tracing --- Cargo.lock | 2 +- transports/websocket/Cargo.toml | 2 +- transports/websocket/src/framed.rs | 52 +++++++++++++++--------------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 247d0dcddd6..6e3f9d24628 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3275,12 +3275,12 @@ dependencies = [ "libp2p-dns", "libp2p-identity", "libp2p-tcp", - "log", "parking_lot", "quicksink", "rcgen 0.10.0", "rw-stream-sink", "soketto", + "tracing", "url", "webpki-roots", ] diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index f3ebf5af000..37d0ada4c74 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -16,11 +16,11 @@ either = "1.9.0" futures = "0.3.28" libp2p-core = { workspace = true } libp2p-identity = { workspace = true } -log = "0.4.20" parking_lot = "0.12.0" quicksink = "0.1" rw-stream-sink = { workspace = true } soketto = "0.7.0" +tracing = { version = "0.1.37", features = ["log"] } url = "2.4" webpki-roots = "0.25" diff --git a/transports/websocket/src/framed.rs b/transports/websocket/src/framed.rs index fc3f6514f12..24bde3b8439 100644 --- a/transports/websocket/src/framed.rs +++ b/transports/websocket/src/framed.rs @@ -28,7 +28,6 @@ use libp2p_core::{ transport::{ListenerId, TransportError, TransportEvent}, Transport, }; -use log::{debug, trace}; use parking_lot::Mutex; use soketto::{ connection::{self, CloseReason}, @@ -127,13 +126,13 @@ where if self.tls_config.server.is_some() { p } else { - debug!("/wss address but TLS server support is not configured"); + tracing::debug!("/wss address but TLS server support is not configured"); return Err(TransportError::MultiaddrNotSupported(addr)); } } Some(p @ Protocol::Ws(_)) => p, _ => { - debug!("{} is not a websocket multiaddr", addr); + tracing::debug!(address=%addr, "Address is not a websocket multiaddr"); return Err(TransportError::MultiaddrNotSupported(addr)); } }; @@ -187,7 +186,7 @@ where .get(&listener_id) .expect("Protocol was inserted in Transport::listen_on."); listen_addr.push(proto.clone()); - debug!("Listening on {}", listen_addr); + tracing::debug!(address=%listen_addr, "Listening on address"); TransportEvent::NewAddress { listener_id, listen_addr, @@ -288,7 +287,7 @@ where { Ok(Either::Left(redirect)) => { if remaining_redirects == 0 { - debug!("Too many redirects (> {})", max_redirects); + tracing::debug!(%max_redirects, "Too many redirects"); return Err(Error::TooManyRedirects); } remaining_redirects -= 1; @@ -310,7 +309,7 @@ where tls_config: tls::Config, role_override: Endpoint, ) -> Result>, Error> { - trace!("Dialing websocket address: {:?}", addr); + tracing::trace!(address=?addr, "Dialing websocket address"); let dial = match role_override { Endpoint::Dialer => transport.lock().dial(addr.tcp_addr), @@ -322,19 +321,19 @@ where })?; let stream = dial.map_err(Error::Transport).await?; - trace!("TCP connection to {} established.", addr.host_port); + tracing::trace!(port=%addr.host_port, "TCP connection established"); let stream = if addr.use_tls { // begin TLS session let dns_name = addr .dns_name .expect("for use_tls we have checked that dns_name is some"); - trace!("Starting TLS handshake with {:?}", dns_name); + tracing::trace!(?dns_name, "Starting TLS handshake"); let stream = tls_config .client .connect(dns_name.clone(), stream) .map_err(|e| { - debug!("TLS handshake with {:?} failed: {}", dns_name, e); + tracing::debug!(?dns_name, "TLS handshake failed: {}", e); Error::Tls(tls::Error::from(e)) }) .await?; @@ -346,7 +345,7 @@ where future::Either::Right(stream) }; - trace!("Sending websocket handshake to {}", addr.host_port); + tracing::trace!(port=%addr.host_port, "Sending websocket handshake"); let mut client = handshake::Client::new(stream, &addr.host_port, addr.path.as_ref()); @@ -359,9 +358,10 @@ where status_code, location, } => { - debug!( - "received redirect ({}); location: {}", - status_code, location + tracing::debug!( + %status_code, + %location, + "received redirect" ); Ok(Either::Left(location)) } @@ -370,7 +370,7 @@ where Err(Error::Handshake(msg.into())) } handshake::ServerResponse::Accepted { .. } => { - trace!("websocket handshake with {} successful", addr.host_port); + tracing::trace!(port=%addr.host_port, "websocket handshake successful"); Ok(Either::Right(Connection::new(client.into_builder()))) } } @@ -388,7 +388,7 @@ where async move { let stream = upgrade.map_err(Error::Transport).await?; - trace!("incoming connection from {}", remote_addr); + tracing::trace!(address=%remote_addr, "incoming connection from address"); let stream = if use_tls { // begin TLS session @@ -396,12 +396,12 @@ where .server .expect("for use_tls we checked server is not none"); - trace!("awaiting TLS handshake with {}", remote_addr); + tracing::trace!(address=%remote_addr, "awaiting TLS handshake with address"); let stream = server .accept(stream) .map_err(move |e| { - debug!("TLS handshake with {} failed: {}", remote_addr, e); + tracing::debug!(address=%remote_addr, "TLS handshake with address failed: {}", e); Error::Tls(tls::Error::from(e)) }) .await?; @@ -414,9 +414,9 @@ where future::Either::Right(stream) }; - trace!( - "receiving websocket handshake request from {}", - remote_addr2 + tracing::trace!( + address=%remote_addr2, + "receiving websocket handshake request from address" ); let mut server = handshake::Server::new(stream); @@ -429,9 +429,9 @@ where request.key() }; - trace!( - "accepting websocket handshake request from {}", - remote_addr2 + tracing::trace!( + address=%remote_addr2, + "accepting websocket handshake request from address" ); let response = handshake::server::Response::Accept { @@ -511,7 +511,7 @@ fn parse_ws_dial_addr(addr: Multiaddr) -> Result> { Some(Protocol::Ws(path)) => break (false, path.into_owned()), Some(Protocol::Wss(path)) => { if dns_name.is_none() { - debug!("Missing DNS name in WSS address: {}", addr); + tracing::debug!(addrress=%addr, "Missing DNS name in WSS address"); return Err(Error::InvalidMultiaddr(addr)); } break (true, path.into_owned()); @@ -556,13 +556,13 @@ fn location_to_multiaddr(location: &str) -> Result> { } else if s.eq_ignore_ascii_case("http") | s.eq_ignore_ascii_case("ws") { a.push(Protocol::Ws(url.path().into())) } else { - debug!("unsupported scheme: {}", s); + tracing::debug!(scheme=%s, "unsupported scheme"); return Err(Error::InvalidRedirectLocation); } Ok(a) } Err(e) => { - debug!("failed to parse url as multi-address: {:?}", e); + tracing::debug!("failed to parse url as multi-address: {:?}", e); Err(Error::InvalidRedirectLocation) } } From 62628f43dcf6b8ae34b92ccce89cdedc6b835144 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Sat, 23 Sep 2023 14:36:58 +0300 Subject: [PATCH 060/105] fix dependencies --- Cargo.lock | 2 +- core/Cargo.toml | 2 +- examples/autonat/Cargo.toml | 2 +- examples/browser-webrtc/Cargo.toml | 2 +- examples/chat/Cargo.toml | 2 +- examples/dcutr/Cargo.toml | 2 +- examples/distributed-key-value-store/Cargo.toml | 2 +- examples/file-sharing/Cargo.toml | 2 +- examples/identify/Cargo.toml | 2 +- examples/ipfs-kad/Cargo.toml | 2 +- examples/ipfs-private/Cargo.toml | 2 +- examples/metrics/Cargo.toml | 2 +- examples/ping/Cargo.toml | 2 +- examples/relay-server/Cargo.toml | 2 +- examples/rendezvous/Cargo.toml | 2 +- identity/Cargo.toml | 2 +- interop-tests/Cargo.toml | 4 ++-- misc/memory-connection-limits/Cargo.toml | 2 +- misc/multistream-select/Cargo.toml | 2 +- misc/server/Cargo.toml | 2 +- misc/webrtc-utils/Cargo.toml | 2 +- muxers/mplex/Cargo.toml | 2 +- muxers/test-harness/Cargo.toml | 2 +- muxers/yamux/Cargo.toml | 2 +- protocols/upnp/Cargo.toml | 2 +- transports/dns/Cargo.toml | 2 +- transports/noise/Cargo.toml | 2 +- transports/plaintext/Cargo.toml | 2 +- transports/pnet/Cargo.toml | 2 +- transports/quic/Cargo.toml | 2 +- transports/tcp/Cargo.toml | 2 +- transports/uds/Cargo.toml | 2 +- transports/webrtc-websys/Cargo.toml | 2 +- transports/webrtc/Cargo.toml | 2 +- transports/websocket/Cargo.toml | 2 +- transports/webtransport-websys/Cargo.toml | 2 +- transports/webtransport-websys/src/transport.rs | 2 +- 37 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6e3f9d24628..3ca8a73050e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3294,12 +3294,12 @@ dependencies = [ "libp2p-core", "libp2p-identity", "libp2p-noise", - "log", "multiaddr", "multibase", "multihash", "send_wrapper 0.6.0", "thiserror", + "tracing", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", diff --git a/core/Cargo.toml b/core/Cargo.toml index 6ca6f9830c2..6fc970998af 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -29,7 +29,7 @@ rw-stream-sink = { workspace = true } serde = { version = "1", optional = true, features = ["derive"] } smallvec = "1.11.0" thiserror = "1.0" -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" unsigned-varint = "0.7" void = "1" diff --git a/examples/autonat/Cargo.toml b/examples/autonat/Cargo.toml index 669e0561280..914e1b9eefd 100644 --- a/examples/autonat/Cargo.toml +++ b/examples/autonat/Cargo.toml @@ -10,5 +10,5 @@ async-std = { version = "1.12", features = ["attributes"] } clap = { version = "4.3.23", features = ["derive"] } futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "tcp", "noise", "yamux", "autonat", "identify", "macros"] } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file diff --git a/examples/browser-webrtc/Cargo.toml b/examples/browser-webrtc/Cargo.toml index e78813dc08a..00c11413881 100644 --- a/examples/browser-webrtc/Cargo.toml +++ b/examples/browser-webrtc/Cargo.toml @@ -17,7 +17,7 @@ anyhow = "1.0.72" env_logger = "0.10" futures = "0.3.28" rand = "0.8" -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] axum = "0.6.19" diff --git a/examples/chat/Cargo.toml b/examples/chat/Cargo.toml index 1fa090d31df..629634cc138 100644 --- a/examples/chat/Cargo.toml +++ b/examples/chat/Cargo.toml @@ -10,5 +10,5 @@ async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "gossipsub", "mdns", "noise", "macros", "tcp", "yamux", "quic"] } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/dcutr/Cargo.toml b/examples/dcutr/Cargo.toml index cf3bc3eaefa..1b593ed550f 100644 --- a/examples/dcutr/Cargo.toml +++ b/examples/dcutr/Cargo.toml @@ -11,5 +11,5 @@ env_logger = "0.10.0" futures = "0.3.28" futures-timer = "3.0" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "dcutr", "identify", "macros", "noise", "ping", "quic", "relay", "rendezvous", "tcp", "tokio", "yamux"] } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/distributed-key-value-store/Cargo.toml b/examples/distributed-key-value-store/Cargo.toml index 31742c7a541..a68ae7abcd8 100644 --- a/examples/distributed-key-value-store/Cargo.toml +++ b/examples/distributed-key-value-store/Cargo.toml @@ -10,5 +10,5 @@ async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "kad", "mdns", "noise", "macros", "tcp", "websocket", "yamux"] } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/file-sharing/Cargo.toml b/examples/file-sharing/Cargo.toml index f41fb7a5641..0edd79c2a41 100644 --- a/examples/file-sharing/Cargo.toml +++ b/examples/file-sharing/Cargo.toml @@ -12,6 +12,6 @@ clap = { version = "4.3.23", features = ["derive"] } either = "1.9" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "cbor", "dns", "kad", "noise", "macros", "request-response", "tcp", "websocket", "yamux"] } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } void = "1.0.2" diff --git a/examples/identify/Cargo.toml b/examples/identify/Cargo.toml index 13d68f612b5..0ed23978db3 100644 --- a/examples/identify/Cargo.toml +++ b/examples/identify/Cargo.toml @@ -11,5 +11,5 @@ async-trait = "0.1" env_logger = "0.10" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "dcutr", "identify", "macros", "noise", "ping", "relay", "rendezvous", "tcp", "tokio", "yamux"] } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/ipfs-kad/Cargo.toml b/examples/ipfs-kad/Cargo.toml index eaa62d30c73..4fe8a21505a 100644 --- a/examples/ipfs-kad/Cargo.toml +++ b/examples/ipfs-kad/Cargo.toml @@ -10,5 +10,5 @@ async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "kad", "noise", "tcp", "websocket", "yamux", "rsa"] } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/ipfs-private/Cargo.toml b/examples/ipfs-private/Cargo.toml index 47b150cbe18..995a8b75bed 100644 --- a/examples/ipfs-private/Cargo.toml +++ b/examples/ipfs-private/Cargo.toml @@ -11,5 +11,5 @@ async-trait = "0.1" either = "1.9" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "gossipsub", "dns", "identify", "kad", "macros", "noise", "ping", "pnet", "tcp", "websocket", "yamux"] } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/metrics/Cargo.toml b/examples/metrics/Cargo.toml index ef7c922dd57..f56d7cdbe22 100644 --- a/examples/metrics/Cargo.toml +++ b/examples/metrics/Cargo.toml @@ -11,5 +11,5 @@ hyper = { version = "0.14", features = ["server", "tcp", "http1"] } libp2p = { path = "../../libp2p", features = ["async-std", "metrics", "ping", "noise", "identify", "tcp", "yamux", "macros"] } tokio = { version = "1", features = ["rt-multi-thread"] } prometheus-client = "0.21.2" -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/ping/Cargo.toml b/examples/ping/Cargo.toml index ec45c14a232..b74292358c2 100644 --- a/examples/ping/Cargo.toml +++ b/examples/ping/Cargo.toml @@ -11,5 +11,5 @@ async-trait = "0.1" env_logger = "0.10.0" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "macros", "noise", "ping", "tcp", "websocket", "yamux"] } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/relay-server/Cargo.toml b/examples/relay-server/Cargo.toml index b180e1d91c2..d4ec4cf1ec0 100644 --- a/examples/relay-server/Cargo.toml +++ b/examples/relay-server/Cargo.toml @@ -11,5 +11,5 @@ async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "noise", "macros", "ping", "tcp", "identify", "yamux", "relay", "quic"] } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/rendezvous/Cargo.toml b/examples/rendezvous/Cargo.toml index 778209d1a43..9741cbdb533 100644 --- a/examples/rendezvous/Cargo.toml +++ b/examples/rendezvous/Cargo.toml @@ -11,5 +11,5 @@ async-trait = "0.1" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "identify", "macros", "noise", "ping", "rendezvous", "tcp", "tokio", "yamux"] } tokio = { version = "1.32", features = [ "rt-multi-thread", "macros", "time" ] } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/identity/Cargo.toml b/identity/Cargo.toml index e7be940ed9f..9ac40525d81 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -16,7 +16,7 @@ asn1_der = { version = "0.7.6", optional = true } bs58 = { version = "0.5.0", optional = true } ed25519-dalek = { version = "2.0", optional = true, features = ["rand_core"] } libsecp256k1 = { version = "0.7.0", optional = true } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" multihash = { version = "0.19.1", optional = true } p256 = { version = "0.13", default-features = false, features = ["ecdsa", "std", "pem"], optional = true } quick-protobuf = "0.8.1" diff --git a/interop-tests/Cargo.toml b/interop-tests/Cargo.toml index 936003ef459..a6526aa92be 100644 --- a/interop-tests/Cargo.toml +++ b/interop-tests/Cargo.toml @@ -14,7 +14,7 @@ either = "1.9.0" env_logger = "0.10.0" futures = "0.3.28" serde = { version = "1", features = ["derive"] } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" rand = "0.8.5" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] @@ -29,7 +29,7 @@ serde_json = "1" thirtyfour = "=0.32.0-rc.8" # https://github.com/stevepryde/thirtyfour/issues/169 tokio = { version = "1.32.0", features = ["full"] } tower-http = { version = "0.4", features = ["cors", "fs", "trace"] } -tracing = "0.1" +tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } [target.'cfg(target_arch = "wasm32")'.dependencies] diff --git a/misc/memory-connection-limits/Cargo.toml b/misc/memory-connection-limits/Cargo.toml index fbf034124dc..6d8ea90349d 100644 --- a/misc/memory-connection-limits/Cargo.toml +++ b/misc/memory-connection-limits/Cargo.toml @@ -15,7 +15,7 @@ libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true, features = ["peerid"] } sysinfo = "0.29" -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" void = "1" [dev-dependencies] diff --git a/misc/multistream-select/Cargo.toml b/misc/multistream-select/Cargo.toml index 5f7290e4474..b9f83719818 100644 --- a/misc/multistream-select/Cargo.toml +++ b/misc/multistream-select/Cargo.toml @@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] bytes = "1" futures = "0.3" -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" pin-project = "1.1.3" smallvec = "1.11.0" unsigned-varint = "0.7" diff --git a/misc/server/Cargo.toml b/misc/server/Cargo.toml index b81b8f743ec..cc48ee0c930 100644 --- a/misc/server/Cargo.toml +++ b/misc/server/Cargo.toml @@ -23,5 +23,5 @@ serde = "1.0.188" serde_derive = "1.0.125" serde_json = "1.0" tokio = { version = "1", features = ["rt-multi-thread", "macros"] } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" zeroize = "1" diff --git a/misc/webrtc-utils/Cargo.toml b/misc/webrtc-utils/Cargo.toml index 52482ebf607..fa949960d58 100644 --- a/misc/webrtc-utils/Cargo.toml +++ b/misc/webrtc-utils/Cargo.toml @@ -25,7 +25,7 @@ serde = { version = "1.0", features = ["derive"] } sha2 = "0.10.7" thiserror = "1" tinytemplate = "1.2" -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" [dev-dependencies] hex-literal = "0.4" diff --git a/muxers/mplex/Cargo.toml b/muxers/mplex/Cargo.toml index 6ad55a284f6..10581e99574 100644 --- a/muxers/mplex/Cargo.toml +++ b/muxers/mplex/Cargo.toml @@ -20,7 +20,7 @@ nohash-hasher = "0.2" parking_lot = "0.12" rand = "0.8" smallvec = "1.11.0" -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } [dev-dependencies] diff --git a/muxers/test-harness/Cargo.toml b/muxers/test-harness/Cargo.toml index 70b6aa3b3d6..460c25e5693 100644 --- a/muxers/test-harness/Cargo.toml +++ b/muxers/test-harness/Cargo.toml @@ -12,4 +12,4 @@ libp2p-core = { workspace = true } futures = "0.3.28" futures-timer = "3.0.2" futures_ringbuf = "0.4.0" -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" diff --git a/muxers/yamux/Cargo.toml b/muxers/yamux/Cargo.toml index 4917bb0717d..e2360b5739c 100644 --- a/muxers/yamux/Cargo.toml +++ b/muxers/yamux/Cargo.toml @@ -15,7 +15,7 @@ futures = "0.3.28" libp2p-core = { workspace = true } thiserror = "1.0" yamux = "0.12" -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" [dev-dependencies] async-std = { version = "1.7.0", features = ["attributes"] } diff --git a/protocols/upnp/Cargo.toml b/protocols/upnp/Cargo.toml index 0756dd35e05..a7735f81b87 100644 --- a/protocols/upnp/Cargo.toml +++ b/protocols/upnp/Cargo.toml @@ -17,7 +17,7 @@ igd-next = "0.14.2" libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } tokio = { version = "1.29", default-features = false, features = ["rt"], optional = true } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" void = "1.0.2" [features] diff --git a/transports/dns/Cargo.toml b/transports/dns/Cargo.toml index 2b041df9a62..496e7685fbe 100644 --- a/transports/dns/Cargo.toml +++ b/transports/dns/Cargo.toml @@ -18,7 +18,7 @@ libp2p-core = { workspace = true } libp2p-identity = { workspace = true } parking_lot = "0.12.0" smallvec = "1.11.0" -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" trust-dns-resolver = { version = "0.23", default-features = false, features = ["system-config"] } [dev-dependencies] diff --git a/transports/noise/Cargo.toml b/transports/noise/Cargo.toml index 2c05f16ecf5..051cb93f2c4 100644 --- a/transports/noise/Cargo.toml +++ b/transports/noise/Cargo.toml @@ -22,7 +22,7 @@ rand = "0.8.3" sha2 = "0.10.7" static_assertions = "1" thiserror = "1.0.48" -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" x25519-dalek = "1.1.0" zeroize = "1" diff --git a/transports/plaintext/Cargo.toml b/transports/plaintext/Cargo.toml index fff1831392c..8295d9c4561 100644 --- a/transports/plaintext/Cargo.toml +++ b/transports/plaintext/Cargo.toml @@ -17,7 +17,7 @@ futures = "0.3.28" libp2p-core = { workspace = true } libp2p-identity = { workspace = true } quick-protobuf = "0.8" -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } [dev-dependencies] diff --git a/transports/pnet/Cargo.toml b/transports/pnet/Cargo.toml index efc9749a702..347d9c82e8d 100644 --- a/transports/pnet/Cargo.toml +++ b/transports/pnet/Cargo.toml @@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"] futures = "0.3.28" salsa20 = "0.10" sha3 = "0.10" -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" rand = "0.8" pin-project = "1.1.3" diff --git a/transports/quic/Cargo.toml b/transports/quic/Cargo.toml index 7178a062ac7..8f9312a2fda 100644 --- a/transports/quic/Cargo.toml +++ b/transports/quic/Cargo.toml @@ -23,7 +23,7 @@ rand = "0.8.5" rustls = { version = "0.21.7", default-features = false } thiserror = "1.0.48" tokio = { version = "1.32.0", default-features = false, features = ["net", "rt", "time"], optional = true } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" socket2 = "0.5.4" [features] diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index 2a79a5aaaf0..a0ca08e316d 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -20,7 +20,7 @@ libp2p-core = { workspace = true } libp2p-identity = { workspace = true } socket2 = { version = "0.5.4", features = ["all"] } tokio = { version = "1.32.0", default-features = false, features = ["net"], optional = true } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" [features] tokio = ["dep:tokio", "if-watch/tokio"] diff --git a/transports/uds/Cargo.toml b/transports/uds/Cargo.toml index aa5a72aab14..2bd5dda60d6 100644 --- a/transports/uds/Cargo.toml +++ b/transports/uds/Cargo.toml @@ -15,7 +15,7 @@ async-std = { version = "1.6.2", optional = true } libp2p-core = { workspace = true } futures = "0.3.28" tokio = { version = "1.32", default-features = false, features = ["net"], optional = true } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" [dev-dependencies] tempfile = "3.8" diff --git a/transports/webrtc-websys/Cargo.toml b/transports/webrtc-websys/Cargo.toml index a7b78a96bdf..4c33f388026 100644 --- a/transports/webrtc-websys/Cargo.toml +++ b/transports/webrtc-websys/Cargo.toml @@ -25,7 +25,7 @@ libp2p-webrtc-utils = { workspace = true } send_wrapper = { version = "0.6.0", features = ["futures"] } serde = { version = "1.0", features = ["derive"] } thiserror = "1" -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" wasm-bindgen = { version = "0.2.87" } wasm-bindgen-futures = { version = "0.4.37" } web-sys = { version = "0.3.64", features = ["Document", "Location", "MessageEvent", "Navigator", "RtcCertificate", "RtcConfiguration", "RtcDataChannel", "RtcDataChannelEvent", "RtcDataChannelInit", "RtcDataChannelState", "RtcDataChannelType", "RtcPeerConnection", "RtcSdpType", "RtcSessionDescription", "RtcSessionDescriptionInit", "Window"] } diff --git a/transports/webrtc/Cargo.toml b/transports/webrtc/Cargo.toml index 62373345d5f..e61f90733d5 100644 --- a/transports/webrtc/Cargo.toml +++ b/transports/webrtc/Cargo.toml @@ -30,7 +30,7 @@ thiserror = "1" tinytemplate = "1.2" tokio = { version = "1.32", features = ["net"], optional = true} tokio-util = { version = "0.7", features = ["compat"], optional = true } -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" webrtc = { version = "0.9.0", optional = true } [features] diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index 37d0ada4c74..f91c0995678 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -20,7 +20,7 @@ parking_lot = "0.12.0" quicksink = "0.1" rw-stream-sink = { workspace = true } soketto = "0.7.0" -tracing = { version = "0.1.37", features = ["log"] } +tracing = "0.1.37" url = "2.4" webpki-roots = "0.25" diff --git a/transports/webtransport-websys/Cargo.toml b/transports/webtransport-websys/Cargo.toml index 7825f64a8ab..c8eff183481 100644 --- a/transports/webtransport-websys/Cargo.toml +++ b/transports/webtransport-websys/Cargo.toml @@ -19,11 +19,11 @@ js-sys = "0.3.64" libp2p-core = { workspace = true } libp2p-identity = { workspace = true } libp2p-noise = { workspace = true } -log = "0.4.20" multiaddr = { workspace = true } multihash = { workspace = true } send_wrapper = { version = "0.6.0", features = ["futures"] } thiserror = "1.0.48" +tracing = "0.1.37" wasm-bindgen = "0.2.87" wasm-bindgen-futures = "0.4.37" web-sys = { version = "0.3.64", features = [ diff --git a/transports/webtransport-websys/src/transport.rs b/transports/webtransport-websys/src/transport.rs index dcb3639a194..cb556ffef99 100644 --- a/transports/webtransport-websys/src/transport.rs +++ b/transports/webtransport-websys/src/transport.rs @@ -65,7 +65,7 @@ impl libp2p_core::Transport for Transport { fn dial(&mut self, addr: Multiaddr) -> Result> { let endpoint = Endpoint::from_multiaddr(&addr).map_err(|e| match e { e @ Error::InvalidMultiaddr(_) => { - log::warn!("{}", e); + tracing::warn!("{}", e); TransportError::MultiaddrNotSupported(addr) } e => TransportError::Other(e), From 8497c2d2b9488b7893d734f07c99f1bf672af077 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Sat, 23 Sep 2023 14:52:46 +0300 Subject: [PATCH 061/105] changes based on feedback --- core/src/transport/global_only.rs | 4 ++-- examples/dcutr/src/main.rs | 4 ++-- protocols/gossipsub/src/peer_score.rs | 13 ++++++------- protocols/identify/src/handler.rs | 4 +++- protocols/kad/src/handler.rs | 8 ++++---- protocols/perf/src/bin/perf.rs | 2 +- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/core/src/transport/global_only.rs b/core/src/transport/global_only.rs index c87affd2ecc..0671b0e9984 100644 --- a/core/src/transport/global_only.rs +++ b/core/src/transport/global_only.rs @@ -291,14 +291,14 @@ impl crate::Transport for Transport { match addr.iter().next() { Some(Protocol::Ip4(a)) => { if !ipv4_global::is_global(a) { - tracing::debug!(ip=?a, "Not dialing non global IP address"); + tracing::debug!(ip=%a, "Not dialing non global IP address"); return Err(TransportError::MultiaddrNotSupported(addr)); } self.inner.dial(addr) } Some(Protocol::Ip6(a)) => { if !ipv6_global::is_global(a) { - tracing::debug!(ip=?a, "Not dialing non global IP address"); + tracing::debug!(ip=%a, "Not dialing non global IP address"); return Err(TransportError::MultiaddrNotSupported(addr)); } self.inner.dial(addr) diff --git a/examples/dcutr/src/main.rs b/examples/dcutr/src/main.rs index b7a7df9be8d..7b62f115043 100644 --- a/examples/dcutr/src/main.rs +++ b/examples/dcutr/src/main.rs @@ -278,10 +278,10 @@ fn main() -> Result<(), Box> { SwarmEvent::ConnectionEstablished { peer_id, endpoint, .. } => { - tracing::info!(peer=%peer_id, endpoint=?endpoint, "Established connection to peer via endpoint"); + tracing::info!(peer=%peer_id, ?endpoint, "Established new connection"); } SwarmEvent::OutgoingConnectionError { peer_id, error, .. } => { - tracing::info!(peer=?peer_id, "Outgoing connection error to peer: {:?}", error); + tracing::info!(peer=?peer_id, "Outgoing connection failed: {error}"); } _ => {} } diff --git a/protocols/gossipsub/src/peer_score.rs b/protocols/gossipsub/src/peer_score.rs index bb808d7a094..b370d2dfe06 100644 --- a/protocols/gossipsub/src/peer_score.rs +++ b/protocols/gossipsub/src/peer_score.rs @@ -277,9 +277,8 @@ impl PeerScore { peer=%peer_id, %topic, %deficit, - "[Penalty] The peer has a mesh message deliveries deficit in topic\ - and will get penalized by {}", - p3 * topic_params.mesh_message_deliveries_weight + penalty=%topic_score, + "[Penalty] The peer has a mesh deliveries deficit and will be penalized" ); } @@ -349,8 +348,8 @@ impl PeerScore { if let Some(peer_stats) = self.peer_stats.get_mut(peer_id) { tracing::debug!( peer=%peer_id, - "[Penalty] Behavioral penalty for peer, count = {}.", - count + %count, + "[Penalty] Behavioral penalty for peer" ); peer_stats.behaviour_penalty += count as f64; } @@ -598,8 +597,8 @@ impl PeerScore { tracing::warn!( peer=%from, status=?record.status, - "Unexpected delivery trace: Message from peer was first seen {}s ago", - record.first_seen.elapsed().as_secs(), + first_seen=?record.first_seen.elapsed().as_secs(), + "Unexpected delivery trace" ); return; } diff --git a/protocols/identify/src/handler.rs b/protocols/identify/src/handler.rs index 846ed71cbc9..8cf92135f41 100644 --- a/protocols/identify/src/handler.rs +++ b/protocols/identify/src/handler.rs @@ -373,7 +373,9 @@ impl ConnectionHandler for Handler { if protocols_changed && self.exchanged_one_periodic_identify { tracing::debug!( peer=%self.remote_peer_id, - "Supported listen protocols changed from [{before}] to [{after}], pushing to peer" + %before, + %after, + "Supported listen protocols changed, pushing to peer" ); let info = self.build_info(); diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index b44fc9de992..0ee674d00ea 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -483,14 +483,14 @@ impl KademliaHandler { tracing::debug!( peer=%remote_peer_id, mode=%mode, - "Operating in mode on new outbound connection to peer" + "New outbound connection" ); } ConnectedPoint::Listener { .. } => { tracing::debug!( peer=%remote_peer_id, mode=%mode, - "Operating in mode on new inbound connection to peer" + "New inbound connection" ); } } @@ -710,7 +710,7 @@ impl ConnectionHandler for KademliaHandler { tracing::debug!( %peer, mode=%new_mode, - "Now operating in mode on outbound connection with peer" + "Changed mode on outbound connection" ) } ConnectedPoint::Listener { local_addr, .. } => { @@ -718,7 +718,7 @@ impl ConnectionHandler for KademliaHandler { %peer, mode=%new_mode, local_address=%local_addr, - "Now operating in mode on inbound connection with peer assuming that one of our external addresses routes to the local address") + "Changed mode on inbound connection assuming that one of our external addresses routes to the local address") } } diff --git a/protocols/perf/src/bin/perf.rs b/protocols/perf/src/bin/perf.rs index 9f763170fe5..b1318c0ab17 100644 --- a/protocols/perf/src/bin/perf.rs +++ b/protocols/perf/src/bin/perf.rs @@ -131,7 +131,7 @@ async fn server(server_address: SocketAddr) -> Result<()> { SwarmEvent::ConnectionEstablished { peer_id, endpoint, .. } => { - tracing::info!(peer=%peer_id, ?endpoint, "Established connection to peer via endpoint"); + tracing::info!(peer=%peer_id, ?endpoint, "Established new connection"); } SwarmEvent::ConnectionClosed { .. } => {} SwarmEvent::Behaviour(()) => { From b6f8e50441e5bc1542faf84a7725e8f52675673e Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Sat, 23 Sep 2023 14:55:31 +0300 Subject: [PATCH 062/105] cargo fmt --- Cargo.lock | 1 - protocols/relay/Cargo.toml | 1 - transports/tcp/src/lib.rs | 4 ++-- transports/webrtc/src/tokio/upgrade.rs | 5 +---- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3ca8a73050e..efa7f23dc93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2959,7 +2959,6 @@ dependencies = [ "libp2p-plaintext", "libp2p-swarm", "libp2p-yamux", - "log", "quick-protobuf", "quick-protobuf-codec", "quickcheck-ext", diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index 1ce704bedae..d230dfc7fef 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -21,7 +21,6 @@ instant = "0.1.12" libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true } -log = "0.4" quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } rand = "0.8.4" diff --git a/transports/tcp/src/lib.rs b/transports/tcp/src/lib.rs index bbe052b531c..c4384f8b400 100644 --- a/transports/tcp/src/lib.rs +++ b/transports/tcp/src/lib.rs @@ -763,8 +763,8 @@ where let remote_addr = ip_to_multiaddr(remote_addr.ip(), remote_addr.port()); tracing::debug!( - remote_address=%remote_addr, - local_address=%local_addr, + remote_address=%remote_addr, + local_address=%local_addr, "Incoming connection from remote at local" ); diff --git a/transports/webrtc/src/tokio/upgrade.rs b/transports/webrtc/src/tokio/upgrade.rs index e9010eb56f6..4145a5e7510 100644 --- a/transports/webrtc/src/tokio/upgrade.rs +++ b/transports/webrtc/src/tokio/upgrade.rs @@ -58,10 +58,7 @@ pub(crate) async fn outbound( peer_connection.set_local_description(offer).await?; let answer = sdp::answer(addr, server_fingerprint, &ufrag); - tracing::debug!( - ?answer, - "calculated SDP answer for outbound connection" - ); + tracing::debug!(?answer, "calculated SDP answer for outbound connection"); peer_connection.set_remote_description(answer).await?; // This will start the gathering of ICE candidates. let data_channel = create_substream_for_noise_handshake(&peer_connection).await?; From 09ea23ad365aee19eb8dc1b58c082dce55584934 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Sat, 23 Sep 2023 16:01:25 +0300 Subject: [PATCH 063/105] personal review --- examples/browser-webrtc/src/main.rs | 8 ++++---- examples/metrics/src/http_service.rs | 2 +- examples/metrics/src/main.rs | 8 ++++---- interop-tests/src/bin/wasm_ping.rs | 6 +++--- interop-tests/src/lib.rs | 4 ++-- misc/multistream-select/src/length_delimited.rs | 2 +- misc/server/src/http_service.rs | 6 +----- misc/server/src/main.rs | 4 ++-- protocols/autonat/src/behaviour/as_client.rs | 8 ++++---- protocols/autonat/src/behaviour/as_server.rs | 2 +- protocols/mdns/src/behaviour/iface.rs | 4 ++-- protocols/perf/src/bin/perf.rs | 13 +++++++------ protocols/ping/Cargo.toml | 2 +- swarm/src/connection/pool.rs | 2 +- swarm/src/lib.rs | 4 ++-- 15 files changed, 36 insertions(+), 39 deletions(-) diff --git a/examples/browser-webrtc/src/main.rs b/examples/browser-webrtc/src/main.rs index 339ac87e79f..4d3ca3bfee7 100644 --- a/examples/browser-webrtc/src/main.rs +++ b/examples/browser-webrtc/src/main.rs @@ -60,7 +60,7 @@ async fn main() -> anyhow::Result<()> { continue; } - tracing::info!("Listening on: {address}"); + tracing::info!(%address, "Listening"); break address; } @@ -74,7 +74,7 @@ async fn main() -> anyhow::Result<()> { loop { tokio::select! { swarm_event = swarm.next() => { - tracing::trace!("Swarm Event: {:?}", swarm_event) + tracing::trace!(?swarm_event) }, _ = tokio::signal::ctrl_c() => { break; @@ -110,7 +110,7 @@ pub(crate) async fn serve(libp2p_transport: Multiaddr) { let addr = SocketAddr::new(listen_addr.into(), 8080); - tracing::info!("Serving client files at http://{addr}"); + tracing::info!(url=%format!("http://{addr}"), "Serving client files at url"); axum::Server::bind(&addr) .serve(server.into_make_service()) @@ -141,7 +141,7 @@ async fn get_index( /// Serves the static files generated by `wasm-pack`. async fn get_static_file(Path(path): Path) -> Result { - tracing::debug!("Serving static file: {path}"); + tracing::debug!(file_path=%path, "Serving static file"); let content = StaticFiles::get(&path).ok_or(StatusCode::NOT_FOUND)?.data; let content_type = mime_guess::from_path(path) diff --git a/examples/metrics/src/http_service.rs b/examples/metrics/src/http_service.rs index 161f9a4baa7..b1d64e8a76a 100644 --- a/examples/metrics/src/http_service.rs +++ b/examples/metrics/src/http_service.rs @@ -38,7 +38,7 @@ pub(crate) async fn metrics_server(registry: Registry) -> Result<(), std::io::Er let rt = tokio::runtime::Runtime::new()?; rt.block_on(async { let server = Server::bind(&addr).serve(MakeMetricService::new(registry)); - tracing::info!("Metrics server on http://{}/metrics", server.local_addr()); + tracing::info!(metrics_server=%format!("http://{}/metrics", server.local_addr())); if let Err(e) = server.await { tracing::error!("server error: {}", e); } diff --git a/examples/metrics/src/main.rs b/examples/metrics/src/main.rs index 7dc04b61e40..b1381d2baec 100644 --- a/examples/metrics/src/main.rs +++ b/examples/metrics/src/main.rs @@ -63,7 +63,7 @@ fn main() -> Result<(), Box> { if let Some(addr) = std::env::args().nth(1) { let remote: Multiaddr = addr.parse()?; swarm.dial(remote)?; - tracing::info!("Dialed {}", addr) + tracing::info!(address=%addr, "Dialed address") } let mut metric_registry = Registry::default(); @@ -74,15 +74,15 @@ fn main() -> Result<(), Box> { loop { match swarm.select_next_some().await { SwarmEvent::Behaviour(BehaviourEvent::Ping(ping_event)) => { - tracing::info!("{:?}", ping_event); + tracing::info!(?ping_event); metrics.record(&ping_event); } SwarmEvent::Behaviour(BehaviourEvent::Identify(identify_event)) => { - tracing::info!("{:?}", identify_event); + tracing::info!(?identify_event); metrics.record(&identify_event); } swarm_event => { - tracing::info!("{:?}", swarm_event); + tracing::info!(?swarm_event); metrics.record(&swarm_event); } } diff --git a/interop-tests/src/bin/wasm_ping.rs b/interop-tests/src/bin/wasm_ping.rs index 7977c59f048..592716651da 100644 --- a/interop-tests/src/bin/wasm_ping.rs +++ b/interop-tests/src/bin/wasm_ping.rs @@ -151,9 +151,9 @@ async fn redis_blpop( .await .map_err(|e| { tracing::warn!( - "Failed to get list elem {} within timeout {}: {e}", - request.key, - request.timeout + key=%request.key, + timeout=%request.timeout, + "Failed to get list elem key within timeout: {e}" ); StatusCode::INTERNAL_SERVER_ERROR })?; diff --git a/interop-tests/src/lib.rs b/interop-tests/src/lib.rs index 4f33480b502..318048044d1 100644 --- a/interop-tests/src/lib.rs +++ b/interop-tests/src/lib.rs @@ -70,7 +70,7 @@ pub async fn run_test( let handshake_start = Instant::now(); swarm.dial(other.parse::()?)?; - tracing::info!("Test instance, dialing multiaddress on: {}.", other); + tracing::info!(listener=%other, "Test instance, dialing multiaddress"); let rtt = loop { if let Some(SwarmEvent::Behaviour(BehaviourEvent::Ping(ping::Event { @@ -147,7 +147,7 @@ pub async fn run_test_wasm( base_url: &str, ) -> Result<(), JsValue> { let result = run_test(transport, ip, is_dialer, test_timeout_secs, base_url).await; - tracing::info!("Sending test result: {result:?}"); + tracing::info!(?result, "Sending test result"); reqwest::Client::new() .post(&format!("http://{}/results", base_url)) .json(&result.map_err(|e| e.to_string())) diff --git a/misc/multistream-select/src/length_delimited.rs b/misc/multistream-select/src/length_delimited.rs index a2c36b05ece..6515d00c717 100644 --- a/misc/multistream-select/src/length_delimited.rs +++ b/misc/multistream-select/src/length_delimited.rs @@ -170,7 +170,7 @@ where if (buf[*pos - 1] & 0x80) == 0 { // MSB is not set, indicating the end of the length prefix. let (len, _) = unsigned_varint::decode::u16(buf).map_err(|e| { - tracing::debug!("invalid length prefix: {}", e); + tracing::debug!("invalid length prefix: {e}"); io::Error::new(io::ErrorKind::InvalidData, "invalid length prefix") })?; diff --git a/misc/server/src/http_service.rs b/misc/server/src/http_service.rs index 568eb6e4547..7905933fbf5 100644 --- a/misc/server/src/http_service.rs +++ b/misc/server/src/http_service.rs @@ -37,11 +37,7 @@ pub(crate) async fn metrics_server( let addr = ([0, 0, 0, 0], 8888).into(); let server = Server::bind(&addr).serve(MakeMetricService::new(registry, metrics_path.clone())); - tracing::info!( - "Metrics server on http://{}{}", - server.local_addr(), - metrics_path - ); + tracing::info!(metrics_server=%format!("http://{}{}", server.local_addr(), metrics_path)); server.await?; Ok(()) } diff --git a/misc/server/src/main.rs b/misc/server/src/main.rs index b8de28d6a88..2b23db53266 100644 --- a/misc/server/src/main.rs +++ b/misc/server/src/main.rs @@ -113,7 +113,7 @@ async fn main() -> Result<(), Box> { match swarm.listen_on(address.clone()) { Ok(_) => {} Err(e @ libp2p::TransportError::MultiaddrNotSupported(_)) => { - tracing::warn!("Failed to listen on {address}, continuing anyways, {e}") + tracing::warn!(%address, "Failed to listen on address, continuing anyways, {e}") } Err(e) => return Err(e.into()), } @@ -202,7 +202,7 @@ async fn main() -> Result<(), Box> { // metrics.record(&e) } SwarmEvent::NewListenAddr { address, .. } => { - tracing::info!("Listening on {address:?}"); + tracing::info!(%address, "Listening on address"); } _ => {} } diff --git a/protocols/autonat/src/behaviour/as_client.rs b/protocols/autonat/src/behaviour/as_client.rs index 034b1593f1f..7e828794457 100644 --- a/protocols/autonat/src/behaviour/as_client.rs +++ b/protocols/autonat/src/behaviour/as_client.rs @@ -113,7 +113,7 @@ impl<'a> HandleInnerEvent for AsClient<'a> { response, }, } => { - tracing::debug!("Outbound dial-back request returned {:?}.", response); + tracing::debug!(?response, "Outbound dial-back request returned response"); let probe_id = self .ongoing_outbound @@ -346,9 +346,9 @@ impl<'a> AsClient<'a> { } tracing::debug!( - "Flipped assumed NAT status from {:?} to {:?}", - self.nat_status, - reported_status + old_status=?self.nat_status, + new_status=?reported_status, + "Flipped assumed NAT status" ); let old_status = self.nat_status.clone(); diff --git a/protocols/autonat/src/behaviour/as_server.rs b/protocols/autonat/src/behaviour/as_server.rs index 8ba070d4669..52bc30ce83f 100644 --- a/protocols/autonat/src/behaviour/as_server.rs +++ b/protocols/autonat/src/behaviour/as_server.rs @@ -210,7 +210,7 @@ impl<'a> AsServer<'a> { tracing::debug!( %peer, %address, - "Dial-back to peer succeeded at address" + "Dial-back to peer succeeded" ); let (probe_id, _, _, channel) = self.ongoing_inbound.remove(peer).unwrap(); diff --git a/protocols/mdns/src/behaviour/iface.rs b/protocols/mdns/src/behaviour/iface.rs index 90d28651bd3..2513283534b 100644 --- a/protocols/mdns/src/behaviour/iface.rs +++ b/protocols/mdns/src/behaviour/iface.rs @@ -167,7 +167,7 @@ where } pub(crate) fn reset_timer(&mut self) { - tracing::trace!("reset timer on {:#?} {:#?}", self.addr, self.probe_state); + tracing::trace!(address=%self.addr, probe_state=?self.probe_state, "reset timer"); let interval = *self.probe_state.interval(); self.timeout = T::interval(interval); } @@ -186,7 +186,7 @@ where if Pin::new(&mut self.timeout).poll_next(cx).is_ready() { tracing::trace!(address=%self.addr, "sending query on iface"); self.send_buffer.push_back(build_query()); - tracing::trace!("tick on {:#?} {:#?}", self.addr, self.probe_state); + tracing::trace!(address=%self.addr, probe_state=?self.probe_state, "tick"); // Stop to probe when the initial interval reach the query interval if let ProbeState::Probing(interval) = self.probe_state { diff --git a/protocols/perf/src/bin/perf.rs b/protocols/perf/src/bin/perf.rs index b1318c0ab17..1c9da6ec712 100644 --- a/protocols/perf/src/bin/perf.rs +++ b/protocols/perf/src/bin/perf.rs @@ -254,11 +254,12 @@ async fn latency(server_address: Multiaddr) -> Result<()> { latencies.sort_by(|a, b| a.partial_cmp(b).unwrap()); tracing::info!( - "Finished: {rounds} pings in {:.4}s", - start.elapsed().as_secs_f64() + %rounds, + elapsed_time=%format!("{:.4}s", start.elapsed().as_secs_f64()), + "Finished rounds of pings" ); - tracing::info!("- {:.4} s median", percentile(&latencies, 0.50),); - tracing::info!("- {:.4} s 95th percentile\n", percentile(&latencies, 0.95),); + tracing::info!(median=%format!("- {:.4} s", percentile(&latencies, 0.50))); + tracing::info!(ninety_fifth_percentile=%format!("- {:.4} s", percentile(&latencies, 0.95))); Ok(()) } @@ -328,7 +329,7 @@ async fn requests_per_second(server_address: Multiaddr) -> Result<()> { tracing::info!( "Finished: sent {num} {to_send} bytes requests with {to_receive} bytes response each within {duration:.2} s", ); - tracing::info!("- {requests_per_second:.2} req/s\n"); + tracing::info!(requests_per_second=%format!("{requests_per_second:.2}")); Ok(()) } @@ -442,7 +443,7 @@ async fn connect( let duration = start.elapsed(); let duration_seconds = duration.as_secs_f64(); - tracing::info!("established connection in {duration_seconds:.4} s"); + tracing::info!(elapsed_time=%format!("{duration_seconds:.4} s")); Ok(server_peer_id) } diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index 6f90c7473ed..0e881d052e9 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -19,8 +19,8 @@ libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true } rand = "0.8" -void = "1.0" tracing = "0.1.37" +void = "1.0" [dev-dependencies] async-std = "1.6.2" diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index 8b185b65f01..df19c69eb50 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -516,7 +516,7 @@ where waker.wake(); } - let span = tracing::error_span!("connection", id = %id, peer = %obtained_peer_id, peer_address = %endpoint.get_remote_address()); + let span = tracing::error_span!("connection", id = %id, peer = %obtained_peer_id, remote_address = %endpoint.get_remote_address()); let connection: Connection = Connection::new( connection, handler, diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index f736d96fe4a..0b5b3035ff3 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -1004,8 +1004,8 @@ where } => { tracing::debug!( listener=?listener_id, - "Listener closed by {:?}.", - reason + ?reason, + "Listener closed" ); let addrs = self.listened_addrs.remove(&listener_id).unwrap_or_default(); for addr in addrs.iter() { From cbbf21c5e1047d5b2c08770f70c8725c65e62d02 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Sun, 1 Oct 2023 13:50:53 +0300 Subject: [PATCH 064/105] remove env logger dependency --- Cargo.lock | 71 +++++++------------ examples/browser-webrtc/Cargo.toml | 2 +- examples/browser-webrtc/src/main.rs | 6 +- examples/dcutr/Cargo.toml | 1 - examples/dcutr/src/main.rs | 7 +- examples/identify/Cargo.toml | 1 - examples/identify/src/main.rs | 8 +-- examples/ping/Cargo.toml | 1 - examples/ping/src/main.rs | 7 +- interop-tests/Cargo.toml | 4 +- interop-tests/src/arch.rs | 6 +- libp2p/Cargo.toml | 7 +- libp2p/src/tutorials/ping.rs | 13 ++-- misc/multistream-select/Cargo.toml | 2 +- .../multistream-select/tests/dialer_select.rs | 3 +- misc/server/Cargo.toml | 2 +- misc/server/src/main.rs | 3 +- muxers/mplex/Cargo.toml | 2 +- muxers/mplex/benches/split_send_size.rs | 3 +- muxers/mplex/src/io.rs | 6 +- protocols/autonat/Cargo.toml | 2 +- protocols/dcutr/Cargo.toml | 2 +- protocols/dcutr/tests/lib.rs | 3 +- protocols/gossipsub/Cargo.toml | 2 +- protocols/gossipsub/src/behaviour/tests.rs | 3 +- protocols/gossipsub/tests/smoke.rs | 4 +- protocols/identify/Cargo.toml | 2 +- protocols/identify/tests/smoke.rs | 7 +- protocols/kad/Cargo.toml | 2 +- protocols/kad/tests/client_mode.rs | 9 +-- protocols/mdns/Cargo.toml | 2 +- protocols/mdns/tests/use-async-std.rs | 9 +-- protocols/mdns/tests/use-tokio.rs | 7 +- protocols/perf/Cargo.toml | 2 +- protocols/perf/src/bin/perf.rs | 5 +- protocols/perf/tests/lib.rs | 3 +- protocols/ping/Cargo.toml | 2 +- protocols/relay/Cargo.toml | 2 +- protocols/relay/tests/lib.rs | 11 +-- protocols/rendezvous/Cargo.toml | 6 +- protocols/rendezvous/tests/rendezvous.rs | 17 ++--- protocols/request-response/Cargo.toml | 2 +- protocols/request-response/tests/ping.rs | 3 +- swarm/Cargo.toml | 2 +- swarm/src/lib.rs | 2 +- transports/dns/Cargo.toml | 2 +- transports/dns/src/lib.rs | 3 +- transports/noise/Cargo.toml | 2 +- transports/noise/tests/smoke.rs | 3 +- transports/plaintext/Cargo.toml | 2 +- transports/plaintext/tests/smoke.rs | 3 +- transports/quic/Cargo.toml | 2 +- transports/quic/tests/smoke.rs | 23 +++--- transports/tcp/Cargo.toml | 2 +- transports/tcp/src/lib.rs | 14 ++-- transports/webrtc/Cargo.toml | 5 +- transports/webrtc/tests/smoke.rs | 5 +- 57 files changed, 155 insertions(+), 177 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 79fb7e08cd2..e5ea0d5276e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -668,7 +668,6 @@ version = "0.1.0" dependencies = [ "anyhow", "axum", - "env_logger 0.10.0", "futures", "js-sys", "libp2p", @@ -682,6 +681,7 @@ dependencies = [ "tower", "tower-http", "tracing", + "tracing-subscriber", "wasm-bindgen", "wasm-bindgen-futures", "wasm-logger", @@ -1233,7 +1233,6 @@ name = "dcutr-example" version = "0.1.0" dependencies = [ "clap", - "env_logger 0.10.0", "futures", "futures-timer", "libp2p", @@ -1432,19 +1431,6 @@ dependencies = [ "regex", ] -[[package]] -name = "env_logger" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" -dependencies = [ - "humantime", - "is-terminal", - "log", - "regex", - "termcolor", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -2007,12 +1993,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "hyper" version = "0.14.27" @@ -2071,7 +2051,6 @@ version = "0.1.0" dependencies = [ "async-std", "async-trait", - "env_logger 0.10.0", "futures", "libp2p", "tracing", @@ -2206,7 +2185,6 @@ dependencies = [ "axum", "console_error_panic_hook", "either", - "env_logger 0.10.0", "futures", "futures-timer", "instant", @@ -2372,7 +2350,6 @@ dependencies = [ "bytes", "clap", "either", - "env_logger 0.10.0", "futures", "futures-timer", "getrandom 0.2.10", @@ -2412,6 +2389,7 @@ dependencies = [ "multiaddr", "pin-project", "tokio", + "tracing-subscriber", ] [[package]] @@ -2433,7 +2411,6 @@ version = "0.11.0" dependencies = [ "async-std", "async-trait", - "env_logger 0.10.0", "futures", "futures-timer", "instant", @@ -2445,6 +2422,7 @@ dependencies = [ "quick-protobuf", "rand 0.8.5", "tracing", + "tracing-subscriber", ] [[package]] @@ -2503,7 +2481,6 @@ dependencies = [ "asynchronous-codec", "clap", "either", - "env_logger 0.10.0", "futures", "futures-timer", "instant", @@ -2524,6 +2501,7 @@ dependencies = [ "rand 0.8.5", "thiserror", "tracing", + "tracing-subscriber", "void", ] @@ -2548,7 +2526,6 @@ dependencies = [ "async-std", "async-std-resolver", "async-trait", - "env_logger 0.10.0", "futures", "libp2p-core", "libp2p-identity", @@ -2556,6 +2533,7 @@ dependencies = [ "smallvec", "tokio", "tracing", + "tracing-subscriber", "trust-dns-resolver", ] @@ -2588,7 +2566,6 @@ dependencies = [ "byteorder", "bytes", "either", - "env_logger 0.10.0", "fnv", "futures", "futures-ticker", @@ -2612,6 +2589,7 @@ dependencies = [ "sha2 0.10.7", "smallvec", "tracing", + "tracing-subscriber", "unsigned-varint", "void", ] @@ -2623,7 +2601,6 @@ dependencies = [ "async-std", "asynchronous-codec", "either", - "env_logger 0.10.0", "futures", "futures-timer", "libp2p-core", @@ -2636,6 +2613,7 @@ dependencies = [ "smallvec", "thiserror", "tracing", + "tracing-subscriber", "void", ] @@ -2676,7 +2654,6 @@ dependencies = [ "asynchronous-codec", "bytes", "either", - "env_logger 0.10.0", "fnv", "futures", "futures-timer", @@ -2697,6 +2674,7 @@ dependencies = [ "smallvec", "thiserror", "tracing", + "tracing-subscriber", "uint", "unsigned-varint", "void", @@ -2709,7 +2687,6 @@ dependencies = [ "async-io", "async-std", "data-encoding", - "env_logger 0.10.0", "futures", "if-watch", "libp2p-core", @@ -2724,6 +2701,7 @@ dependencies = [ "socket2 0.5.4", "tokio", "tracing", + "tracing-subscriber", "trust-dns-proto", "void", ] @@ -2772,7 +2750,6 @@ dependencies = [ "asynchronous-codec", "bytes", "criterion", - "env_logger 0.10.0", "futures", "libp2p-core", "libp2p-identity", @@ -2785,6 +2762,7 @@ dependencies = [ "rand 0.8.5", "smallvec", "tracing", + "tracing-subscriber", "unsigned-varint", ] @@ -2805,7 +2783,6 @@ version = "0.43.1" dependencies = [ "bytes", "curve25519-dalek 4.1.0", - "env_logger 0.10.0", "futures", "futures_ringbuf", "libp2p-core", @@ -2821,6 +2798,7 @@ dependencies = [ "static_assertions", "thiserror", "tracing", + "tracing-subscriber", "x25519-dalek 1.1.1", "zeroize", ] @@ -2832,7 +2810,6 @@ dependencies = [ "anyhow", "async-trait", "clap", - "env_logger 0.10.0", "futures", "instant", "libp2p-core", @@ -2851,6 +2828,7 @@ dependencies = [ "thiserror", "tokio", "tracing", + "tracing-subscriber", "void", ] @@ -2860,7 +2838,6 @@ version = "0.43.1" dependencies = [ "async-std", "either", - "env_logger 0.10.0", "futures", "futures-timer", "instant", @@ -2871,6 +2848,7 @@ dependencies = [ "quickcheck-ext", "rand 0.8.5", "tracing", + "tracing-subscriber", "void", ] @@ -2880,7 +2858,6 @@ version = "0.40.0" dependencies = [ "asynchronous-codec", "bytes", - "env_logger 0.10.0", "futures", "futures_ringbuf", "libp2p-core", @@ -2889,6 +2866,7 @@ dependencies = [ "quickcheck-ext", "rand 0.8.5", "tracing", + "tracing-subscriber", "unsigned-varint", ] @@ -2919,7 +2897,6 @@ version = "0.9.2" dependencies = [ "async-std", "bytes", - "env_logger 0.10.0", "futures", "futures-timer", "if-watch", @@ -2939,6 +2916,7 @@ dependencies = [ "thiserror", "tokio", "tracing", + "tracing-subscriber", ] [[package]] @@ -2948,7 +2926,6 @@ dependencies = [ "asynchronous-codec", "bytes", "either", - "env_logger 0.10.0", "futures", "futures-bounded", "futures-timer", @@ -2966,6 +2943,7 @@ dependencies = [ "static_assertions", "thiserror", "tracing", + "tracing-subscriber", "void", ] @@ -2976,7 +2954,6 @@ dependencies = [ "async-trait", "asynchronous-codec", "bimap", - "env_logger 0.10.0", "futures", "futures-timer", "instant", @@ -2996,6 +2973,7 @@ dependencies = [ "thiserror", "tokio", "tracing", + "tracing-subscriber", "void", ] @@ -3006,7 +2984,6 @@ dependencies = [ "async-std", "async-trait", "cbor4ii", - "env_logger 0.10.0", "futures", "futures_ringbuf", "instant", @@ -3022,6 +2999,7 @@ dependencies = [ "serde_json", "smallvec", "tracing", + "tracing-subscriber", "void", ] @@ -3031,7 +3009,6 @@ version = "0.12.3" dependencies = [ "base64 0.21.4", "clap", - "env_logger 0.10.0", "futures", "futures-timer", "hyper", @@ -3042,6 +3019,7 @@ dependencies = [ "serde_json", "tokio", "tracing", + "tracing-subscriber", "zeroize", ] @@ -3051,7 +3029,6 @@ version = "0.43.4" dependencies = [ "async-std", "either", - "env_logger 0.10.0", "fnv", "futures", "futures-timer", @@ -3073,6 +3050,7 @@ dependencies = [ "smallvec", "tokio", "tracing", + "tracing-subscriber", "trybuild", "void", "wasm-bindgen-futures", @@ -3112,7 +3090,6 @@ version = "0.40.0" dependencies = [ "async-io", "async-std", - "env_logger 0.10.0", "futures", "futures-timer", "if-watch", @@ -3122,6 +3099,7 @@ dependencies = [ "socket2 0.5.4", "tokio", "tracing", + "tracing-subscriber", ] [[package]] @@ -3190,7 +3168,6 @@ version = "0.6.1-alpha" dependencies = [ "async-trait", "bytes", - "env_logger 0.10.0", "futures", "futures-timer", "hex", @@ -3210,6 +3187,7 @@ dependencies = [ "tokio", "tokio-util", "tracing", + "tracing-subscriber", "webrtc", ] @@ -3589,7 +3567,6 @@ version = "0.13.0" dependencies = [ "async-std", "bytes", - "env_logger 0.10.0", "futures", "futures_ringbuf", "pin-project", @@ -3598,6 +3575,7 @@ dependencies = [ "rw-stream-sink", "smallvec", "tracing", + "tracing-subscriber", "unsigned-varint", ] @@ -4018,7 +3996,6 @@ version = "0.1.0" dependencies = [ "async-std", "async-trait", - "env_logger 0.10.0", "futures", "libp2p", "tracing", @@ -4240,7 +4217,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" dependencies = [ - "env_logger 0.8.4", + "env_logger", "log", "rand 0.8.5", ] diff --git a/examples/browser-webrtc/Cargo.toml b/examples/browser-webrtc/Cargo.toml index 00c11413881..644c1eb3ce2 100644 --- a/examples/browser-webrtc/Cargo.toml +++ b/examples/browser-webrtc/Cargo.toml @@ -14,10 +14,10 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1.0.72" -env_logger = "0.10" futures = "0.3.28" rand = "0.8" tracing = "0.1.37" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] axum = "0.6.19" diff --git a/examples/browser-webrtc/src/main.rs b/examples/browser-webrtc/src/main.rs index 4d3ca3bfee7..8f9e03bc74b 100644 --- a/examples/browser-webrtc/src/main.rs +++ b/examples/browser-webrtc/src/main.rs @@ -20,13 +20,11 @@ use rand::thread_rng; use std::net::{Ipv4Addr, SocketAddr}; use std::time::Duration; use tower_http::cors::{Any, CorsLayer}; +use tracing_subscriber::EnvFilter; #[tokio::main] async fn main() -> anyhow::Result<()> { - env_logger::builder() - .parse_filters("browser_webrtc_example=debug,libp2p_webrtc=info,libp2p_ping=debug") - .parse_default_env() - .init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let id_keys = identity::Keypair::generate_ed25519(); let local_peer_id = id_keys.public().to_peer_id(); diff --git a/examples/dcutr/Cargo.toml b/examples/dcutr/Cargo.toml index 1b593ed550f..ae21a82da56 100644 --- a/examples/dcutr/Cargo.toml +++ b/examples/dcutr/Cargo.toml @@ -7,7 +7,6 @@ license = "MIT" [dependencies] clap = { version = "4.3.23", features = ["derive"] } -env_logger = "0.10.0" futures = "0.3.28" futures-timer = "3.0" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "dcutr", "identify", "macros", "noise", "ping", "quic", "relay", "rendezvous", "tcp", "tokio", "yamux"] } diff --git a/examples/dcutr/src/main.rs b/examples/dcutr/src/main.rs index 82e9b2c4b00..3a9cdb479e3 100644 --- a/examples/dcutr/src/main.rs +++ b/examples/dcutr/src/main.rs @@ -39,7 +39,6 @@ use libp2p::{ }; use std::error::Error; use std::str::FromStr; -use tracing::level_filters::LevelFilter; use tracing_subscriber::EnvFilter; #[derive(Debug, Parser)] @@ -80,11 +79,7 @@ impl FromStr for Mode { } fn main() -> Result<(), Box> { - let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::DEBUG.into()) - .from_env_lossy(); - - tracing_subscriber::fmt().with_env_filter(env_filter).init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let opts = Opts::parse(); diff --git a/examples/identify/Cargo.toml b/examples/identify/Cargo.toml index 0ed23978db3..45b99c40083 100644 --- a/examples/identify/Cargo.toml +++ b/examples/identify/Cargo.toml @@ -8,7 +8,6 @@ license = "MIT" [dependencies] async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" -env_logger = "0.10" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "dcutr", "identify", "macros", "noise", "ping", "relay", "rendezvous", "tcp", "tokio", "yamux"] } tracing = "0.1.37" diff --git a/examples/identify/src/main.rs b/examples/identify/src/main.rs index a9eeaf922b0..0cd99d1157d 100644 --- a/examples/identify/src/main.rs +++ b/examples/identify/src/main.rs @@ -28,15 +28,11 @@ use libp2p::{ tcp, yamux, PeerId, Transport, }; use std::error::Error; -use tracing_subscriber::{filter::LevelFilter, EnvFilter}; +use tracing_subscriber::EnvFilter; #[async_std::main] async fn main() -> Result<(), Box> { - let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::DEBUG.into()) - .from_env_lossy(); - - tracing_subscriber::fmt().with_env_filter(env_filter).init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); diff --git a/examples/ping/Cargo.toml b/examples/ping/Cargo.toml index b74292358c2..bd397667bbc 100644 --- a/examples/ping/Cargo.toml +++ b/examples/ping/Cargo.toml @@ -8,7 +8,6 @@ license = "MIT" [dependencies] async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" -env_logger = "0.10.0" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "macros", "noise", "ping", "tcp", "websocket", "yamux"] } tracing = "0.1.37" diff --git a/examples/ping/src/main.rs b/examples/ping/src/main.rs index dff0b25af97..8de55ffc6c5 100644 --- a/examples/ping/src/main.rs +++ b/examples/ping/src/main.rs @@ -29,16 +29,11 @@ use libp2p::{ }; use std::error::Error; use std::time::Duration; -use tracing::level_filters::LevelFilter; use tracing_subscriber::EnvFilter; #[async_std::main] async fn main() -> Result<(), Box> { - let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::DEBUG.into()) - .from_env_lossy(); - - tracing_subscriber::fmt().with_env_filter(env_filter).init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); diff --git a/interop-tests/Cargo.toml b/interop-tests/Cargo.toml index a6526aa92be..7ed2b6cc0b1 100644 --- a/interop-tests/Cargo.toml +++ b/interop-tests/Cargo.toml @@ -11,11 +11,11 @@ crate-type = ["cdylib", "rlib"] [dependencies] anyhow = "1" either = "1.9.0" -env_logger = "0.10.0" futures = "0.3.28" +rand = "0.8.5" serde = { version = "1", features = ["derive"] } tracing = "0.1.37" -rand = "0.8.5" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] axum = "0.6" diff --git a/interop-tests/src/arch.rs b/interop-tests/src/arch.rs index b30c3ad1e31..28e4a3cc969 100644 --- a/interop-tests/src/arch.rs +++ b/interop-tests/src/arch.rs @@ -18,7 +18,6 @@ pub(crate) mod native { use anyhow::{bail, Context, Result}; use either::Either; - use env_logger::{Env, Target}; use futures::future::BoxFuture; use futures::FutureExt; use libp2p::core::muxing::StreamMuxerBox; @@ -30,6 +29,7 @@ pub(crate) mod native { use libp2p_mplex as mplex; use libp2p_webrtc as webrtc; use redis::AsyncCommands; + use tracing_subscriber::EnvFilter; use crate::{from_env, Muxer, SecProtocol, Transport}; @@ -38,9 +38,7 @@ pub(crate) mod native { pub(crate) type Instant = std::time::Instant; pub(crate) fn init_logger() { - env_logger::Builder::from_env(Env::default().default_filter_or("info")) - .target(Target::Stdout) - .init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); } pub(crate) fn sleep(duration: Duration) -> BoxFuture<'static, ()> { diff --git a/libp2p/Cargo.toml b/libp2p/Cargo.toml index 6b11d7deec4..0df0cc82f8e 100644 --- a/libp2p/Cargo.toml +++ b/libp2p/Cargo.toml @@ -141,13 +141,12 @@ libp2p-websocket = { workspace = true, optional = true } [dev-dependencies] async-std = { version = "1.6.2", features = ["attributes"] } async-trait = "0.1" -either = "1.8.0" -env_logger = "0.10.0" clap = { version = "4.1.6", features = ["derive"] } -tokio = { version = "1.15", features = ["io-util", "io-std", "macros", "rt", "rt-multi-thread"] } - +either = "1.8.0" libp2p-noise = { workspace = true } libp2p-tcp = { workspace = true, features = ["tokio"] } +tokio = { version = "1.15", features = ["io-util", "io-std", "macros", "rt", "rt-multi-thread"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/libp2p/src/tutorials/ping.rs b/libp2p/src/tutorials/ping.rs index aedc149228e..8ced0a9f7ae 100644 --- a/libp2p/src/tutorials/ping.rs +++ b/libp2p/src/tutorials/ping.rs @@ -57,8 +57,8 @@ //! [dependencies] //! libp2p = { version = "0.50", features = ["tcp", "dns", "async-std", "noise", "yamux", "websocket", "ping", "macros"] } //! futures = "0.3.21" -//! env_logger = "0.10.0" //! async-std = { version = "1.12.0", features = ["attributes"] } +//! tracing-subscriber = { version = "0.3", features = ["env-filter"] } //! ``` //! //! ## Network identity @@ -172,16 +172,17 @@ //! removed the print of the local [`PeerId`](crate::PeerId) because every time a [`Swarm`] is //! created, it prints the local [`PeerId`](crate::PeerId) in the logs at the INFO level. In order //! to continue to see the local [`PeerId`](crate::PeerId) you must initialize the logger -//! (In our example, `env_logger` is used) +//! (In our example, `tracing_subscriber` is used) //! //! ```rust //! use libp2p::swarm::{NetworkBehaviour, SwarmBuilder}; //! use libp2p::{identity, ping, PeerId}; //! use std::error::Error; +//! use tracing_subscriber::EnvFilter; //! //! #[async_std::main] //! async fn main() -> Result<(), Box> { -//! env_logger::init(); +//! tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); //! let local_key = identity::Keypair::generate_ed25519(); //! let local_peer_id = PeerId::from(local_key.public()); //! @@ -261,10 +262,11 @@ //! use libp2p::{identity, ping, Multiaddr, PeerId}; //! use std::error::Error; //! use std::time::Duration; +//! use tracing_subscriber::EnvFilter; //! //! #[async_std::main] //! async fn main() -> Result<(), Box> { -//! env_logger::init(); +//! tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); //! let local_key = identity::Keypair::generate_ed25519(); //! let local_peer_id = PeerId::from(local_key.public()); //! @@ -304,10 +306,11 @@ //! use libp2p::{identity, ping, Multiaddr, PeerId}; //! use std::error::Error; //! use std::time::Duration; +//! use tracing_subscriber::EnvFilter; //! //! #[async_std::main] //! async fn main() -> Result<(), Box> { -//! env_logger::init(); +//! tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); //! let local_key = identity::Keypair::generate_ed25519(); //! let local_peer_id = PeerId::from(local_key.public()); //! diff --git a/misc/multistream-select/Cargo.toml b/misc/multistream-select/Cargo.toml index b9f83719818..b8dde78d641 100644 --- a/misc/multistream-select/Cargo.toml +++ b/misc/multistream-select/Cargo.toml @@ -20,11 +20,11 @@ unsigned-varint = "0.7" [dev-dependencies] async-std = { version = "1.6.2", features = ["attributes"] } -env_logger = "0.10" futures_ringbuf = "0.4.0" quickcheck = { workspace = true } rand = "0.8" rw-stream-sink = { workspace = true } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/misc/multistream-select/tests/dialer_select.rs b/misc/multistream-select/tests/dialer_select.rs index d1b276458c4..8e1ed2769b4 100644 --- a/misc/multistream-select/tests/dialer_select.rs +++ b/misc/multistream-select/tests/dialer_select.rs @@ -23,6 +23,7 @@ use futures::prelude::*; use multistream_select::{dialer_select_proto, listener_select_proto, NegotiationError, Version}; use std::time::Duration; +use tracing_subscriber::EnvFilter; #[test] fn select_proto_basic() { @@ -72,7 +73,7 @@ fn select_proto_basic() { /// Tests the expected behaviour of failed negotiations. #[test] fn negotiation_failed() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); async fn run( Test { diff --git a/misc/server/Cargo.toml b/misc/server/Cargo.toml index cc48ee0c930..21739fbed59 100644 --- a/misc/server/Cargo.toml +++ b/misc/server/Cargo.toml @@ -13,7 +13,6 @@ license = "MIT" [dependencies] base64 = "0.21" clap = { version = "4.3.12", features = ["derive"] } -env_logger = "0.10.0" futures = "0.3" futures-timer = "3" hyper = { version = "0.14", features = ["server", "tcp", "http1"] } @@ -24,4 +23,5 @@ serde_derive = "1.0.125" serde_json = "1.0" tokio = { version = "1", features = ["rt-multi-thread", "macros"] } tracing = "0.1.37" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } zeroize = "1" diff --git a/misc/server/src/main.rs b/misc/server/src/main.rs index 14d696cf0aa..7e6e90da1ed 100644 --- a/misc/server/src/main.rs +++ b/misc/server/src/main.rs @@ -25,6 +25,7 @@ use std::path::PathBuf; use std::str::FromStr; use std::task::Poll; use std::time::Duration; +use tracing_subscriber::EnvFilter; use zeroize::Zeroizing; mod behaviour; @@ -55,7 +56,7 @@ struct Opts { #[tokio::main] async fn main() -> Result<(), Box> { - env_logger::init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let opt = Opts::parse(); diff --git a/muxers/mplex/Cargo.toml b/muxers/mplex/Cargo.toml index 10581e99574..4ac35c533d9 100644 --- a/muxers/mplex/Cargo.toml +++ b/muxers/mplex/Cargo.toml @@ -26,12 +26,12 @@ unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } [dev-dependencies] async-std = { version = "1.7.0", features = ["attributes"] } criterion = "0.5" -env_logger = "0.10" futures = "0.3" libp2p-muxer-test-harness = { path = "../test-harness" } libp2p-plaintext = { workspace = true } libp2p-tcp = { workspace = true, features = ["async-io"] } quickcheck = { workspace = true } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } [[bench]] name = "split_send_size" diff --git a/muxers/mplex/benches/split_send_size.rs b/muxers/mplex/benches/split_send_size.rs index dfdc619afb1..2cc8754e73c 100644 --- a/muxers/mplex/benches/split_send_size.rs +++ b/muxers/mplex/benches/split_send_size.rs @@ -35,6 +35,7 @@ use libp2p_mplex as mplex; use libp2p_plaintext::PlainText2Config; use std::pin::Pin; use std::time::Duration; +use tracing_subscriber::EnvFilter; type BenchTransport = transport::Boxed<(PeerId, muxing::StreamMuxerBox)>; @@ -51,7 +52,7 @@ const BENCH_SIZES: [usize; 8] = [ ]; fn prepare(c: &mut Criterion) { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let payload: Vec = vec![1; 1024 * 1024]; diff --git a/muxers/mplex/src/io.rs b/muxers/mplex/src/io.rs index 0ba67f0acdc..c8c0f3786fd 100644 --- a/muxers/mplex/src/io.rs +++ b/muxers/mplex/src/io.rs @@ -1230,7 +1230,8 @@ mod tests { #[test] fn max_buffer_behaviour() { - let _ = env_logger::try_init(); + use tracing_subscriber::EnvFilter; + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); fn prop(cfg: MplexConfig, overflow: NonZeroU8) { let mut r_buf = BytesMut::new(); @@ -1365,7 +1366,8 @@ mod tests { #[test] fn close_on_error() { - let _ = env_logger::try_init(); + use tracing_subscriber::EnvFilter; + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); fn prop(cfg: MplexConfig, num_streams: NonZeroU8) { let num_streams = cmp::min(cfg.max_substreams, num_streams.get() as usize); diff --git a/protocols/autonat/Cargo.toml b/protocols/autonat/Cargo.toml index 813ad6abfac..ee7d16fa606 100644 --- a/protocols/autonat/Cargo.toml +++ b/protocols/autonat/Cargo.toml @@ -25,8 +25,8 @@ tracing = "0.1.37" [dev-dependencies] async-std = { version = "1.10", features = ["attributes"] } -env_logger = "0.10" libp2p-swarm-test = { path = "../../swarm-test" } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/protocols/dcutr/Cargo.toml b/protocols/dcutr/Cargo.toml index a8c10ef8909..6bbe6167e60 100644 --- a/protocols/dcutr/Cargo.toml +++ b/protocols/dcutr/Cargo.toml @@ -28,7 +28,6 @@ void = "1" [dev-dependencies] async-std = { version = "1.12.0", features = ["attributes"] } clap = { version = "4.3.23", features = ["derive"] } -env_logger = "0.10.0" libp2p-dns = { workspace = true, features = ["async-std"] } libp2p-identify = { workspace = true } libp2p-noise = { workspace = true } @@ -40,6 +39,7 @@ libp2p-swarm-test = { path = "../../swarm-test" } libp2p-tcp = { workspace = true, features = ["async-io"] } libp2p-yamux = { workspace = true } rand = "0.8" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/protocols/dcutr/tests/lib.rs b/protocols/dcutr/tests/lib.rs index 6888e5914a0..eb54ea7d0f3 100644 --- a/protocols/dcutr/tests/lib.rs +++ b/protocols/dcutr/tests/lib.rs @@ -29,10 +29,11 @@ use libp2p_relay as relay; use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent}; use libp2p_swarm_test::SwarmExt as _; use std::time::Duration; +use tracing_subscriber::EnvFilter; #[async_std::test] async fn connect() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let mut relay = build_relay(); let mut dst = build_client(); diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 50c10aa25e2..d7bfb7b97d4 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -44,13 +44,13 @@ prometheus-client = "0.21.2" [dev-dependencies] async-std = { version = "1.6.3", features = ["unstable"] } -env_logger = "0.10.0" hex = "0.4.2" libp2p-core = { workspace = true } libp2p-yamux = { workspace = true } libp2p-noise = { workspace = true } libp2p-swarm-test = { path = "../../swarm-test" } quickcheck = { workspace = true } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/protocols/gossipsub/src/behaviour/tests.rs b/protocols/gossipsub/src/behaviour/tests.rs index b2414fd7afc..8b7e433f17e 100644 --- a/protocols/gossipsub/src/behaviour/tests.rs +++ b/protocols/gossipsub/src/behaviour/tests.rs @@ -4665,7 +4665,8 @@ fn test_limit_number_of_message_ids_inside_ihave() { #[test] fn test_iwant_penalties() { - let _ = env_logger::try_init(); + use tracing_subscriber::EnvFilter; + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let config = ConfigBuilder::default() .iwant_followup_time(Duration::from_secs(4)) diff --git a/protocols/gossipsub/tests/smoke.rs b/protocols/gossipsub/tests/smoke.rs index 26db5ccbea5..a3681ac5421 100644 --- a/protocols/gossipsub/tests/smoke.rs +++ b/protocols/gossipsub/tests/smoke.rs @@ -28,7 +28,7 @@ use libp2p_swarm_test::SwarmExt as _; use quickcheck::{QuickCheck, TestResult}; use rand::{seq::SliceRandom, SeedableRng}; use std::{task::Poll, time::Duration}; - +use tracing_subscriber::EnvFilter; struct Graph { nodes: SelectAll>, } @@ -128,7 +128,7 @@ async fn build_node() -> Swarm { #[test] fn multi_hop_propagation() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); fn prop(num_nodes: u8, seed: u64) -> TestResult { if !(2..=50).contains(&num_nodes) { diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index ae5aa7bcc94..bb550b61ae7 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -28,9 +28,9 @@ either = "1.9.0" [dev-dependencies] async-std = { version = "1.6.2", features = ["attributes"] } -env_logger = "0.10" libp2p-swarm-test = { path = "../../swarm-test" } libp2p-swarm = { workspace = true, features = ["macros"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/protocols/identify/tests/smoke.rs b/protocols/identify/tests/smoke.rs index c1926b4125f..a9a7a94e189 100644 --- a/protocols/identify/tests/smoke.rs +++ b/protocols/identify/tests/smoke.rs @@ -3,10 +3,11 @@ use libp2p_identify as identify; use libp2p_swarm::{Swarm, SwarmEvent}; use libp2p_swarm_test::SwarmExt; use std::iter; +use tracing_subscriber::EnvFilter; #[async_std::test] async fn periodic_identify() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let mut swarm1 = Swarm::new_ephemeral(|identity| { identify::Behaviour::new( @@ -80,7 +81,7 @@ async fn periodic_identify() { #[async_std::test] async fn identify_push() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let mut swarm1 = Swarm::new_ephemeral(|identity| { identify::Behaviour::new(identify::Config::new("a".to_string(), identity.public())) @@ -130,7 +131,7 @@ async fn identify_push() { #[async_std::test] async fn discover_peer_after_disconnect() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let mut swarm1 = Swarm::new_ephemeral(|identity| { identify::Behaviour::new(identify::Config::new("a".to_string(), identity.public())) diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index 7ff0a40e6ec..cbbf4287968 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -36,7 +36,6 @@ tracing = "0.1.37" [dev-dependencies] async-std = { version = "1.12.0", features = ["attributes"] } -env_logger = "0.10.0" futures-timer = "3.0" libp2p-identify = { path = "../identify" } libp2p-noise = { workspace = true } @@ -44,6 +43,7 @@ libp2p-swarm = { path = "../../swarm", features = ["macros"] } libp2p-swarm-test = { path = "../../swarm-test" } libp2p-yamux = { workspace = true } quickcheck = { workspace = true } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } [features] serde = ["dep:serde", "bytes/serde"] diff --git a/protocols/kad/tests/client_mode.rs b/protocols/kad/tests/client_mode.rs index 30fd4d972a8..542a8b84c8e 100644 --- a/protocols/kad/tests/client_mode.rs +++ b/protocols/kad/tests/client_mode.rs @@ -4,10 +4,11 @@ use libp2p_kad::store::MemoryStore; use libp2p_kad::{Kademlia, KademliaConfig, KademliaEvent, Mode}; use libp2p_swarm::Swarm; use libp2p_swarm_test::SwarmExt; +use tracing_subscriber::EnvFilter; #[async_std::test] async fn server_gets_added_to_routing_table_by_client() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let mut client = Swarm::new_ephemeral(MyBehaviour::new); let mut server = Swarm::new_ephemeral(MyBehaviour::new); @@ -30,7 +31,7 @@ async fn server_gets_added_to_routing_table_by_client() { #[async_std::test] async fn two_servers_add_each_other_to_routing_table() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let mut server1 = Swarm::new_ephemeral(MyBehaviour::new); let mut server2 = Swarm::new_ephemeral(MyBehaviour::new); @@ -74,7 +75,7 @@ async fn two_servers_add_each_other_to_routing_table() { #[async_std::test] async fn adding_an_external_addresses_activates_server_mode_on_existing_connections() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let mut client = Swarm::new_ephemeral(MyBehaviour::new); let mut server = Swarm::new_ephemeral(MyBehaviour::new); @@ -113,7 +114,7 @@ async fn adding_an_external_addresses_activates_server_mode_on_existing_connecti #[async_std::test] async fn set_client_to_server_mode() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let mut client = Swarm::new_ephemeral(MyBehaviour::new); client.behaviour_mut().kad.set_mode(Some(Mode::Client)); diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index ca858c6e8c0..dfe5c617c76 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -32,13 +32,13 @@ async-io = ["dep:async-io", "if-watch/smol"] [dev-dependencies] async-std = { version = "1.9.0", features = ["attributes"] } -env_logger = "0.10.0" libp2p-noise = { workspace = true } libp2p-swarm = { workspace = true, features = ["tokio", "async-std"] } libp2p-tcp = { workspace = true, features = ["tokio", "async-io"] } libp2p-yamux = { workspace = true } tokio = { version = "1.32", default-features = false, features = ["macros", "rt", "rt-multi-thread", "time"] } libp2p-swarm-test = { path = "../../swarm-test" } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } [[test]] name = "use-async-std" diff --git a/protocols/mdns/tests/use-async-std.rs b/protocols/mdns/tests/use-async-std.rs index 6d45d92cdd9..c322f1c4baa 100644 --- a/protocols/mdns/tests/use-async-std.rs +++ b/protocols/mdns/tests/use-async-std.rs @@ -24,17 +24,18 @@ use libp2p_mdns::{async_io::Behaviour, Config}; use libp2p_swarm::{Swarm, SwarmEvent}; use libp2p_swarm_test::SwarmExt as _; use std::time::Duration; +use tracing_subscriber::EnvFilter; #[async_std::test] async fn test_discovery_async_std_ipv4() { - env_logger::try_init().ok(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); run_discovery_test(Config::default()).await } #[async_std::test] async fn test_discovery_async_std_ipv6() { - env_logger::try_init().ok(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let config = Config { enable_ipv6: true, @@ -45,7 +46,7 @@ async fn test_discovery_async_std_ipv6() { #[async_std::test] async fn test_expired_async_std() { - env_logger::try_init().ok(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let config = Config { ttl: Duration::from_secs(1), @@ -78,7 +79,7 @@ async fn test_expired_async_std() { #[async_std::test] async fn test_no_expiration_on_close_async_std() { - env_logger::try_init().ok(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let config = Config { ttl: Duration::from_secs(120), query_interval: Duration::from_secs(10), diff --git a/protocols/mdns/tests/use-tokio.rs b/protocols/mdns/tests/use-tokio.rs index 50d6be0c00f..f39ed1b6075 100644 --- a/protocols/mdns/tests/use-tokio.rs +++ b/protocols/mdns/tests/use-tokio.rs @@ -22,17 +22,18 @@ use libp2p_mdns::{tokio::Behaviour, Config, Event}; use libp2p_swarm::{Swarm, SwarmEvent}; use libp2p_swarm_test::SwarmExt as _; use std::time::Duration; +use tracing_subscriber::EnvFilter; #[tokio::test] async fn test_discovery_tokio_ipv4() { - env_logger::try_init().ok(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); run_discovery_test(Config::default()).await } #[tokio::test] async fn test_discovery_tokio_ipv6() { - env_logger::try_init().ok(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let config = Config { enable_ipv6: true, @@ -43,7 +44,7 @@ async fn test_discovery_tokio_ipv6() { #[tokio::test] async fn test_expired_tokio() { - env_logger::try_init().ok(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let config = Config { ttl: Duration::from_secs(1), diff --git a/protocols/perf/Cargo.toml b/protocols/perf/Cargo.toml index 8741e2b8c13..239bddc8006 100644 --- a/protocols/perf/Cargo.toml +++ b/protocols/perf/Cargo.toml @@ -14,7 +14,6 @@ categories = ["network-programming", "asynchronous"] anyhow = "1" async-trait = "0.1" clap = { version = "4.3.23", features = ["derive"] } -env_logger = "0.10.0" futures = "0.3.28" instant = "0.1.12" libp2p-core = { workspace = true } @@ -30,6 +29,7 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" tracing = "0.1.37" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } tokio = { version = "1.32.0", features = ["full"] } void = "1" diff --git a/protocols/perf/src/bin/perf.rs b/protocols/perf/src/bin/perf.rs index 840235fa43a..8ff0a280e0d 100644 --- a/protocols/perf/src/bin/perf.rs +++ b/protocols/perf/src/bin/perf.rs @@ -33,6 +33,7 @@ use libp2p_identity::PeerId; use libp2p_perf::{Run, RunDuration, RunParams}; use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent}; use serde::{Deserialize, Serialize}; +use tracing_subscriber::EnvFilter; #[derive(Debug, Parser)] #[clap(name = "libp2p perf client")] @@ -72,9 +73,7 @@ impl FromStr for Transport { #[tokio::main] async fn main() -> Result<()> { - env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")) - .format_timestamp_millis() - .init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let opts = Opts::parse(); match opts { diff --git a/protocols/perf/tests/lib.rs b/protocols/perf/tests/lib.rs index af5bc2c35a2..017a4617dfe 100644 --- a/protocols/perf/tests/lib.rs +++ b/protocols/perf/tests/lib.rs @@ -21,10 +21,11 @@ use libp2p_perf::{client, server, RunParams}; use libp2p_swarm::{Swarm, SwarmEvent}; use libp2p_swarm_test::SwarmExt; +use tracing_subscriber::EnvFilter; #[tokio::test] async fn perf() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let mut server = Swarm::new_ephemeral(|_| server::Behaviour::new()); let server_peer_id = *server.local_peer_id(); diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index 0e881d052e9..aa9c0a66d38 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -24,10 +24,10 @@ void = "1.0" [dev-dependencies] async-std = "1.6.2" -env_logger = "0.10.0" libp2p-swarm = { workspace = true, features = ["macros"] } libp2p-swarm-test = { path = "../../swarm-test" } quickcheck = { workspace = true } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index d230dfc7fef..d4e0c953e81 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -30,12 +30,12 @@ tracing = "0.1.37" void = "1" [dev-dependencies] -env_logger = "0.10.0" libp2p-ping = { workspace = true } libp2p-plaintext = { workspace = true } libp2p-swarm = { workspace = true, features = ["macros", "async-std"] } libp2p-yamux = { workspace = true } quickcheck = { workspace = true } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/protocols/relay/tests/lib.rs b/protocols/relay/tests/lib.rs index fa79ab67f4b..a9c5dca0221 100644 --- a/protocols/relay/tests/lib.rs +++ b/protocols/relay/tests/lib.rs @@ -36,10 +36,11 @@ use libp2p_plaintext::PlainText2Config; use libp2p_relay as relay; use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent}; use std::time::Duration; +use tracing_subscriber::EnvFilter; #[test] fn reservation() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let mut pool = LocalPool::new(); let relay_addr = Multiaddr::empty().with(Protocol::Memory(rand::random::())); @@ -80,7 +81,7 @@ fn reservation() { #[test] fn new_reservation_to_same_relay_replaces_old() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let mut pool = LocalPool::new(); let relay_addr = Multiaddr::empty().with(Protocol::Memory(rand::random::())); @@ -171,7 +172,7 @@ fn new_reservation_to_same_relay_replaces_old() { #[test] fn connect() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let mut pool = LocalPool::new(); let relay_addr = Multiaddr::empty().with(Protocol::Memory(rand::random::())); @@ -255,7 +256,7 @@ async fn connection_established_to( #[test] fn handle_dial_failure() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let mut pool = LocalPool::new(); let relay_addr = Multiaddr::empty().with(Protocol::Memory(rand::random::())); @@ -274,7 +275,7 @@ fn handle_dial_failure() { #[test] fn reuse_connection() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let mut pool = LocalPool::new(); let relay_addr = Multiaddr::empty().with(Protocol::Memory(rand::random::())); diff --git a/protocols/rendezvous/Cargo.toml b/protocols/rendezvous/Cargo.toml index 1ee7ac616f9..6cafb18fa91 100644 --- a/protocols/rendezvous/Cargo.toml +++ b/protocols/rendezvous/Cargo.toml @@ -29,16 +29,16 @@ tracing = "0.1.37" void = "1" [dev-dependencies] -env_logger = "0.10.0" libp2p-swarm = { workspace = true, features = ["macros", "tokio"] } libp2p-noise = { workspace = true } libp2p-ping = { workspace = true } libp2p-identify = { workspace = true } -libp2p-yamux = { workspace = true } +libp2p-swarm-test = { path = "../../swarm-test" } libp2p-tcp = { workspace = true, features = ["tokio"] } +libp2p-yamux = { workspace = true } rand = "0.8" tokio = { version = "1.32", features = [ "rt-multi-thread", "time", "macros", "sync", "process", "fs", "net" ] } -libp2p-swarm-test = { path = "../../swarm-test" } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/protocols/rendezvous/tests/rendezvous.rs b/protocols/rendezvous/tests/rendezvous.rs index 992876d1971..fc510b367f3 100644 --- a/protocols/rendezvous/tests/rendezvous.rs +++ b/protocols/rendezvous/tests/rendezvous.rs @@ -27,10 +27,11 @@ use libp2p_swarm::{DialError, Swarm, SwarmEvent}; use libp2p_swarm_test::SwarmExt; use std::convert::TryInto; use std::time::Duration; +use tracing_subscriber::EnvFilter; #[tokio::test] async fn given_successful_registration_then_successful_discovery() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let ([mut alice, mut bob], mut robert) = new_server_with_connected_clients(rendezvous::server::Config::default()).await; @@ -83,7 +84,7 @@ async fn given_successful_registration_then_successful_discovery() { #[tokio::test] async fn should_return_error_when_no_external_addresses() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let server = new_server(rendezvous::server::Config::default()).await; let mut client = Swarm::new_ephemeral(rendezvous::client::Behaviour::new); @@ -98,7 +99,7 @@ async fn should_return_error_when_no_external_addresses() { #[tokio::test] async fn given_successful_registration_then_refresh_ttl() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let ([mut alice, mut bob], mut robert) = new_server_with_connected_clients(rendezvous::server::Config::default()).await; @@ -164,7 +165,7 @@ async fn given_successful_registration_then_refresh_ttl() { #[tokio::test] async fn given_invalid_ttl_then_unsuccessful_registration() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let ([mut alice], mut robert) = new_server_with_connected_clients(rendezvous::server::Config::default()).await; @@ -191,7 +192,7 @@ async fn given_invalid_ttl_then_unsuccessful_registration() { #[tokio::test] async fn discover_allows_for_dial_by_peer_id() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let ([mut alice, mut bob], robert) = new_server_with_connected_clients(rendezvous::server::Config::default()).await; @@ -246,7 +247,7 @@ async fn discover_allows_for_dial_by_peer_id() { #[tokio::test] async fn eve_cannot_register() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let mut robert = new_server(rendezvous::server::Config::default()).await; let mut eve = new_impersonating_client().await; @@ -272,7 +273,7 @@ async fn eve_cannot_register() { // test if charlie can operate as client and server simultaneously #[tokio::test] async fn can_combine_client_and_server() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let ([mut alice], mut robert) = new_server_with_connected_clients(rendezvous::server::Config::default()).await; @@ -308,7 +309,7 @@ async fn can_combine_client_and_server() { #[tokio::test] async fn registration_on_clients_expire() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let ([mut alice, mut bob], robert) = new_server_with_connected_clients(rendezvous::server::Config::default().with_min_ttl(1)) diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index 7bf7ab142c2..fb31e107231 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -31,7 +31,6 @@ cbor = ["dep:serde", "dep:cbor4ii", "libp2p-swarm/macros"] [dev-dependencies] async-std = { version = "1.6.2", features = ["attributes"] } -env_logger = "0.10.0" libp2p-noise = { workspace = true } libp2p-tcp = { workspace = true, features = ["async-io"] } libp2p-yamux = { workspace = true } @@ -39,6 +38,7 @@ rand = "0.8" libp2p-swarm-test = { path = "../../swarm-test" } futures_ringbuf = "0.4.0" serde = { version = "1.0", features = ["derive"]} +tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/protocols/request-response/tests/ping.rs b/protocols/request-response/tests/ping.rs index e0424488f48..508315637ff 100644 --- a/protocols/request-response/tests/ping.rs +++ b/protocols/request-response/tests/ping.rs @@ -29,11 +29,12 @@ use libp2p_swarm_test::SwarmExt; use rand::{self, Rng}; use serde::{Deserialize, Serialize}; use std::iter; +use tracing_subscriber::EnvFilter; #[async_std::test] #[cfg(feature = "cbor")] async fn is_response_outbound() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let ping = Ping("ping".to_string().into_bytes()); let offline_peer = PeerId::random(); diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 1ea9b7defe5..75584167ea3 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -41,7 +41,6 @@ wasm-bindgen = ["dep:wasm-bindgen-futures", "dep:getrandom"] [dev-dependencies] async-std = { version = "1.6.2", features = ["attributes"] } either = "1.9.0" -env_logger = "0.10" futures = "0.3.28" libp2p-identify = { path = "../protocols/identify" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. libp2p-identity = { workspace = true, features = ["ed25519"] } @@ -56,6 +55,7 @@ void = "1" once_cell = "1.18.0" trybuild = "1.0.85" tokio = { version = "1.29.1", features = ["time", "rt", "macros"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } [[test]] name = "swarm_derive" diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 0b5b3035ff3..51f713ae916 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -2374,7 +2374,7 @@ mod tests { #[test] fn aborting_pending_connection_surfaces_error() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init(); let mut dialer = new_test_swarm().build(); let mut listener = new_test_swarm().build(); diff --git a/transports/dns/Cargo.toml b/transports/dns/Cargo.toml index 816ef7abd89..7d51e726f27 100644 --- a/transports/dns/Cargo.toml +++ b/transports/dns/Cargo.toml @@ -22,9 +22,9 @@ tracing = "0.1.37" trust-dns-resolver = { version = "0.23", default-features = false, features = ["system-config"] } [dev-dependencies] -env_logger = "0.10" tokio-crate = { package = "tokio", version = "1.0", default-features = false, features = ["rt", "time"] } async-std-crate = { package = "async-std", version = "1.6" } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } [features] async-std = ["async-std-resolver"] diff --git a/transports/dns/src/lib.rs b/transports/dns/src/lib.rs index ed120ef21d5..8296b08811c 100644 --- a/transports/dns/src/lib.rs +++ b/transports/dns/src/lib.rs @@ -631,7 +631,8 @@ mod tests { #[test] fn basic_resolve() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init(); + #[derive(Clone)] struct CustomTransport; diff --git a/transports/noise/Cargo.toml b/transports/noise/Cargo.toml index 051cb93f2c4..78fe854ad61 100644 --- a/transports/noise/Cargo.toml +++ b/transports/noise/Cargo.toml @@ -33,9 +33,9 @@ snow = { version = "0.9.2", features = ["ring-resolver"], default-features = fal snow = { version = "0.9.2", features = ["default-resolver"], default-features = false } [dev-dependencies] -env_logger = "0.10.0" futures_ringbuf = "0.4.0" quickcheck = { workspace = true } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/transports/noise/tests/smoke.rs b/transports/noise/tests/smoke.rs index f7f0a32ebcf..01166cf7e3b 100644 --- a/transports/noise/tests/smoke.rs +++ b/transports/noise/tests/smoke.rs @@ -24,6 +24,7 @@ use libp2p_core::{upgrade, InboundUpgrade, OutboundUpgrade}; use libp2p_identity as identity; use libp2p_noise as noise; use quickcheck::*; +use tracing_subscriber::EnvFilter; use std::{convert::TryInto, io}; #[allow(dead_code)] @@ -39,7 +40,7 @@ fn core_upgrade_compat() { #[test] fn xx() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); fn prop(mut messages: Vec) -> bool { messages.truncate(5); let server_id = identity::Keypair::generate_ed25519(); diff --git a/transports/plaintext/Cargo.toml b/transports/plaintext/Cargo.toml index 8295d9c4561..982ffcf34d0 100644 --- a/transports/plaintext/Cargo.toml +++ b/transports/plaintext/Cargo.toml @@ -21,11 +21,11 @@ tracing = "0.1.37" unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } [dev-dependencies] -env_logger = "0.10.0" libp2p-identity = { workspace = true, features = ["ed25519"] } quickcheck = { workspace = true } rand = "0.8" futures_ringbuf = "0.4.0" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/transports/plaintext/tests/smoke.rs b/transports/plaintext/tests/smoke.rs index fb51b1991c9..cf9a4d95490 100644 --- a/transports/plaintext/tests/smoke.rs +++ b/transports/plaintext/tests/smoke.rs @@ -23,10 +23,11 @@ use libp2p_core::InboundUpgrade; use libp2p_identity as identity; use libp2p_plaintext::PlainText2Config; use quickcheck::QuickCheck; +use tracing_subscriber::EnvFilter; #[test] fn variable_msg_length() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); fn prop(msg: Vec) { let msg_to_send = msg.clone(); diff --git a/transports/quic/Cargo.toml b/transports/quic/Cargo.toml index 8f9312a2fda..95a3813208e 100644 --- a/transports/quic/Cargo.toml +++ b/transports/quic/Cargo.toml @@ -39,13 +39,13 @@ rustc-args = ["--cfg", "docsrs"] [dev-dependencies] async-std = { version = "1.12.0", features = ["attributes"] } -env_logger = "0.10.0" libp2p-muxer-test-harness = { path = "../../muxers/test-harness" } libp2p-noise = { workspace = true } libp2p-tcp = { workspace = true, features = ["async-io"] } libp2p-yamux = { workspace = true } quickcheck = "1" tokio = { version = "1.32.0", features = ["macros", "rt-multi-thread", "time"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } [[test]] name = "stream_compliance" diff --git a/transports/quic/tests/smoke.rs b/transports/quic/tests/smoke.rs index 3f47271ae6b..d93f7a021c3 100644 --- a/transports/quic/tests/smoke.rs +++ b/transports/quic/tests/smoke.rs @@ -26,6 +26,7 @@ use std::{ pin::Pin, sync::{Arc, Mutex}, }; +use tracing_subscriber::EnvFilter; #[cfg(feature = "tokio")] #[tokio::test] @@ -42,7 +43,7 @@ async fn async_std_smoke() { #[cfg(feature = "async-std")] #[async_std::test] async fn dial_failure() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let mut a = create_default_transport::().1; let mut b = create_default_transport::().1; @@ -60,7 +61,7 @@ async fn dial_failure() { #[cfg(feature = "tokio")] #[tokio::test] async fn endpoint_reuse() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let (_, mut a_transport) = create_default_transport::(); let (_, mut b_transport) = create_default_transport::(); @@ -85,7 +86,7 @@ async fn endpoint_reuse() { #[cfg(feature = "async-std")] #[async_std::test] async fn ipv4_dial_ipv6() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let (a_peer_id, mut a_transport) = create_default_transport::(); let (b_peer_id, mut b_transport) = create_default_transport::(); @@ -103,7 +104,7 @@ async fn ipv4_dial_ipv6() { #[cfg(feature = "async-std")] #[async_std::test] async fn wrapped_with_delay() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); struct DialDelay(Arc>>); @@ -271,7 +272,7 @@ async fn tcp_and_quic() { #[cfg(feature = "async-std")] #[test] fn concurrent_connections_and_streams_async_std() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); quickcheck::QuickCheck::new() .min_tests_passed(1) @@ -282,7 +283,7 @@ fn concurrent_connections_and_streams_async_std() { #[cfg(feature = "tokio")] #[test] fn concurrent_connections_and_streams_tokio() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let rt = tokio::runtime::Runtime::new().unwrap(); let _guard = rt.enter(); @@ -299,7 +300,7 @@ async fn draft_29_support() { use futures::{future::poll_fn, select}; use libp2p_core::transport::TransportError; - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let (_, mut a_transport) = create_transport::(|cfg| cfg.support_draft_29 = true); @@ -360,7 +361,7 @@ async fn draft_29_support() { #[cfg(feature = "async-std")] #[async_std::test] async fn backpressure() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let max_stream_data = quic::Config::new(&generate_tls_keypair()).max_stream_data; let (mut stream_a, mut stream_b) = build_streams::().await; @@ -384,7 +385,7 @@ async fn backpressure() { #[cfg(feature = "async-std")] #[async_std::test] async fn read_after_peer_dropped_stream() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let (mut stream_a, mut stream_b) = build_streams::().await; let data = vec![0; 10]; @@ -404,7 +405,7 @@ async fn read_after_peer_dropped_stream() { #[async_std::test] #[should_panic] async fn write_after_peer_dropped_stream() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let (stream_a, mut stream_b) = build_streams::().await; drop(stream_a); futures_timer::Delay::new(Duration::from_millis(1)).await; @@ -458,7 +459,7 @@ async fn test_local_listener_reuse() { } async fn smoke() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let (a_peer_id, mut a_transport) = create_default_transport::

(); let (b_peer_id, mut b_transport) = create_default_transport::

(); diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index 6c6ae012eb4..78307e40673 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -29,7 +29,7 @@ async-io = ["dep:async-io", "if-watch/smol"] [dev-dependencies] async-std = { version = "1.6.5", features = ["attributes"] } tokio = { version = "1.32.0", default-features = false, features = ["full"] } -env_logger = "0.10.0" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/transports/tcp/src/lib.rs b/transports/tcp/src/lib.rs index c4384f8b400..3e303b17914 100644 --- a/transports/tcp/src/lib.rs +++ b/transports/tcp/src/lib.rs @@ -904,7 +904,7 @@ mod tests { #[test] fn communicating_between_dialer_and_listener() { - env_logger::try_init().ok(); + tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init(); async fn listener(addr: Multiaddr, mut ready_tx: mpsc::Sender) { let mut tcp = Transport::::default().boxed(); @@ -973,7 +973,7 @@ mod tests { #[test] fn wildcard_expansion() { - env_logger::try_init().ok(); + tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init(); async fn listener(addr: Multiaddr, mut ready_tx: mpsc::Sender) { let mut tcp = Transport::::default().boxed(); @@ -1042,7 +1042,7 @@ mod tests { #[test] fn port_reuse_dialing() { - env_logger::try_init().ok(); + tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init(); async fn listener( addr: Multiaddr, @@ -1149,7 +1149,7 @@ mod tests { #[test] fn port_reuse_listening() { - env_logger::try_init().ok(); + tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init(); async fn listen_twice(addr: Multiaddr) { let mut tcp = Transport::::new(Config::new().port_reuse(true)); @@ -1203,7 +1203,7 @@ mod tests { #[test] fn listen_port_0() { - env_logger::try_init().ok(); + tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init(); async fn listen(addr: Multiaddr) -> Multiaddr { let mut tcp = Transport::::default().boxed(); @@ -1238,7 +1238,7 @@ mod tests { #[test] fn listen_invalid_addr() { - env_logger::try_init().ok(); + tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init(); fn test(addr: Multiaddr) { #[cfg(feature = "async-io")] @@ -1308,7 +1308,7 @@ mod tests { #[test] fn test_remove_listener() { - env_logger::try_init().ok(); + tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init(); async fn cycle_listeners() -> bool { let mut tcp = Transport::::default().boxed(); diff --git a/transports/webrtc/Cargo.toml b/transports/webrtc/Cargo.toml index e61f90733d5..80c52fc8e81 100644 --- a/transports/webrtc/Cargo.toml +++ b/transports/webrtc/Cargo.toml @@ -38,9 +38,10 @@ tokio = ["dep:tokio", "dep:tokio-util", "dep:webrtc", "if-watch/tokio"] pem = ["webrtc?/pem"] [dev-dependencies] -env_logger = "0.10" -tokio = { version = "1.32", features = ["full"] } quickcheck = "1.0.3" +tokio = { version = "1.32", features = ["full"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } + [[test]] name = "smoke" diff --git a/transports/webrtc/tests/smoke.rs b/transports/webrtc/tests/smoke.rs index f6a5c8116ef..c87cd88621b 100644 --- a/transports/webrtc/tests/smoke.rs +++ b/transports/webrtc/tests/smoke.rs @@ -28,6 +28,7 @@ use libp2p_core::{Multiaddr, Transport}; use libp2p_identity::PeerId; use libp2p_webrtc as webrtc; use rand::{thread_rng, RngCore}; +use tracing_subscriber::EnvFilter; use std::future::Future; use std::num::NonZeroU8; use std::pin::Pin; @@ -36,7 +37,7 @@ use std::time::Duration; #[tokio::test] async fn smoke() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let (a_peer_id, mut a_transport) = create_transport(); let (b_peer_id, mut b_transport) = create_transport(); @@ -53,7 +54,7 @@ async fn smoke() { // Note: This test should likely be ported to the muxer compliance test suite. #[test] fn concurrent_connections_and_streams_tokio() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); let rt = tokio::runtime::Runtime::new().unwrap(); let _guard = rt.enter(); From 540f1290409183f78ff8cbbda1edc067ed2bce5f Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Sun, 1 Oct 2023 13:51:26 +0300 Subject: [PATCH 065/105] fmt --- examples/autonat/src/bin/autonat_client.rs | 4 +- examples/autonat/src/bin/autonat_server.rs | 4 +- examples/browser-webrtc/src/main.rs | 4 +- examples/chat/src/main.rs | 2 +- examples/dcutr/src/main.rs | 4 +- examples/identify/src/main.rs | 4 +- examples/ping/src/main.rs | 4 +- interop-tests/src/arch.rs | 4 +- .../multistream-select/tests/dialer_select.rs | 4 +- misc/server/src/main.rs | 4 +- muxers/mplex/benches/split_send_size.rs | 4 +- muxers/mplex/src/io.rs | 8 +++- protocols/dcutr/tests/lib.rs | 4 +- protocols/gossipsub/src/behaviour/tests.rs | 4 +- protocols/gossipsub/tests/smoke.rs | 4 +- protocols/identify/tests/smoke.rs | 12 +++-- protocols/kad/tests/client_mode.rs | 16 +++++-- protocols/mdns/tests/use-async-std.rs | 16 +++++-- protocols/mdns/tests/use-tokio.rs | 12 +++-- protocols/perf/src/bin/perf.rs | 4 +- protocols/perf/tests/lib.rs | 4 +- protocols/relay/tests/lib.rs | 20 ++++++--- protocols/rendezvous/tests/rendezvous.rs | 32 ++++++++++---- protocols/request-response/tests/ping.rs | 4 +- swarm/src/lib.rs | 4 +- transports/dns/src/lib.rs | 5 ++- transports/noise/tests/smoke.rs | 6 ++- transports/plaintext/tests/smoke.rs | 4 +- transports/quic/tests/smoke.rs | 44 ++++++++++++++----- transports/tcp/src/lib.rs | 28 +++++++++--- transports/webrtc/tests/smoke.rs | 10 +++-- 31 files changed, 210 insertions(+), 73 deletions(-) diff --git a/examples/autonat/src/bin/autonat_client.rs b/examples/autonat/src/bin/autonat_client.rs index 04b1da15a2c..1c5bb702300 100644 --- a/examples/autonat/src/bin/autonat_client.rs +++ b/examples/autonat/src/bin/autonat_client.rs @@ -46,7 +46,9 @@ struct Opt { #[async_std::main] async fn main() -> Result<(), Box> { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let opt = Opt::parse(); diff --git a/examples/autonat/src/bin/autonat_server.rs b/examples/autonat/src/bin/autonat_server.rs index f77d6945669..db81fa4ab5b 100644 --- a/examples/autonat/src/bin/autonat_server.rs +++ b/examples/autonat/src/bin/autonat_server.rs @@ -38,7 +38,9 @@ struct Opt { #[async_std::main] async fn main() -> Result<(), Box> { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let opt = Opt::parse(); diff --git a/examples/browser-webrtc/src/main.rs b/examples/browser-webrtc/src/main.rs index 8f9e03bc74b..711606b9bf0 100644 --- a/examples/browser-webrtc/src/main.rs +++ b/examples/browser-webrtc/src/main.rs @@ -24,7 +24,9 @@ use tracing_subscriber::EnvFilter; #[tokio::main] async fn main() -> anyhow::Result<()> { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let id_keys = identity::Keypair::generate_ed25519(); let local_peer_id = id_keys.public().to_peer_id(); diff --git a/examples/chat/src/main.rs b/examples/chat/src/main.rs index 81bb96d837c..e4040eaa05c 100644 --- a/examples/chat/src/main.rs +++ b/examples/chat/src/main.rs @@ -32,8 +32,8 @@ use std::collections::hash_map::DefaultHasher; use std::error::Error; use std::hash::{Hash, Hasher}; use std::time::Duration; -use tracing_subscriber::{filter::LevelFilter, EnvFilter}; use tokio::{io, io::AsyncBufReadExt, select}; +use tracing_subscriber::{filter::LevelFilter, EnvFilter}; // We create a custom network behaviour that combines Gossipsub and Mdns. #[derive(NetworkBehaviour)] diff --git a/examples/dcutr/src/main.rs b/examples/dcutr/src/main.rs index 3a9cdb479e3..6706bd0a05d 100644 --- a/examples/dcutr/src/main.rs +++ b/examples/dcutr/src/main.rs @@ -79,7 +79,9 @@ impl FromStr for Mode { } fn main() -> Result<(), Box> { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let opts = Opts::parse(); diff --git a/examples/identify/src/main.rs b/examples/identify/src/main.rs index 0cd99d1157d..11b5e9914c1 100644 --- a/examples/identify/src/main.rs +++ b/examples/identify/src/main.rs @@ -32,7 +32,9 @@ use tracing_subscriber::EnvFilter; #[async_std::main] async fn main() -> Result<(), Box> { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); diff --git a/examples/ping/src/main.rs b/examples/ping/src/main.rs index 8de55ffc6c5..d714f346735 100644 --- a/examples/ping/src/main.rs +++ b/examples/ping/src/main.rs @@ -33,7 +33,9 @@ use tracing_subscriber::EnvFilter; #[async_std::main] async fn main() -> Result<(), Box> { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); diff --git a/interop-tests/src/arch.rs b/interop-tests/src/arch.rs index 28e4a3cc969..207bf9afe3f 100644 --- a/interop-tests/src/arch.rs +++ b/interop-tests/src/arch.rs @@ -38,7 +38,9 @@ pub(crate) mod native { pub(crate) type Instant = std::time::Instant; pub(crate) fn init_logger() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); } pub(crate) fn sleep(duration: Duration) -> BoxFuture<'static, ()> { diff --git a/misc/multistream-select/tests/dialer_select.rs b/misc/multistream-select/tests/dialer_select.rs index 8e1ed2769b4..2bdc390bc00 100644 --- a/misc/multistream-select/tests/dialer_select.rs +++ b/misc/multistream-select/tests/dialer_select.rs @@ -73,7 +73,9 @@ fn select_proto_basic() { /// Tests the expected behaviour of failed negotiations. #[test] fn negotiation_failed() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); async fn run( Test { diff --git a/misc/server/src/main.rs b/misc/server/src/main.rs index 7e6e90da1ed..af8fd6d1a19 100644 --- a/misc/server/src/main.rs +++ b/misc/server/src/main.rs @@ -56,7 +56,9 @@ struct Opts { #[tokio::main] async fn main() -> Result<(), Box> { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let opt = Opts::parse(); diff --git a/muxers/mplex/benches/split_send_size.rs b/muxers/mplex/benches/split_send_size.rs index 2cc8754e73c..bab6497e291 100644 --- a/muxers/mplex/benches/split_send_size.rs +++ b/muxers/mplex/benches/split_send_size.rs @@ -52,7 +52,9 @@ const BENCH_SIZES: [usize; 8] = [ ]; fn prepare(c: &mut Criterion) { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let payload: Vec = vec![1; 1024 * 1024]; diff --git a/muxers/mplex/src/io.rs b/muxers/mplex/src/io.rs index c8c0f3786fd..29259484970 100644 --- a/muxers/mplex/src/io.rs +++ b/muxers/mplex/src/io.rs @@ -1231,7 +1231,9 @@ mod tests { #[test] fn max_buffer_behaviour() { use tracing_subscriber::EnvFilter; - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); fn prop(cfg: MplexConfig, overflow: NonZeroU8) { let mut r_buf = BytesMut::new(); @@ -1367,7 +1369,9 @@ mod tests { #[test] fn close_on_error() { use tracing_subscriber::EnvFilter; - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); fn prop(cfg: MplexConfig, num_streams: NonZeroU8) { let num_streams = cmp::min(cfg.max_substreams, num_streams.get() as usize); diff --git a/protocols/dcutr/tests/lib.rs b/protocols/dcutr/tests/lib.rs index eb54ea7d0f3..14aca6a3c25 100644 --- a/protocols/dcutr/tests/lib.rs +++ b/protocols/dcutr/tests/lib.rs @@ -33,7 +33,9 @@ use tracing_subscriber::EnvFilter; #[async_std::test] async fn connect() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let mut relay = build_relay(); let mut dst = build_client(); diff --git a/protocols/gossipsub/src/behaviour/tests.rs b/protocols/gossipsub/src/behaviour/tests.rs index 8b7e433f17e..c03718a1651 100644 --- a/protocols/gossipsub/src/behaviour/tests.rs +++ b/protocols/gossipsub/src/behaviour/tests.rs @@ -4666,7 +4666,9 @@ fn test_limit_number_of_message_ids_inside_ihave() { #[test] fn test_iwant_penalties() { use tracing_subscriber::EnvFilter; - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let config = ConfigBuilder::default() .iwant_followup_time(Duration::from_secs(4)) diff --git a/protocols/gossipsub/tests/smoke.rs b/protocols/gossipsub/tests/smoke.rs index a3681ac5421..715eeb24154 100644 --- a/protocols/gossipsub/tests/smoke.rs +++ b/protocols/gossipsub/tests/smoke.rs @@ -128,7 +128,9 @@ async fn build_node() -> Swarm { #[test] fn multi_hop_propagation() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); fn prop(num_nodes: u8, seed: u64) -> TestResult { if !(2..=50).contains(&num_nodes) { diff --git a/protocols/identify/tests/smoke.rs b/protocols/identify/tests/smoke.rs index a9a7a94e189..721653359d7 100644 --- a/protocols/identify/tests/smoke.rs +++ b/protocols/identify/tests/smoke.rs @@ -7,7 +7,9 @@ use tracing_subscriber::EnvFilter; #[async_std::test] async fn periodic_identify() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let mut swarm1 = Swarm::new_ephemeral(|identity| { identify::Behaviour::new( @@ -81,7 +83,9 @@ async fn periodic_identify() { #[async_std::test] async fn identify_push() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let mut swarm1 = Swarm::new_ephemeral(|identity| { identify::Behaviour::new(identify::Config::new("a".to_string(), identity.public())) @@ -131,7 +135,9 @@ async fn identify_push() { #[async_std::test] async fn discover_peer_after_disconnect() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let mut swarm1 = Swarm::new_ephemeral(|identity| { identify::Behaviour::new(identify::Config::new("a".to_string(), identity.public())) diff --git a/protocols/kad/tests/client_mode.rs b/protocols/kad/tests/client_mode.rs index 542a8b84c8e..4d021ae29d7 100644 --- a/protocols/kad/tests/client_mode.rs +++ b/protocols/kad/tests/client_mode.rs @@ -8,7 +8,9 @@ use tracing_subscriber::EnvFilter; #[async_std::test] async fn server_gets_added_to_routing_table_by_client() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let mut client = Swarm::new_ephemeral(MyBehaviour::new); let mut server = Swarm::new_ephemeral(MyBehaviour::new); @@ -31,7 +33,9 @@ async fn server_gets_added_to_routing_table_by_client() { #[async_std::test] async fn two_servers_add_each_other_to_routing_table() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let mut server1 = Swarm::new_ephemeral(MyBehaviour::new); let mut server2 = Swarm::new_ephemeral(MyBehaviour::new); @@ -75,7 +79,9 @@ async fn two_servers_add_each_other_to_routing_table() { #[async_std::test] async fn adding_an_external_addresses_activates_server_mode_on_existing_connections() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let mut client = Swarm::new_ephemeral(MyBehaviour::new); let mut server = Swarm::new_ephemeral(MyBehaviour::new); @@ -114,7 +120,9 @@ async fn adding_an_external_addresses_activates_server_mode_on_existing_connecti #[async_std::test] async fn set_client_to_server_mode() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let mut client = Swarm::new_ephemeral(MyBehaviour::new); client.behaviour_mut().kad.set_mode(Some(Mode::Client)); diff --git a/protocols/mdns/tests/use-async-std.rs b/protocols/mdns/tests/use-async-std.rs index c322f1c4baa..44afafe1a56 100644 --- a/protocols/mdns/tests/use-async-std.rs +++ b/protocols/mdns/tests/use-async-std.rs @@ -28,14 +28,18 @@ use tracing_subscriber::EnvFilter; #[async_std::test] async fn test_discovery_async_std_ipv4() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); run_discovery_test(Config::default()).await } #[async_std::test] async fn test_discovery_async_std_ipv6() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let config = Config { enable_ipv6: true, @@ -46,7 +50,9 @@ async fn test_discovery_async_std_ipv6() { #[async_std::test] async fn test_expired_async_std() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let config = Config { ttl: Duration::from_secs(1), @@ -79,7 +85,9 @@ async fn test_expired_async_std() { #[async_std::test] async fn test_no_expiration_on_close_async_std() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let config = Config { ttl: Duration::from_secs(120), query_interval: Duration::from_secs(10), diff --git a/protocols/mdns/tests/use-tokio.rs b/protocols/mdns/tests/use-tokio.rs index f39ed1b6075..cb7b1e2c6d8 100644 --- a/protocols/mdns/tests/use-tokio.rs +++ b/protocols/mdns/tests/use-tokio.rs @@ -26,14 +26,18 @@ use tracing_subscriber::EnvFilter; #[tokio::test] async fn test_discovery_tokio_ipv4() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); run_discovery_test(Config::default()).await } #[tokio::test] async fn test_discovery_tokio_ipv6() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let config = Config { enable_ipv6: true, @@ -44,7 +48,9 @@ async fn test_discovery_tokio_ipv6() { #[tokio::test] async fn test_expired_tokio() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let config = Config { ttl: Duration::from_secs(1), diff --git a/protocols/perf/src/bin/perf.rs b/protocols/perf/src/bin/perf.rs index 8ff0a280e0d..9ec80176bbb 100644 --- a/protocols/perf/src/bin/perf.rs +++ b/protocols/perf/src/bin/perf.rs @@ -73,7 +73,9 @@ impl FromStr for Transport { #[tokio::main] async fn main() -> Result<()> { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let opts = Opts::parse(); match opts { diff --git a/protocols/perf/tests/lib.rs b/protocols/perf/tests/lib.rs index 017a4617dfe..b3af382febb 100644 --- a/protocols/perf/tests/lib.rs +++ b/protocols/perf/tests/lib.rs @@ -25,7 +25,9 @@ use tracing_subscriber::EnvFilter; #[tokio::test] async fn perf() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let mut server = Swarm::new_ephemeral(|_| server::Behaviour::new()); let server_peer_id = *server.local_peer_id(); diff --git a/protocols/relay/tests/lib.rs b/protocols/relay/tests/lib.rs index a9c5dca0221..18d85d3cab4 100644 --- a/protocols/relay/tests/lib.rs +++ b/protocols/relay/tests/lib.rs @@ -40,7 +40,9 @@ use tracing_subscriber::EnvFilter; #[test] fn reservation() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let mut pool = LocalPool::new(); let relay_addr = Multiaddr::empty().with(Protocol::Memory(rand::random::())); @@ -81,7 +83,9 @@ fn reservation() { #[test] fn new_reservation_to_same_relay_replaces_old() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let mut pool = LocalPool::new(); let relay_addr = Multiaddr::empty().with(Protocol::Memory(rand::random::())); @@ -172,7 +176,9 @@ fn new_reservation_to_same_relay_replaces_old() { #[test] fn connect() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let mut pool = LocalPool::new(); let relay_addr = Multiaddr::empty().with(Protocol::Memory(rand::random::())); @@ -256,7 +262,9 @@ async fn connection_established_to( #[test] fn handle_dial_failure() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let mut pool = LocalPool::new(); let relay_addr = Multiaddr::empty().with(Protocol::Memory(rand::random::())); @@ -275,7 +283,9 @@ fn handle_dial_failure() { #[test] fn reuse_connection() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let mut pool = LocalPool::new(); let relay_addr = Multiaddr::empty().with(Protocol::Memory(rand::random::())); diff --git a/protocols/rendezvous/tests/rendezvous.rs b/protocols/rendezvous/tests/rendezvous.rs index fc510b367f3..9a158ecd70d 100644 --- a/protocols/rendezvous/tests/rendezvous.rs +++ b/protocols/rendezvous/tests/rendezvous.rs @@ -31,7 +31,9 @@ use tracing_subscriber::EnvFilter; #[tokio::test] async fn given_successful_registration_then_successful_discovery() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let ([mut alice, mut bob], mut robert) = new_server_with_connected_clients(rendezvous::server::Config::default()).await; @@ -84,7 +86,9 @@ async fn given_successful_registration_then_successful_discovery() { #[tokio::test] async fn should_return_error_when_no_external_addresses() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let server = new_server(rendezvous::server::Config::default()).await; let mut client = Swarm::new_ephemeral(rendezvous::client::Behaviour::new); @@ -99,7 +103,9 @@ async fn should_return_error_when_no_external_addresses() { #[tokio::test] async fn given_successful_registration_then_refresh_ttl() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let ([mut alice, mut bob], mut robert) = new_server_with_connected_clients(rendezvous::server::Config::default()).await; @@ -165,7 +171,9 @@ async fn given_successful_registration_then_refresh_ttl() { #[tokio::test] async fn given_invalid_ttl_then_unsuccessful_registration() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let ([mut alice], mut robert) = new_server_with_connected_clients(rendezvous::server::Config::default()).await; @@ -192,7 +200,9 @@ async fn given_invalid_ttl_then_unsuccessful_registration() { #[tokio::test] async fn discover_allows_for_dial_by_peer_id() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let ([mut alice, mut bob], robert) = new_server_with_connected_clients(rendezvous::server::Config::default()).await; @@ -247,7 +257,9 @@ async fn discover_allows_for_dial_by_peer_id() { #[tokio::test] async fn eve_cannot_register() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let mut robert = new_server(rendezvous::server::Config::default()).await; let mut eve = new_impersonating_client().await; @@ -273,7 +285,9 @@ async fn eve_cannot_register() { // test if charlie can operate as client and server simultaneously #[tokio::test] async fn can_combine_client_and_server() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let ([mut alice], mut robert) = new_server_with_connected_clients(rendezvous::server::Config::default()).await; @@ -309,7 +323,9 @@ async fn can_combine_client_and_server() { #[tokio::test] async fn registration_on_clients_expire() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let ([mut alice, mut bob], robert) = new_server_with_connected_clients(rendezvous::server::Config::default().with_min_ttl(1)) diff --git a/protocols/request-response/tests/ping.rs b/protocols/request-response/tests/ping.rs index 508315637ff..a2900bfdd97 100644 --- a/protocols/request-response/tests/ping.rs +++ b/protocols/request-response/tests/ping.rs @@ -34,7 +34,9 @@ use tracing_subscriber::EnvFilter; #[async_std::test] #[cfg(feature = "cbor")] async fn is_response_outbound() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let ping = Ping("ping".to_string().into_bytes()); let offline_peer = PeerId::random(); diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 51f713ae916..8136a27404c 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -2374,7 +2374,9 @@ mod tests { #[test] fn aborting_pending_connection_surfaces_error() { - tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init(); let mut dialer = new_test_swarm().build(); let mut listener = new_test_swarm().build(); diff --git a/transports/dns/src/lib.rs b/transports/dns/src/lib.rs index 8296b08811c..83e40092a2a 100644 --- a/transports/dns/src/lib.rs +++ b/transports/dns/src/lib.rs @@ -631,8 +631,9 @@ mod tests { #[test] fn basic_resolve() { - tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init(); - + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init(); #[derive(Clone)] struct CustomTransport; diff --git a/transports/noise/tests/smoke.rs b/transports/noise/tests/smoke.rs index 01166cf7e3b..160003729ba 100644 --- a/transports/noise/tests/smoke.rs +++ b/transports/noise/tests/smoke.rs @@ -24,8 +24,8 @@ use libp2p_core::{upgrade, InboundUpgrade, OutboundUpgrade}; use libp2p_identity as identity; use libp2p_noise as noise; use quickcheck::*; -use tracing_subscriber::EnvFilter; use std::{convert::TryInto, io}; +use tracing_subscriber::EnvFilter; #[allow(dead_code)] fn core_upgrade_compat() { @@ -40,7 +40,9 @@ fn core_upgrade_compat() { #[test] fn xx() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); fn prop(mut messages: Vec) -> bool { messages.truncate(5); let server_id = identity::Keypair::generate_ed25519(); diff --git a/transports/plaintext/tests/smoke.rs b/transports/plaintext/tests/smoke.rs index cf9a4d95490..47ebc75a327 100644 --- a/transports/plaintext/tests/smoke.rs +++ b/transports/plaintext/tests/smoke.rs @@ -27,7 +27,9 @@ use tracing_subscriber::EnvFilter; #[test] fn variable_msg_length() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); fn prop(msg: Vec) { let msg_to_send = msg.clone(); diff --git a/transports/quic/tests/smoke.rs b/transports/quic/tests/smoke.rs index d93f7a021c3..008df43d7aa 100644 --- a/transports/quic/tests/smoke.rs +++ b/transports/quic/tests/smoke.rs @@ -43,7 +43,9 @@ async fn async_std_smoke() { #[cfg(feature = "async-std")] #[async_std::test] async fn dial_failure() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let mut a = create_default_transport::().1; let mut b = create_default_transport::().1; @@ -61,7 +63,9 @@ async fn dial_failure() { #[cfg(feature = "tokio")] #[tokio::test] async fn endpoint_reuse() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let (_, mut a_transport) = create_default_transport::(); let (_, mut b_transport) = create_default_transport::(); @@ -86,7 +90,9 @@ async fn endpoint_reuse() { #[cfg(feature = "async-std")] #[async_std::test] async fn ipv4_dial_ipv6() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let (a_peer_id, mut a_transport) = create_default_transport::(); let (b_peer_id, mut b_transport) = create_default_transport::(); @@ -104,7 +110,9 @@ async fn ipv4_dial_ipv6() { #[cfg(feature = "async-std")] #[async_std::test] async fn wrapped_with_delay() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); struct DialDelay(Arc>>); @@ -272,7 +280,9 @@ async fn tcp_and_quic() { #[cfg(feature = "async-std")] #[test] fn concurrent_connections_and_streams_async_std() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); quickcheck::QuickCheck::new() .min_tests_passed(1) @@ -283,7 +293,9 @@ fn concurrent_connections_and_streams_async_std() { #[cfg(feature = "tokio")] #[test] fn concurrent_connections_and_streams_tokio() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let rt = tokio::runtime::Runtime::new().unwrap(); let _guard = rt.enter(); @@ -300,7 +312,9 @@ async fn draft_29_support() { use futures::{future::poll_fn, select}; use libp2p_core::transport::TransportError; - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let (_, mut a_transport) = create_transport::(|cfg| cfg.support_draft_29 = true); @@ -361,7 +375,9 @@ async fn draft_29_support() { #[cfg(feature = "async-std")] #[async_std::test] async fn backpressure() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let max_stream_data = quic::Config::new(&generate_tls_keypair()).max_stream_data; let (mut stream_a, mut stream_b) = build_streams::().await; @@ -385,7 +401,9 @@ async fn backpressure() { #[cfg(feature = "async-std")] #[async_std::test] async fn read_after_peer_dropped_stream() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let (mut stream_a, mut stream_b) = build_streams::().await; let data = vec![0; 10]; @@ -405,7 +423,9 @@ async fn read_after_peer_dropped_stream() { #[async_std::test] #[should_panic] async fn write_after_peer_dropped_stream() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let (stream_a, mut stream_b) = build_streams::().await; drop(stream_a); futures_timer::Delay::new(Duration::from_millis(1)).await; @@ -459,7 +479,9 @@ async fn test_local_listener_reuse() { } async fn smoke() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let (a_peer_id, mut a_transport) = create_default_transport::

(); let (b_peer_id, mut b_transport) = create_default_transport::

(); diff --git a/transports/tcp/src/lib.rs b/transports/tcp/src/lib.rs index 3e303b17914..1674606dd88 100644 --- a/transports/tcp/src/lib.rs +++ b/transports/tcp/src/lib.rs @@ -904,7 +904,9 @@ mod tests { #[test] fn communicating_between_dialer_and_listener() { - tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init(); async fn listener(addr: Multiaddr, mut ready_tx: mpsc::Sender) { let mut tcp = Transport::::default().boxed(); @@ -973,7 +975,9 @@ mod tests { #[test] fn wildcard_expansion() { - tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init(); async fn listener(addr: Multiaddr, mut ready_tx: mpsc::Sender) { let mut tcp = Transport::::default().boxed(); @@ -1042,7 +1046,9 @@ mod tests { #[test] fn port_reuse_dialing() { - tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init(); async fn listener( addr: Multiaddr, @@ -1149,7 +1155,9 @@ mod tests { #[test] fn port_reuse_listening() { - tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init(); async fn listen_twice(addr: Multiaddr) { let mut tcp = Transport::::new(Config::new().port_reuse(true)); @@ -1203,7 +1211,9 @@ mod tests { #[test] fn listen_port_0() { - tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init(); async fn listen(addr: Multiaddr) -> Multiaddr { let mut tcp = Transport::::default().boxed(); @@ -1238,7 +1248,9 @@ mod tests { #[test] fn listen_invalid_addr() { - tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init(); fn test(addr: Multiaddr) { #[cfg(feature = "async-io")] @@ -1308,7 +1320,9 @@ mod tests { #[test] fn test_remove_listener() { - tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init(); async fn cycle_listeners() -> bool { let mut tcp = Transport::::default().boxed(); diff --git a/transports/webrtc/tests/smoke.rs b/transports/webrtc/tests/smoke.rs index c87cd88621b..99fc1af221d 100644 --- a/transports/webrtc/tests/smoke.rs +++ b/transports/webrtc/tests/smoke.rs @@ -28,16 +28,18 @@ use libp2p_core::{Multiaddr, Transport}; use libp2p_identity::PeerId; use libp2p_webrtc as webrtc; use rand::{thread_rng, RngCore}; -use tracing_subscriber::EnvFilter; use std::future::Future; use std::num::NonZeroU8; use std::pin::Pin; use std::task::{Context, Poll}; use std::time::Duration; +use tracing_subscriber::EnvFilter; #[tokio::test] async fn smoke() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let (a_peer_id, mut a_transport) = create_transport(); let (b_peer_id, mut b_transport) = create_transport(); @@ -54,7 +56,9 @@ async fn smoke() { // Note: This test should likely be ported to the muxer compliance test suite. #[test] fn concurrent_connections_and_streams_tokio() { - tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let rt = tokio::runtime::Runtime::new().unwrap(); let _guard = rt.enter(); From 92eb66935d046754dbab0d26d10b574ae2aaaae0 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Sun, 1 Oct 2023 14:06:00 +0300 Subject: [PATCH 066/105] fmt --- protocols/kad/src/behaviour/test.rs | 4 +++- swarm/src/connection.rs | 4 +++- transports/plaintext/tests/smoke.rs | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/protocols/kad/src/behaviour/test.rs b/protocols/kad/src/behaviour/test.rs index f85208ee817..6ed3f80a6fd 100644 --- a/protocols/kad/src/behaviour/test.rs +++ b/protocols/kad/src/behaviour/test.rs @@ -314,7 +314,9 @@ fn query_iter() { #[test] fn unresponsive_not_returned_direct() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init(); // Build one node. It contains fake addresses to non-existing nodes. We ask it to find a // random peer. We make sure that no fake address is returned. diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index ae22012988b..69d83bbf455 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -988,7 +988,9 @@ mod tests { #[test] fn checked_add_fraction_can_add_u64_max() { - let _ = env_logger::try_init(); + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init(); let start = Instant::now(); let duration = checked_add_fraction(start, Duration::from_secs(u64::MAX)); diff --git a/transports/plaintext/tests/smoke.rs b/transports/plaintext/tests/smoke.rs index d263ae3b159..4cfbf3c8fe8 100644 --- a/transports/plaintext/tests/smoke.rs +++ b/transports/plaintext/tests/smoke.rs @@ -21,7 +21,7 @@ use futures::io::{AsyncReadExt, AsyncWriteExt}; use libp2p_core::InboundUpgrade; use libp2p_identity as identity; -use libp2p_plaintext::PlainText2Config; +use libp2p_plaintext as plaintext; use quickcheck::QuickCheck; use tracing_subscriber::EnvFilter; From fc40b5622a78b87ab9d9fb7b622e3707e9f5f15f Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Sun, 1 Oct 2023 14:06:09 +0300 Subject: [PATCH 067/105] fmt --- protocols/identify/src/handler.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/protocols/identify/src/handler.rs b/protocols/identify/src/handler.rs index 4d0258ca3ce..e890caa4c01 100644 --- a/protocols/identify/src/handler.rs +++ b/protocols/identify/src/handler.rs @@ -180,7 +180,9 @@ impl Handler { .try_push(protocol::recv_push(stream).map_ok(Success::ReceivedIdentifyPush)) .is_err() { - tracing::warn!("Dropping inbound identify push stream because we are at capacity"); + tracing::warn!( + "Dropping inbound identify push stream because we are at capacity" + ); } } } @@ -215,7 +217,9 @@ impl Handler { ) .is_err() { - tracing::warn!("Dropping outbound identify push stream because we are at capacity"); + tracing::warn!( + "Dropping outbound identify push stream because we are at capacity" + ); } } } From 294f1e004e2cb65bd09ecd36ff0b807ab50284d3 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Sun, 1 Oct 2023 14:11:21 +0300 Subject: [PATCH 068/105] fixes based on feedback --- protocols/ping/src/handler.rs | 6 +----- protocols/ping/src/lib.rs | 4 ++-- swarm/src/connection/pool.rs | 4 ++-- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index 0b50b70c89b..f5de5f7325f 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -23,7 +23,6 @@ use futures::future::{BoxFuture, Either}; use futures::prelude::*; use futures_timer::Delay; use libp2p_core::upgrade::ReadyUpgrade; -use libp2p_identity::PeerId; use libp2p_swarm::handler::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, }; @@ -147,8 +146,6 @@ pub struct Handler { inbound: Option, /// Tracks the state of our handler. state: State, - /// The peer we are connected to. - _peer: PeerId, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -166,9 +163,8 @@ enum State { impl Handler { /// Builds a new [`Handler`] with the given configuration. - pub fn new(config: Config, peer: PeerId) -> Self { + pub fn new(config: Config) -> Self { Handler { - _peer: peer, config, interval: Delay::new(Duration::new(0, 0)), pending_errors: VecDeque::with_capacity(2), diff --git a/protocols/ping/src/lib.rs b/protocols/ping/src/lib.rs index d1c4a2facaf..a3e588c8d7c 100644 --- a/protocols/ping/src/lib.rs +++ b/protocols/ping/src/lib.rs @@ -115,7 +115,7 @@ impl NetworkBehaviour for Behaviour { _: &Multiaddr, _: &Multiaddr, ) -> Result, ConnectionDenied> { - Ok(Handler::new(self.config.clone(), peer)) + Ok(Handler::new(self.config.clone())) } fn handle_established_outbound_connection( @@ -125,7 +125,7 @@ impl NetworkBehaviour for Behaviour { _: &Multiaddr, _: Endpoint, ) -> Result, ConnectionDenied> { - Ok(Handler::new(self.config.clone(), peer)) + Ok(Handler::new(self.config.clone())) } fn on_connection_handler_event( diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index df19c69eb50..3a55eb7646e 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -516,8 +516,8 @@ where waker.wake(); } - let span = tracing::error_span!("connection", id = %id, peer = %obtained_peer_id, remote_address = %endpoint.get_remote_address()); - let connection: Connection = Connection::new( + let span = tracing::error_span!("Connection::poll", id = %id, peer = %obtained_peer_id, remote_address = %endpoint.get_remote_address()); + let connection = Connection::new( connection, handler, self.substream_upgrade_protocol_override, From 897dea0f8264fd76147e37f100f6b604ec998847 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Sun, 1 Oct 2023 14:14:03 +0300 Subject: [PATCH 069/105] remove unnecessary peer id ref --- protocols/ping/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protocols/ping/src/lib.rs b/protocols/ping/src/lib.rs index a3e588c8d7c..36b33bea8ad 100644 --- a/protocols/ping/src/lib.rs +++ b/protocols/ping/src/lib.rs @@ -111,7 +111,7 @@ impl NetworkBehaviour for Behaviour { fn handle_established_inbound_connection( &mut self, _: ConnectionId, - peer: PeerId, + _: PeerId, _: &Multiaddr, _: &Multiaddr, ) -> Result, ConnectionDenied> { @@ -121,7 +121,7 @@ impl NetworkBehaviour for Behaviour { fn handle_established_outbound_connection( &mut self, _: ConnectionId, - peer: PeerId, + _: PeerId, _: &Multiaddr, _: Endpoint, ) -> Result, ConnectionDenied> { From 587b1ac8b164ae6265ddf1f5ce5e5a495d1945b2 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 5 Oct 2023 14:40:21 +0300 Subject: [PATCH 070/105] fixing tracing subscriber issue --- examples/autonat/src/bin/autonat_client.rs | 4 +- examples/autonat/src/bin/autonat_server.rs | 4 +- examples/browser-webrtc/src/main.rs | 7 ++- examples/chat/src/main.rs | 2 +- examples/dcutr/src/main.rs | 4 +- .../distributed-key-value-store/src/main.rs | 2 +- examples/file-sharing/src/main.rs | 2 +- examples/identify/src/main.rs | 4 +- examples/ipfs-kad/src/main.rs | 2 +- examples/ipfs-private/src/main.rs | 2 +- examples/metrics/src/main.rs | 2 +- examples/ping/src/main.rs | 4 +- examples/relay-server/src/main.rs | 2 +- examples/rendezvous/src/bin/rzv-discover.rs | 2 +- examples/rendezvous/src/bin/rzv-identify.rs | 2 +- examples/rendezvous/src/bin/rzv-register.rs | 2 +- examples/rendezvous/src/main.rs | 2 +- interop-tests/src/arch.rs | 4 +- .../multistream-select/tests/dialer_select.rs | 4 +- misc/server/src/main.rs | 4 +- muxers/mplex/benches/split_send_size.rs | 4 +- muxers/mplex/src/io.rs | 8 ++-- protocols/dcutr/tests/lib.rs | 4 +- protocols/gossipsub/src/behaviour/tests.rs | 4 +- protocols/gossipsub/tests/smoke.rs | 4 +- protocols/identify/tests/smoke.rs | 12 ++--- protocols/kad/src/behaviour/test.rs | 4 +- protocols/kad/tests/client_mode.rs | 16 +++---- protocols/mdns/tests/use-async-std.rs | 16 +++---- protocols/mdns/tests/use-tokio.rs | 12 ++--- protocols/perf/src/bin/perf.rs | 4 +- protocols/perf/tests/lib.rs | 4 +- protocols/relay/tests/lib.rs | 20 ++++----- protocols/rendezvous/tests/rendezvous.rs | 32 +++++++------- protocols/request-response/tests/ping.rs | 4 +- swarm/src/connection.rs | 4 +- swarm/src/lib.rs | 4 +- transports/dns/src/lib.rs | 4 +- transports/noise/tests/smoke.rs | 4 +- transports/plaintext/tests/smoke.rs | 4 +- transports/quic/tests/smoke.rs | 44 +++++++++---------- transports/tcp/src/lib.rs | 28 ++++++------ transports/webrtc/tests/smoke.rs | 8 ++-- 43 files changed, 154 insertions(+), 155 deletions(-) diff --git a/examples/autonat/src/bin/autonat_client.rs b/examples/autonat/src/bin/autonat_client.rs index 1c5bb702300..a82ec9e7679 100644 --- a/examples/autonat/src/bin/autonat_client.rs +++ b/examples/autonat/src/bin/autonat_client.rs @@ -46,9 +46,9 @@ struct Opt { #[async_std::main] async fn main() -> Result<(), Box> { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let opt = Opt::parse(); diff --git a/examples/autonat/src/bin/autonat_server.rs b/examples/autonat/src/bin/autonat_server.rs index db81fa4ab5b..ffa94eaa139 100644 --- a/examples/autonat/src/bin/autonat_server.rs +++ b/examples/autonat/src/bin/autonat_server.rs @@ -38,9 +38,9 @@ struct Opt { #[async_std::main] async fn main() -> Result<(), Box> { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let opt = Opt::parse(); diff --git a/examples/browser-webrtc/src/main.rs b/examples/browser-webrtc/src/main.rs index 711606b9bf0..5b2cc5fe9a0 100644 --- a/examples/browser-webrtc/src/main.rs +++ b/examples/browser-webrtc/src/main.rs @@ -20,13 +20,12 @@ use rand::thread_rng; use std::net::{Ipv4Addr, SocketAddr}; use std::time::Duration; use tower_http::cors::{Any, CorsLayer}; -use tracing_subscriber::EnvFilter; #[tokio::main] async fn main() -> anyhow::Result<()> { - tracing_subscriber::fmt() - .with_env_filter(EnvFilter::from_default_env()) - .init(); + let _ = tracing_subscriber::fmt() + .with_env_filter("browser_webrtc_example=debug,libp2p_webrtc=info,libp2p_ping=debug") + .try_init(); let id_keys = identity::Keypair::generate_ed25519(); let local_peer_id = id_keys.public().to_peer_id(); diff --git a/examples/chat/src/main.rs b/examples/chat/src/main.rs index e4040eaa05c..0b6b2cbe1b2 100644 --- a/examples/chat/src/main.rs +++ b/examples/chat/src/main.rs @@ -48,7 +48,7 @@ async fn main() -> Result<(), Box> { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - tracing_subscriber::fmt().with_env_filter(env_filter).init(); + let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); // Create a random PeerId let id_keys = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(id_keys.public()); diff --git a/examples/dcutr/src/main.rs b/examples/dcutr/src/main.rs index 6706bd0a05d..a5479c12846 100644 --- a/examples/dcutr/src/main.rs +++ b/examples/dcutr/src/main.rs @@ -79,9 +79,9 @@ impl FromStr for Mode { } fn main() -> Result<(), Box> { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let opts = Opts::parse(); diff --git a/examples/distributed-key-value-store/src/main.rs b/examples/distributed-key-value-store/src/main.rs index d769cd8ddfd..9dce5d23a30 100644 --- a/examples/distributed-key-value-store/src/main.rs +++ b/examples/distributed-key-value-store/src/main.rs @@ -40,7 +40,7 @@ async fn main() -> Result<(), Box> { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - tracing_subscriber::fmt().with_env_filter(env_filter).init(); + let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); // Create a random key for ourselves. let local_key = identity::Keypair::generate_ed25519(); diff --git a/examples/file-sharing/src/main.rs b/examples/file-sharing/src/main.rs index 482abd57c0d..a955bd34970 100644 --- a/examples/file-sharing/src/main.rs +++ b/examples/file-sharing/src/main.rs @@ -39,7 +39,7 @@ async fn main() -> Result<(), Box> { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - tracing_subscriber::fmt().with_env_filter(env_filter).init(); + let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); let opt = Opt::parse(); diff --git a/examples/identify/src/main.rs b/examples/identify/src/main.rs index 11b5e9914c1..519722b2112 100644 --- a/examples/identify/src/main.rs +++ b/examples/identify/src/main.rs @@ -32,9 +32,9 @@ use tracing_subscriber::EnvFilter; #[async_std::main] async fn main() -> Result<(), Box> { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); diff --git a/examples/ipfs-kad/src/main.rs b/examples/ipfs-kad/src/main.rs index 673f2db9226..980e92ee4e7 100644 --- a/examples/ipfs-kad/src/main.rs +++ b/examples/ipfs-kad/src/main.rs @@ -44,7 +44,7 @@ async fn main() -> Result<(), Box> { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - tracing_subscriber::fmt().with_env_filter(env_filter).init(); + let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); // Create a random key for ourselves. let local_key = identity::Keypair::generate_ed25519(); diff --git a/examples/ipfs-private/src/main.rs b/examples/ipfs-private/src/main.rs index f01ebd53288..9697d1135af 100644 --- a/examples/ipfs-private/src/main.rs +++ b/examples/ipfs-private/src/main.rs @@ -115,7 +115,7 @@ async fn main() -> Result<(), Box> { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - tracing_subscriber::fmt().with_env_filter(env_filter).init(); + let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); let ipfs_path = get_ipfs_path(); println!("using IPFS_PATH {ipfs_path:?}"); diff --git a/examples/metrics/src/main.rs b/examples/metrics/src/main.rs index b1381d2baec..8d937070643 100644 --- a/examples/metrics/src/main.rs +++ b/examples/metrics/src/main.rs @@ -40,7 +40,7 @@ fn main() -> Result<(), Box> { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - tracing_subscriber::fmt().with_env_filter(env_filter).init(); + let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); diff --git a/examples/ping/src/main.rs b/examples/ping/src/main.rs index d714f346735..b7d4534070f 100644 --- a/examples/ping/src/main.rs +++ b/examples/ping/src/main.rs @@ -33,9 +33,9 @@ use tracing_subscriber::EnvFilter; #[async_std::main] async fn main() -> Result<(), Box> { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); diff --git a/examples/relay-server/src/main.rs b/examples/relay-server/src/main.rs index a3581b07f0e..a93282f226c 100644 --- a/examples/relay-server/src/main.rs +++ b/examples/relay-server/src/main.rs @@ -44,7 +44,7 @@ fn main() -> Result<(), Box> { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - tracing_subscriber::fmt().with_env_filter(env_filter).init(); + let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); let opt = Opt::parse(); println!("opt: {opt:?}"); diff --git a/examples/rendezvous/src/bin/rzv-discover.rs b/examples/rendezvous/src/bin/rzv-discover.rs index 1b828570c70..bed022e849d 100644 --- a/examples/rendezvous/src/bin/rzv-discover.rs +++ b/examples/rendezvous/src/bin/rzv-discover.rs @@ -38,7 +38,7 @@ async fn main() { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - tracing_subscriber::fmt().with_env_filter(env_filter).init(); + let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); let key_pair = identity::Keypair::generate_ed25519(); let rendezvous_point_address = "/ip4/127.0.0.1/tcp/62649".parse::().unwrap(); diff --git a/examples/rendezvous/src/bin/rzv-identify.rs b/examples/rendezvous/src/bin/rzv-identify.rs index 5645e740585..3cf5ee4693d 100644 --- a/examples/rendezvous/src/bin/rzv-identify.rs +++ b/examples/rendezvous/src/bin/rzv-identify.rs @@ -34,7 +34,7 @@ async fn main() { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - tracing_subscriber::fmt().with_env_filter(env_filter).init(); + let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); let key_pair = identity::Keypair::generate_ed25519(); let rendezvous_point_address = "/ip4/127.0.0.1/tcp/62649".parse::().unwrap(); diff --git a/examples/rendezvous/src/bin/rzv-register.rs b/examples/rendezvous/src/bin/rzv-register.rs index 1b3be203d90..f9c50ddaf7d 100644 --- a/examples/rendezvous/src/bin/rzv-register.rs +++ b/examples/rendezvous/src/bin/rzv-register.rs @@ -34,7 +34,7 @@ async fn main() { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - tracing_subscriber::fmt().with_env_filter(env_filter).init(); + let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); let key_pair = identity::Keypair::generate_ed25519(); let rendezvous_point_address = "/ip4/127.0.0.1/tcp/62649".parse::().unwrap(); diff --git a/examples/rendezvous/src/main.rs b/examples/rendezvous/src/main.rs index 029746b4cbf..c920455c785 100644 --- a/examples/rendezvous/src/main.rs +++ b/examples/rendezvous/src/main.rs @@ -36,7 +36,7 @@ async fn main() { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - tracing_subscriber::fmt().with_env_filter(env_filter).init(); + let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); let key_pair = identity::Keypair::generate_ed25519(); diff --git a/interop-tests/src/arch.rs b/interop-tests/src/arch.rs index 207bf9afe3f..43763b5e1b0 100644 --- a/interop-tests/src/arch.rs +++ b/interop-tests/src/arch.rs @@ -38,9 +38,9 @@ pub(crate) mod native { pub(crate) type Instant = std::time::Instant; pub(crate) fn init_logger() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); } pub(crate) fn sleep(duration: Duration) -> BoxFuture<'static, ()> { diff --git a/misc/multistream-select/tests/dialer_select.rs b/misc/multistream-select/tests/dialer_select.rs index 2bdc390bc00..1c23d04a3e0 100644 --- a/misc/multistream-select/tests/dialer_select.rs +++ b/misc/multistream-select/tests/dialer_select.rs @@ -73,9 +73,9 @@ fn select_proto_basic() { /// Tests the expected behaviour of failed negotiations. #[test] fn negotiation_failed() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); async fn run( Test { diff --git a/misc/server/src/main.rs b/misc/server/src/main.rs index af8fd6d1a19..cc9b4639370 100644 --- a/misc/server/src/main.rs +++ b/misc/server/src/main.rs @@ -56,9 +56,9 @@ struct Opts { #[tokio::main] async fn main() -> Result<(), Box> { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let opt = Opts::parse(); diff --git a/muxers/mplex/benches/split_send_size.rs b/muxers/mplex/benches/split_send_size.rs index 57b16f6e7bb..9a9814d2f2a 100644 --- a/muxers/mplex/benches/split_send_size.rs +++ b/muxers/mplex/benches/split_send_size.rs @@ -52,9 +52,9 @@ const BENCH_SIZES: [usize; 8] = [ ]; fn prepare(c: &mut Criterion) { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let payload: Vec = vec![1; 1024 * 1024]; diff --git a/muxers/mplex/src/io.rs b/muxers/mplex/src/io.rs index 29259484970..0dd8b9ea6a9 100644 --- a/muxers/mplex/src/io.rs +++ b/muxers/mplex/src/io.rs @@ -1231,9 +1231,9 @@ mod tests { #[test] fn max_buffer_behaviour() { use tracing_subscriber::EnvFilter; - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); fn prop(cfg: MplexConfig, overflow: NonZeroU8) { let mut r_buf = BytesMut::new(); @@ -1369,9 +1369,9 @@ mod tests { #[test] fn close_on_error() { use tracing_subscriber::EnvFilter; - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); fn prop(cfg: MplexConfig, num_streams: NonZeroU8) { let num_streams = cmp::min(cfg.max_substreams, num_streams.get() as usize); diff --git a/protocols/dcutr/tests/lib.rs b/protocols/dcutr/tests/lib.rs index 92f003a08f4..7b2babbeeb5 100644 --- a/protocols/dcutr/tests/lib.rs +++ b/protocols/dcutr/tests/lib.rs @@ -33,9 +33,9 @@ use tracing_subscriber::EnvFilter; #[async_std::test] async fn connect() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let mut relay = build_relay(); let mut dst = build_client(); diff --git a/protocols/gossipsub/src/behaviour/tests.rs b/protocols/gossipsub/src/behaviour/tests.rs index c03718a1651..6eb3a711cd1 100644 --- a/protocols/gossipsub/src/behaviour/tests.rs +++ b/protocols/gossipsub/src/behaviour/tests.rs @@ -4666,9 +4666,9 @@ fn test_limit_number_of_message_ids_inside_ihave() { #[test] fn test_iwant_penalties() { use tracing_subscriber::EnvFilter; - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let config = ConfigBuilder::default() .iwant_followup_time(Duration::from_secs(4)) diff --git a/protocols/gossipsub/tests/smoke.rs b/protocols/gossipsub/tests/smoke.rs index 715eeb24154..5820db69b0a 100644 --- a/protocols/gossipsub/tests/smoke.rs +++ b/protocols/gossipsub/tests/smoke.rs @@ -128,9 +128,9 @@ async fn build_node() -> Swarm { #[test] fn multi_hop_propagation() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); fn prop(num_nodes: u8, seed: u64) -> TestResult { if !(2..=50).contains(&num_nodes) { diff --git a/protocols/identify/tests/smoke.rs b/protocols/identify/tests/smoke.rs index 721653359d7..6df3bd808c0 100644 --- a/protocols/identify/tests/smoke.rs +++ b/protocols/identify/tests/smoke.rs @@ -7,9 +7,9 @@ use tracing_subscriber::EnvFilter; #[async_std::test] async fn periodic_identify() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let mut swarm1 = Swarm::new_ephemeral(|identity| { identify::Behaviour::new( @@ -83,9 +83,9 @@ async fn periodic_identify() { #[async_std::test] async fn identify_push() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let mut swarm1 = Swarm::new_ephemeral(|identity| { identify::Behaviour::new(identify::Config::new("a".to_string(), identity.public())) @@ -135,9 +135,9 @@ async fn identify_push() { #[async_std::test] async fn discover_peer_after_disconnect() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let mut swarm1 = Swarm::new_ephemeral(|identity| { identify::Behaviour::new(identify::Config::new("a".to_string(), identity.public())) diff --git a/protocols/kad/src/behaviour/test.rs b/protocols/kad/src/behaviour/test.rs index 6ed3f80a6fd..fa0255544a5 100644 --- a/protocols/kad/src/behaviour/test.rs +++ b/protocols/kad/src/behaviour/test.rs @@ -314,9 +314,9 @@ fn query_iter() { #[test] fn unresponsive_not_returned_direct() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) - .init(); + .try_init(); // Build one node. It contains fake addresses to non-existing nodes. We ask it to find a // random peer. We make sure that no fake address is returned. diff --git a/protocols/kad/tests/client_mode.rs b/protocols/kad/tests/client_mode.rs index 9e953385673..a7f36d95d15 100644 --- a/protocols/kad/tests/client_mode.rs +++ b/protocols/kad/tests/client_mode.rs @@ -8,9 +8,9 @@ use tracing_subscriber::EnvFilter; #[async_std::test] async fn server_gets_added_to_routing_table_by_client() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let mut client = Swarm::new_ephemeral(MyBehaviour::new); let mut server = Swarm::new_ephemeral(MyBehaviour::new); @@ -33,9 +33,9 @@ async fn server_gets_added_to_routing_table_by_client() { #[async_std::test] async fn two_servers_add_each_other_to_routing_table() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let mut server1 = Swarm::new_ephemeral(MyBehaviour::new); let mut server2 = Swarm::new_ephemeral(MyBehaviour::new); @@ -79,9 +79,9 @@ async fn two_servers_add_each_other_to_routing_table() { #[async_std::test] async fn adding_an_external_addresses_activates_server_mode_on_existing_connections() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let mut client = Swarm::new_ephemeral(MyBehaviour::new); let mut server = Swarm::new_ephemeral(MyBehaviour::new); @@ -120,9 +120,9 @@ async fn adding_an_external_addresses_activates_server_mode_on_existing_connecti #[async_std::test] async fn set_client_to_server_mode() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let mut client = Swarm::new_ephemeral(MyBehaviour::new); client.behaviour_mut().kad.set_mode(Some(Mode::Client)); diff --git a/protocols/mdns/tests/use-async-std.rs b/protocols/mdns/tests/use-async-std.rs index 44afafe1a56..549f70978af 100644 --- a/protocols/mdns/tests/use-async-std.rs +++ b/protocols/mdns/tests/use-async-std.rs @@ -28,18 +28,18 @@ use tracing_subscriber::EnvFilter; #[async_std::test] async fn test_discovery_async_std_ipv4() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); run_discovery_test(Config::default()).await } #[async_std::test] async fn test_discovery_async_std_ipv6() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let config = Config { enable_ipv6: true, @@ -50,9 +50,9 @@ async fn test_discovery_async_std_ipv6() { #[async_std::test] async fn test_expired_async_std() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let config = Config { ttl: Duration::from_secs(1), @@ -85,9 +85,9 @@ async fn test_expired_async_std() { #[async_std::test] async fn test_no_expiration_on_close_async_std() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let config = Config { ttl: Duration::from_secs(120), query_interval: Duration::from_secs(10), diff --git a/protocols/mdns/tests/use-tokio.rs b/protocols/mdns/tests/use-tokio.rs index cb7b1e2c6d8..cf0d9f4bed4 100644 --- a/protocols/mdns/tests/use-tokio.rs +++ b/protocols/mdns/tests/use-tokio.rs @@ -26,18 +26,18 @@ use tracing_subscriber::EnvFilter; #[tokio::test] async fn test_discovery_tokio_ipv4() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); run_discovery_test(Config::default()).await } #[tokio::test] async fn test_discovery_tokio_ipv6() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let config = Config { enable_ipv6: true, @@ -48,9 +48,9 @@ async fn test_discovery_tokio_ipv6() { #[tokio::test] async fn test_expired_tokio() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let config = Config { ttl: Duration::from_secs(1), diff --git a/protocols/perf/src/bin/perf.rs b/protocols/perf/src/bin/perf.rs index d446392cd80..fe93fa29431 100644 --- a/protocols/perf/src/bin/perf.rs +++ b/protocols/perf/src/bin/perf.rs @@ -73,9 +73,9 @@ impl FromStr for Transport { #[tokio::main] async fn main() -> Result<()> { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let opts = Opts::parse(); match opts { diff --git a/protocols/perf/tests/lib.rs b/protocols/perf/tests/lib.rs index b3af382febb..7c92674dee9 100644 --- a/protocols/perf/tests/lib.rs +++ b/protocols/perf/tests/lib.rs @@ -25,9 +25,9 @@ use tracing_subscriber::EnvFilter; #[tokio::test] async fn perf() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let mut server = Swarm::new_ephemeral(|_| server::Behaviour::new()); let server_peer_id = *server.local_peer_id(); diff --git a/protocols/relay/tests/lib.rs b/protocols/relay/tests/lib.rs index da5c6965729..54011eea94e 100644 --- a/protocols/relay/tests/lib.rs +++ b/protocols/relay/tests/lib.rs @@ -39,9 +39,9 @@ use tracing_subscriber::EnvFilter; #[test] fn reservation() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let mut pool = LocalPool::new(); let relay_addr = Multiaddr::empty().with(Protocol::Memory(rand::random::())); @@ -82,9 +82,9 @@ fn reservation() { #[test] fn new_reservation_to_same_relay_replaces_old() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let mut pool = LocalPool::new(); let relay_addr = Multiaddr::empty().with(Protocol::Memory(rand::random::())); @@ -175,9 +175,9 @@ fn new_reservation_to_same_relay_replaces_old() { #[test] fn connect() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let mut pool = LocalPool::new(); let relay_addr = Multiaddr::empty().with(Protocol::Memory(rand::random::())); @@ -261,9 +261,9 @@ async fn connection_established_to( #[test] fn handle_dial_failure() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let mut pool = LocalPool::new(); let relay_addr = Multiaddr::empty().with(Protocol::Memory(rand::random::())); @@ -282,9 +282,9 @@ fn handle_dial_failure() { #[test] fn reuse_connection() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let mut pool = LocalPool::new(); let relay_addr = Multiaddr::empty().with(Protocol::Memory(rand::random::())); diff --git a/protocols/rendezvous/tests/rendezvous.rs b/protocols/rendezvous/tests/rendezvous.rs index 9a158ecd70d..e60856b0467 100644 --- a/protocols/rendezvous/tests/rendezvous.rs +++ b/protocols/rendezvous/tests/rendezvous.rs @@ -31,9 +31,9 @@ use tracing_subscriber::EnvFilter; #[tokio::test] async fn given_successful_registration_then_successful_discovery() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let ([mut alice, mut bob], mut robert) = new_server_with_connected_clients(rendezvous::server::Config::default()).await; @@ -86,9 +86,9 @@ async fn given_successful_registration_then_successful_discovery() { #[tokio::test] async fn should_return_error_when_no_external_addresses() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let server = new_server(rendezvous::server::Config::default()).await; let mut client = Swarm::new_ephemeral(rendezvous::client::Behaviour::new); @@ -103,9 +103,9 @@ async fn should_return_error_when_no_external_addresses() { #[tokio::test] async fn given_successful_registration_then_refresh_ttl() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let ([mut alice, mut bob], mut robert) = new_server_with_connected_clients(rendezvous::server::Config::default()).await; @@ -171,9 +171,9 @@ async fn given_successful_registration_then_refresh_ttl() { #[tokio::test] async fn given_invalid_ttl_then_unsuccessful_registration() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let ([mut alice], mut robert) = new_server_with_connected_clients(rendezvous::server::Config::default()).await; @@ -200,9 +200,9 @@ async fn given_invalid_ttl_then_unsuccessful_registration() { #[tokio::test] async fn discover_allows_for_dial_by_peer_id() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let ([mut alice, mut bob], robert) = new_server_with_connected_clients(rendezvous::server::Config::default()).await; @@ -257,9 +257,9 @@ async fn discover_allows_for_dial_by_peer_id() { #[tokio::test] async fn eve_cannot_register() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let mut robert = new_server(rendezvous::server::Config::default()).await; let mut eve = new_impersonating_client().await; @@ -285,9 +285,9 @@ async fn eve_cannot_register() { // test if charlie can operate as client and server simultaneously #[tokio::test] async fn can_combine_client_and_server() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let ([mut alice], mut robert) = new_server_with_connected_clients(rendezvous::server::Config::default()).await; @@ -323,9 +323,9 @@ async fn can_combine_client_and_server() { #[tokio::test] async fn registration_on_clients_expire() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); let ([mut alice, mut bob], robert) = new_server_with_connected_clients(rendezvous::server::Config::default().with_min_ttl(1)) diff --git a/protocols/request-response/tests/ping.rs b/protocols/request-response/tests/ping.rs index a2900bfdd97..1b26b3b6cfa 100644 --- a/protocols/request-response/tests/ping.rs +++ b/protocols/request-response/tests/ping.rs @@ -34,9 +34,9 @@ use tracing_subscriber::EnvFilter; #[async_std::test] #[cfg(feature = "cbor")] async fn is_response_outbound() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let ping = Ping("ping".to_string().into_bytes()); let offline_peer = PeerId::random(); diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 69d83bbf455..fc897592489 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -988,9 +988,9 @@ mod tests { #[test] fn checked_add_fraction_can_add_u64_max() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) - .init(); + .try_init(); let start = Instant::now(); let duration = checked_add_fraction(start, Duration::from_secs(u64::MAX)); diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 7365e38c6d7..fa39587a070 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -2367,9 +2367,9 @@ mod tests { #[test] fn aborting_pending_connection_surfaces_error() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) - .init(); + .try_init(); let mut dialer = new_test_swarm().build(); let mut listener = new_test_swarm().build(); diff --git a/transports/dns/src/lib.rs b/transports/dns/src/lib.rs index 83e40092a2a..28b05af667c 100644 --- a/transports/dns/src/lib.rs +++ b/transports/dns/src/lib.rs @@ -631,9 +631,9 @@ mod tests { #[test] fn basic_resolve() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) - .init(); + .try_init(); #[derive(Clone)] struct CustomTransport; diff --git a/transports/noise/tests/smoke.rs b/transports/noise/tests/smoke.rs index 160003729ba..9106b14e2bd 100644 --- a/transports/noise/tests/smoke.rs +++ b/transports/noise/tests/smoke.rs @@ -40,9 +40,9 @@ fn core_upgrade_compat() { #[test] fn xx() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); fn prop(mut messages: Vec) -> bool { messages.truncate(5); let server_id = identity::Keypair::generate_ed25519(); diff --git a/transports/plaintext/tests/smoke.rs b/transports/plaintext/tests/smoke.rs index 4cfbf3c8fe8..40606a09327 100644 --- a/transports/plaintext/tests/smoke.rs +++ b/transports/plaintext/tests/smoke.rs @@ -27,9 +27,9 @@ use tracing_subscriber::EnvFilter; #[test] fn variable_msg_length() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); fn prop(msg: Vec) { let msg_to_send = msg.clone(); diff --git a/transports/quic/tests/smoke.rs b/transports/quic/tests/smoke.rs index 008df43d7aa..ac9792390e2 100644 --- a/transports/quic/tests/smoke.rs +++ b/transports/quic/tests/smoke.rs @@ -43,9 +43,9 @@ async fn async_std_smoke() { #[cfg(feature = "async-std")] #[async_std::test] async fn dial_failure() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let mut a = create_default_transport::().1; let mut b = create_default_transport::().1; @@ -63,9 +63,9 @@ async fn dial_failure() { #[cfg(feature = "tokio")] #[tokio::test] async fn endpoint_reuse() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let (_, mut a_transport) = create_default_transport::(); let (_, mut b_transport) = create_default_transport::(); @@ -90,9 +90,9 @@ async fn endpoint_reuse() { #[cfg(feature = "async-std")] #[async_std::test] async fn ipv4_dial_ipv6() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let (a_peer_id, mut a_transport) = create_default_transport::(); let (b_peer_id, mut b_transport) = create_default_transport::(); @@ -110,9 +110,9 @@ async fn ipv4_dial_ipv6() { #[cfg(feature = "async-std")] #[async_std::test] async fn wrapped_with_delay() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); struct DialDelay(Arc>>); @@ -280,9 +280,9 @@ async fn tcp_and_quic() { #[cfg(feature = "async-std")] #[test] fn concurrent_connections_and_streams_async_std() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); quickcheck::QuickCheck::new() .min_tests_passed(1) @@ -293,9 +293,9 @@ fn concurrent_connections_and_streams_async_std() { #[cfg(feature = "tokio")] #[test] fn concurrent_connections_and_streams_tokio() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let rt = tokio::runtime::Runtime::new().unwrap(); let _guard = rt.enter(); @@ -312,9 +312,9 @@ async fn draft_29_support() { use futures::{future::poll_fn, select}; use libp2p_core::transport::TransportError; - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let (_, mut a_transport) = create_transport::(|cfg| cfg.support_draft_29 = true); @@ -375,9 +375,9 @@ async fn draft_29_support() { #[cfg(feature = "async-std")] #[async_std::test] async fn backpressure() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let max_stream_data = quic::Config::new(&generate_tls_keypair()).max_stream_data; let (mut stream_a, mut stream_b) = build_streams::().await; @@ -401,9 +401,9 @@ async fn backpressure() { #[cfg(feature = "async-std")] #[async_std::test] async fn read_after_peer_dropped_stream() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let (mut stream_a, mut stream_b) = build_streams::().await; let data = vec![0; 10]; @@ -423,9 +423,9 @@ async fn read_after_peer_dropped_stream() { #[async_std::test] #[should_panic] async fn write_after_peer_dropped_stream() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let (stream_a, mut stream_b) = build_streams::().await; drop(stream_a); futures_timer::Delay::new(Duration::from_millis(1)).await; @@ -479,9 +479,9 @@ async fn test_local_listener_reuse() { } async fn smoke() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let (a_peer_id, mut a_transport) = create_default_transport::

(); let (b_peer_id, mut b_transport) = create_default_transport::

(); diff --git a/transports/tcp/src/lib.rs b/transports/tcp/src/lib.rs index 1674606dd88..6664c9e0b78 100644 --- a/transports/tcp/src/lib.rs +++ b/transports/tcp/src/lib.rs @@ -904,9 +904,9 @@ mod tests { #[test] fn communicating_between_dialer_and_listener() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) - .init(); + .try_init(); async fn listener(addr: Multiaddr, mut ready_tx: mpsc::Sender) { let mut tcp = Transport::::default().boxed(); @@ -975,9 +975,9 @@ mod tests { #[test] fn wildcard_expansion() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) - .init(); + .try_init(); async fn listener(addr: Multiaddr, mut ready_tx: mpsc::Sender) { let mut tcp = Transport::::default().boxed(); @@ -1046,9 +1046,9 @@ mod tests { #[test] fn port_reuse_dialing() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) - .init(); + .try_init(); async fn listener( addr: Multiaddr, @@ -1155,9 +1155,9 @@ mod tests { #[test] fn port_reuse_listening() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) - .init(); + .try_init(); async fn listen_twice(addr: Multiaddr) { let mut tcp = Transport::::new(Config::new().port_reuse(true)); @@ -1211,9 +1211,9 @@ mod tests { #[test] fn listen_port_0() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) - .init(); + .try_init(); async fn listen(addr: Multiaddr) -> Multiaddr { let mut tcp = Transport::::default().boxed(); @@ -1248,9 +1248,9 @@ mod tests { #[test] fn listen_invalid_addr() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) - .init(); + .try_init(); fn test(addr: Multiaddr) { #[cfg(feature = "async-io")] @@ -1320,9 +1320,9 @@ mod tests { #[test] fn test_remove_listener() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) - .init(); + .try_init(); async fn cycle_listeners() -> bool { let mut tcp = Transport::::default().boxed(); diff --git a/transports/webrtc/tests/smoke.rs b/transports/webrtc/tests/smoke.rs index 99fc1af221d..f9480e9c19e 100644 --- a/transports/webrtc/tests/smoke.rs +++ b/transports/webrtc/tests/smoke.rs @@ -37,9 +37,9 @@ use tracing_subscriber::EnvFilter; #[tokio::test] async fn smoke() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let (a_peer_id, mut a_transport) = create_transport(); let (b_peer_id, mut b_transport) = create_transport(); @@ -56,9 +56,9 @@ async fn smoke() { // Note: This test should likely be ported to the muxer compliance test suite. #[test] fn concurrent_connections_and_streams_tokio() { - tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) - .init(); + .try_init(); let rt = tokio::runtime::Runtime::new().unwrap(); let _guard = rt.enter(); From a53da1fed9ac8f5470102ea469a9b5b905c6224f Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 5 Oct 2023 14:40:29 +0300 Subject: [PATCH 071/105] fmt --- examples/chat/src/main.rs | 4 +++- examples/distributed-key-value-store/src/main.rs | 4 +++- examples/file-sharing/src/main.rs | 4 +++- examples/ipfs-kad/src/main.rs | 4 +++- examples/ipfs-private/src/main.rs | 4 +++- examples/metrics/src/main.rs | 4 +++- examples/ping/src/main.rs | 2 +- examples/relay-server/src/main.rs | 4 +++- examples/rendezvous/src/bin/rzv-discover.rs | 4 +++- examples/rendezvous/src/bin/rzv-identify.rs | 4 +++- examples/rendezvous/src/bin/rzv-register.rs | 4 +++- examples/rendezvous/src/main.rs | 4 +++- protocols/rendezvous/tests/rendezvous.rs | 4 ++-- 13 files changed, 36 insertions(+), 14 deletions(-) diff --git a/examples/chat/src/main.rs b/examples/chat/src/main.rs index 0b6b2cbe1b2..a288671b802 100644 --- a/examples/chat/src/main.rs +++ b/examples/chat/src/main.rs @@ -48,7 +48,9 @@ async fn main() -> Result<(), Box> { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); + let _ = tracing_subscriber::fmt() + .with_env_filter(env_filter) + .try_init(); // Create a random PeerId let id_keys = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(id_keys.public()); diff --git a/examples/distributed-key-value-store/src/main.rs b/examples/distributed-key-value-store/src/main.rs index 9dce5d23a30..d3376cccb0f 100644 --- a/examples/distributed-key-value-store/src/main.rs +++ b/examples/distributed-key-value-store/src/main.rs @@ -40,7 +40,9 @@ async fn main() -> Result<(), Box> { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); + let _ = tracing_subscriber::fmt() + .with_env_filter(env_filter) + .try_init(); // Create a random key for ourselves. let local_key = identity::Keypair::generate_ed25519(); diff --git a/examples/file-sharing/src/main.rs b/examples/file-sharing/src/main.rs index a955bd34970..19bb900ba03 100644 --- a/examples/file-sharing/src/main.rs +++ b/examples/file-sharing/src/main.rs @@ -39,7 +39,9 @@ async fn main() -> Result<(), Box> { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); + let _ = tracing_subscriber::fmt() + .with_env_filter(env_filter) + .try_init(); let opt = Opt::parse(); diff --git a/examples/ipfs-kad/src/main.rs b/examples/ipfs-kad/src/main.rs index 980e92ee4e7..1adcbf4f658 100644 --- a/examples/ipfs-kad/src/main.rs +++ b/examples/ipfs-kad/src/main.rs @@ -44,7 +44,9 @@ async fn main() -> Result<(), Box> { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); + let _ = tracing_subscriber::fmt() + .with_env_filter(env_filter) + .try_init(); // Create a random key for ourselves. let local_key = identity::Keypair::generate_ed25519(); diff --git a/examples/ipfs-private/src/main.rs b/examples/ipfs-private/src/main.rs index 9697d1135af..8d2ef521f7f 100644 --- a/examples/ipfs-private/src/main.rs +++ b/examples/ipfs-private/src/main.rs @@ -115,7 +115,9 @@ async fn main() -> Result<(), Box> { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); + let _ = tracing_subscriber::fmt() + .with_env_filter(env_filter) + .try_init(); let ipfs_path = get_ipfs_path(); println!("using IPFS_PATH {ipfs_path:?}"); diff --git a/examples/metrics/src/main.rs b/examples/metrics/src/main.rs index 8d937070643..52469447547 100644 --- a/examples/metrics/src/main.rs +++ b/examples/metrics/src/main.rs @@ -40,7 +40,9 @@ fn main() -> Result<(), Box> { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); + let _ = tracing_subscriber::fmt() + .with_env_filter(env_filter) + .try_init(); let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); diff --git a/examples/ping/src/main.rs b/examples/ping/src/main.rs index b7d4534070f..8acf0a89c21 100644 --- a/examples/ping/src/main.rs +++ b/examples/ping/src/main.rs @@ -33,7 +33,7 @@ use tracing_subscriber::EnvFilter; #[async_std::main] async fn main() -> Result<(), Box> { - let _ = tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) .try_init(); diff --git a/examples/relay-server/src/main.rs b/examples/relay-server/src/main.rs index a93282f226c..4b52033df1f 100644 --- a/examples/relay-server/src/main.rs +++ b/examples/relay-server/src/main.rs @@ -44,7 +44,9 @@ fn main() -> Result<(), Box> { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); + let _ = tracing_subscriber::fmt() + .with_env_filter(env_filter) + .try_init(); let opt = Opt::parse(); println!("opt: {opt:?}"); diff --git a/examples/rendezvous/src/bin/rzv-discover.rs b/examples/rendezvous/src/bin/rzv-discover.rs index bed022e849d..da839d9dbd4 100644 --- a/examples/rendezvous/src/bin/rzv-discover.rs +++ b/examples/rendezvous/src/bin/rzv-discover.rs @@ -38,7 +38,9 @@ async fn main() { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); + let _ = tracing_subscriber::fmt() + .with_env_filter(env_filter) + .try_init(); let key_pair = identity::Keypair::generate_ed25519(); let rendezvous_point_address = "/ip4/127.0.0.1/tcp/62649".parse::().unwrap(); diff --git a/examples/rendezvous/src/bin/rzv-identify.rs b/examples/rendezvous/src/bin/rzv-identify.rs index 3cf5ee4693d..b7a04b92f82 100644 --- a/examples/rendezvous/src/bin/rzv-identify.rs +++ b/examples/rendezvous/src/bin/rzv-identify.rs @@ -34,7 +34,9 @@ async fn main() { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); + let _ = tracing_subscriber::fmt() + .with_env_filter(env_filter) + .try_init(); let key_pair = identity::Keypair::generate_ed25519(); let rendezvous_point_address = "/ip4/127.0.0.1/tcp/62649".parse::().unwrap(); diff --git a/examples/rendezvous/src/bin/rzv-register.rs b/examples/rendezvous/src/bin/rzv-register.rs index f9c50ddaf7d..54f651cdfb8 100644 --- a/examples/rendezvous/src/bin/rzv-register.rs +++ b/examples/rendezvous/src/bin/rzv-register.rs @@ -34,7 +34,9 @@ async fn main() { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); + let _ = tracing_subscriber::fmt() + .with_env_filter(env_filter) + .try_init(); let key_pair = identity::Keypair::generate_ed25519(); let rendezvous_point_address = "/ip4/127.0.0.1/tcp/62649".parse::().unwrap(); diff --git a/examples/rendezvous/src/main.rs b/examples/rendezvous/src/main.rs index c920455c785..2d4ebc0050d 100644 --- a/examples/rendezvous/src/main.rs +++ b/examples/rendezvous/src/main.rs @@ -36,7 +36,9 @@ async fn main() { .with_default_directive(LevelFilter::DEBUG.into()) .from_env_lossy(); - let _ = tracing_subscriber::fmt().with_env_filter(env_filter).try_init(); + let _ = tracing_subscriber::fmt() + .with_env_filter(env_filter) + .try_init(); let key_pair = identity::Keypair::generate_ed25519(); diff --git a/protocols/rendezvous/tests/rendezvous.rs b/protocols/rendezvous/tests/rendezvous.rs index e60856b0467..42fefe83395 100644 --- a/protocols/rendezvous/tests/rendezvous.rs +++ b/protocols/rendezvous/tests/rendezvous.rs @@ -86,7 +86,7 @@ async fn given_successful_registration_then_successful_discovery() { #[tokio::test] async fn should_return_error_when_no_external_addresses() { - let _ = tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) .try_init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); @@ -171,7 +171,7 @@ async fn given_successful_registration_then_refresh_ttl() { #[tokio::test] async fn given_invalid_ttl_then_unsuccessful_registration() { - let _ = tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) .try_init(); let namespace = rendezvous::Namespace::from_static("some-namespace"); From 612d93378be5ab8cd69ad05eb0ffe4d74b688a03 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 5 Oct 2023 21:20:51 +0300 Subject: [PATCH 072/105] add mdns + ping example --- Cargo.lock | 265 ++++++++++++++++++++ Cargo.toml | 1 + examples/open-telemetry/Cargo.toml | 18 ++ examples/open-telemetry/DOCKERFILE | 30 +++ examples/open-telemetry/docker-compose.yaml | 46 ++++ examples/open-telemetry/src/main.rs | 145 +++++++++++ 6 files changed, 505 insertions(+) create mode 100644 examples/open-telemetry/Cargo.toml create mode 100644 examples/open-telemetry/DOCKERFILE create mode 100644 examples/open-telemetry/docker-compose.yaml create mode 100644 examples/open-telemetry/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index c836e9b0080..4fb19f9704f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -416,6 +416,28 @@ dependencies = [ "trust-dns-resolver", ] +[[package]] +name = "async-stream" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite 0.2.12", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.37", +] + [[package]] name = "async-task" version = "4.4.0" @@ -1202,6 +1224,19 @@ dependencies = [ "syn 2.0.37", ] +[[package]] +name = "dashmap" +version = "5.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" +dependencies = [ + "cfg-if", + "hashbrown 0.14.0", + "lock_api", + "once_cell", + "parking_lot_core", +] + [[package]] name = "data-encoding" version = "2.4.0" @@ -2032,6 +2067,18 @@ dependencies = [ "tokio-rustls 0.23.4", ] +[[package]] +name = "hyper-timeout" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" +dependencies = [ + "hyper", + "pin-project-lite 0.2.12", + "tokio", + "tokio-io-timeout", +] + [[package]] name = "hyper-tls" version = "0.5.0" @@ -3800,6 +3847,22 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "open-telemetry-example" +version = "0.1.0" +dependencies = [ + "async-std", + "async-trait", + "futures", + "libp2p", + "opentelemetry", + "opentelemetry-otlp", + "tokio", + "tracing", + "tracing-opentelemetry", + "tracing-subscriber", +] + [[package]] name = "openssl" version = "0.10.55" @@ -3844,6 +3907,85 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "opentelemetry" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f4b8347cc26099d3aeee044065ecc3ae11469796b4d65d065a23a584ed92a6f" +dependencies = [ + "opentelemetry_api", + "opentelemetry_sdk", +] + +[[package]] +name = "opentelemetry-otlp" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8af72d59a4484654ea8eb183fea5ae4eb6a41d7ac3e3bae5f4d2a282a3a7d3ca" +dependencies = [ + "async-trait", + "futures", + "futures-util", + "http", + "opentelemetry", + "opentelemetry-proto", + "prost", + "thiserror", + "tokio", + "tonic", +] + +[[package]] +name = "opentelemetry-proto" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "045f8eea8c0fa19f7d48e7bc3128a39c2e5c533d5c61298c548dfefc1064474c" +dependencies = [ + "futures", + "futures-util", + "opentelemetry", + "prost", + "tonic", +] + +[[package]] +name = "opentelemetry_api" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed41783a5bf567688eb38372f2b7a8530f5a607a4b49d38dd7573236c23ca7e2" +dependencies = [ + "fnv", + "futures-channel", + "futures-util", + "indexmap 1.9.3", + "once_cell", + "pin-project-lite 0.2.12", + "thiserror", + "urlencoding", +] + +[[package]] +name = "opentelemetry_sdk" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b3a2a91fdbfdd4d212c0dcc2ab540de2c2bcbbd90be17de7a7daf8822d010c1" +dependencies = [ + "async-trait", + "crossbeam-channel", + "dashmap", + "fnv", + "futures-channel", + "futures-executor", + "futures-util", + "once_cell", + "opentelemetry_api", + "percent-encoding", + "rand 0.8.5", + "thiserror", + "tokio", + "tokio-stream", +] + [[package]] name = "overload" version = "0.1.1" @@ -4186,6 +4328,29 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "prost" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "quick-error" version = "1.2.3" @@ -5540,6 +5705,16 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "tokio-io-timeout" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" +dependencies = [ + "pin-project-lite 0.2.12", + "tokio", +] + [[package]] name = "tokio-macros" version = "2.1.0" @@ -5582,6 +5757,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-stream" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" +dependencies = [ + "futures-core", + "pin-project-lite 0.2.12", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.9" @@ -5597,6 +5783,38 @@ dependencies = [ "tracing", ] +[[package]] +name = "tonic" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f219fad3b929bef19b1f86fbc0358d35daed8f2cac972037ac0dc10bbb8d5fb" +dependencies = [ + "async-stream", + "async-trait", + "axum", + "base64 0.13.1", + "bytes", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-timeout", + "percent-encoding", + "pin-project", + "prost", + "prost-derive", + "tokio", + "tokio-stream", + "tokio-util", + "tower", + "tower-layer", + "tower-service", + "tracing", + "tracing-futures", +] + [[package]] name = "tower" version = "0.4.13" @@ -5605,9 +5823,13 @@ checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" dependencies = [ "futures-core", "futures-util", + "indexmap 1.9.3", "pin-project", "pin-project-lite 0.2.12", + "rand 0.8.5", + "slab", "tokio", + "tokio-util", "tower-layer", "tower-service", "tracing", @@ -5684,6 +5906,16 @@ dependencies = [ "valuable", ] +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + [[package]] name = "tracing-log" version = "0.1.3" @@ -5695,6 +5927,30 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-opentelemetry" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00a39dcf9bfc1742fa4d6215253b33a6e474be78275884c216fc2a06267b3600" +dependencies = [ + "once_cell", + "opentelemetry", + "tracing", + "tracing-core", + "tracing-log", + "tracing-subscriber", +] + +[[package]] +name = "tracing-serde" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" +dependencies = [ + "serde", + "tracing-core", +] + [[package]] name = "tracing-subscriber" version = "0.3.17" @@ -5705,12 +5961,15 @@ dependencies = [ "nu-ansi-term", "once_cell", "regex", + "serde", + "serde_json", "sharded-slab", "smallvec", "thread_local", "tracing", "tracing-core", "tracing-log", + "tracing-serde", ] [[package]] @@ -5927,6 +6186,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + [[package]] name = "utf8parse" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index 73ae23d70ff..39034445a74 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ members = [ "examples/ipfs-kad", "examples/ipfs-private", "examples/metrics", + "examples/open-telemetry", "examples/ping", "examples/relay-server", "examples/rendezvous", diff --git a/examples/open-telemetry/Cargo.toml b/examples/open-telemetry/Cargo.toml new file mode 100644 index 00000000000..6b44aa0797d --- /dev/null +++ b/examples/open-telemetry/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "open-telemetry-example" +version = "0.1.0" +edition = "2021" +publish = false +license = "MIT" + +[dependencies] +async-std = { version = "1.12", features = ["attributes"] } +async-trait = "0.1" +futures = "0.3.28" +libp2p = { path = "../../libp2p", features = ["async-std", "dns", "macros", "noise", "ping", "tcp", "websocket", "yamux"] } +opentelemetry = { version = "0.19.0", features = ["rt-tokio", "metrics"] } +opentelemetry-otlp = { version = "0.12.0", features = ["metrics"]} +tokio = { version = "1.32", features = ["full"] } +tracing = "0.1.37" +tracing-subscriber = { version = "0.3", features = ["env-filter", "json", "fmt"] } +tracing-opentelemetry = "0.19.0" \ No newline at end of file diff --git a/examples/open-telemetry/DOCKERFILE b/examples/open-telemetry/DOCKERFILE new file mode 100644 index 00000000000..51a9ba76b35 --- /dev/null +++ b/examples/open-telemetry/DOCKERFILE @@ -0,0 +1,30 @@ +FROM rust:1.70-slim as BUILDER +ARG PACKAGE +WORKDIR /build/ +COPY . ./ +RUN --mount=type=cache,target=./target \ + --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \ + --mount=type=cache,target=/usr/local/rustup,sharing=locked \ + cargo build -p $PACKAGE --release + +RUN --mount=type=cache,target=./target \ + mv ./target/release/$PACKAGE /usr/local/bin/$PACKAGE + +FROM debian:11.7-slim +ARG PACKAGE +WORKDIR /app/ +COPY --from=BUILDER /usr/local/bin/$PACKAGE . +RUN ln -s ./${PACKAGE} ./app +COPY ./docker-init.sh . +ENV RUST_BACKTRACE=1 +ENV PATH "/app:$PATH" +ENV PACKAGE_NAME ${PACKAGE} +RUN apt-get update -y \ + && apt-get install -y iputils-ping iptables lsof iproute2 curl iperf3 ca-certificates \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +ENTRYPOINT ["docker-init.sh"] +CMD ["open-telemetry"] + + diff --git a/examples/open-telemetry/docker-compose.yaml b/examples/open-telemetry/docker-compose.yaml new file mode 100644 index 00000000000..20f57651b73 --- /dev/null +++ b/examples/open-telemetry/docker-compose.yaml @@ -0,0 +1,46 @@ +version: "2" +services: + + # Jaeger + jaeger-all-in-one: + image: jaegertracing/all-in-one:latest + restart: always + ports: + - "16686:16686" + - "14268" + - "14250" + + # Collector + otel-collector: + image: ${OTELCOL_IMG} + restart: always + command: ["--config=/etc/otel-collector-config.yaml", "${OTELCOL_ARGS}"] + volumes: + - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml + ports: + - "4317:4317" # OTLP gRPC receiver + depends_on: + - jaeger-all-in-one + + demo-client: + build: + dockerfile: Dockerfile + context: ./client + restart: always + environment: + - OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317 + - DEMO_SERVER_ENDPOINT=http://demo-server:7080/hello + depends_on: + - demo-server + + demo-server: + build: + dockerfile: Dockerfile + context: ./server + restart: always + environment: + - OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317 + ports: + - "7080" + depends_on: + - otel-collector \ No newline at end of file diff --git a/examples/open-telemetry/src/main.rs b/examples/open-telemetry/src/main.rs new file mode 100644 index 00000000000..0beb8007f5d --- /dev/null +++ b/examples/open-telemetry/src/main.rs @@ -0,0 +1,145 @@ +// Copyright 2018 Parity Technologies (UK) Ltd. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +use libp2p::core::transport::upgrade; +use libp2p::mdns; +use libp2p::swarm::NetworkBehaviour; +use opentelemetry::sdk; +use opentelemetry::sdk::export::metrics; +use opentelemetry_otlp::WithExportConfig; +use std::error::Error; +use tracing::Dispatch; +use tracing_subscriber::filter::LevelFilter; +use tracing_subscriber::EnvFilter; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, Layer}; + +use futures::prelude::*; +use libp2p::core::upgrade::Version; +use libp2p::{ + identity, noise, ping, + swarm::{SwarmBuilder, SwarmEvent}, + tcp, yamux, Multiaddr, PeerId, Transport, +}; +use std::time::Duration; + +// We create a custom network behaviour that combines Ping and Mdns. +#[derive(NetworkBehaviour)] +struct MyBehaviour { + ping: ping::Behaviour, + mdns: mdns::tokio::Behaviour, +} +/* +#[async_std::main] +async fn main() -> Result<(), Box> { + let _ = tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .try_init(); + + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::INFO.into()) + .from_env_lossy(); + + let grpc_endpoint = format!("http://"); + + tracing::trace!(%grpc_endpoint, "Setting up OTLP exporter for collector"); + + let exporter = opentelemetry_otlp::new_exporter() + .tonic() + .with_endpoint(grpc_endpoint.clone()); + + let tracer = opentelemetry_otlp::new_pipeline() + .tracing() + .with_exporter(exporter) + .with_trace_config(sdk::trace::Config::default()) + .install_batch(opentelemetry::runtime::Tokio)?; + + tracing::trace!("Successfully initialized trace provider on tokio runtime"); + + let exporter = opentelemetry_otlp::new_exporter() + .tonic() + .with_endpoint(grpc_endpoint); + + opentelemetry_otlp::new_pipeline() + .metrics( + sdk::metrics::selectors::simple::inexpensive(), + metrics::aggregation::cumulative_temporality_selector(), + opentelemetry::runtime::Tokio, + ) + .with_exporter(exporter) + .build()?; + + tracing::trace!("Successfully initialized metric controller on tokio runtime"); + + let dispatch: Dispatch = tracing_subscriber::registry() + .with(tracing_opentelemetry::layer() + .with_tracer(tracer) + .with_filter(env_filter), + ) + .into(); + + let _ = dispatch.try_init(); + + Ok(()) +} +*/ +#[tokio::main] +async fn main() -> Result<(), Box> { + let _ = tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .try_init(); + + let local_key = identity::Keypair::generate_ed25519(); + let local_peer_id = PeerId::from(local_key.public()); + + // Set up an encrypted DNS-enabled TCP Transport over the yamux protocol. + let tcp_transport = tcp::tokio::Transport::new(tcp::Config::default().nodelay(true)) + .upgrade(upgrade::Version::V1Lazy) + .authenticate(noise::Config::new(&local_key)?) + .multiplex(yamux::Config::default()) + .timeout(std::time::Duration::from_secs(20)) + .boxed(); + + let mut swarm = { + let mdns = mdns::tokio::Behaviour::new(mdns::Config::default(), local_peer_id)?; + let behaviour = MyBehaviour { + mdns, + ping: ping::Behaviour::default(), + }; + SwarmBuilder::with_tokio_executor(tcp_transport, behaviour, local_peer_id) + .idle_connection_timeout(Duration::from_secs(60)) + .build() + }; + + swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?; + + loop { + match swarm.select_next_some().await { + SwarmEvent::NewListenAddr { address, .. } => println!("Listening on {address:?}"), + SwarmEvent::Behaviour(MyBehaviourEvent::Mdns(mdns::Event::Discovered(list))) => { + for (_, addr) in list { + swarm.dial(addr.clone())?; + println!("Dialed {addr}") + } + } + SwarmEvent::Behaviour(event) => println!("{event:?}"), + _ => {} + } + } +} From edaea4f032d5b103001a34e2d93d730c2807db28 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 5 Oct 2023 21:53:26 +0300 Subject: [PATCH 073/105] otel example --- examples/open-telemetry/src/main.rs | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/open-telemetry/src/main.rs b/examples/open-telemetry/src/main.rs index 0beb8007f5d..22a3c58bd61 100644 --- a/examples/open-telemetry/src/main.rs +++ b/examples/open-telemetry/src/main.rs @@ -31,11 +31,10 @@ use tracing_subscriber::EnvFilter; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, Layer}; use futures::prelude::*; -use libp2p::core::upgrade::Version; use libp2p::{ identity, noise, ping, swarm::{SwarmBuilder, SwarmEvent}, - tcp, yamux, Multiaddr, PeerId, Transport, + tcp, yamux, PeerId, Transport, }; use std::time::Duration; @@ -45,18 +44,9 @@ struct MyBehaviour { ping: ping::Behaviour, mdns: mdns::tokio::Behaviour, } -/* -#[async_std::main] -async fn main() -> Result<(), Box> { - let _ = tracing_subscriber::fmt() - .with_env_filter(EnvFilter::from_default_env()) - .try_init(); - - let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::INFO.into()) - .from_env_lossy(); - let grpc_endpoint = format!("http://"); +async fn init_telemetry() -> Result<(), Box> { + let grpc_endpoint = format!("http://localhost:4317"); tracing::trace!(%grpc_endpoint, "Setting up OTLP exporter for collector"); @@ -87,10 +77,15 @@ async fn main() -> Result<(), Box> { tracing::trace!("Successfully initialized metric controller on tokio runtime"); + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::INFO.into()) + .from_env_lossy(); + let dispatch: Dispatch = tracing_subscriber::registry() - .with(tracing_opentelemetry::layer() - .with_tracer(tracer) - .with_filter(env_filter), + .with( + tracing_opentelemetry::layer() + .with_tracer(tracer) + .with_filter(env_filter), ) .into(); @@ -98,12 +93,17 @@ async fn main() -> Result<(), Box> { Ok(()) } -*/ #[tokio::main] async fn main() -> Result<(), Box> { + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::INFO.into()) + .from_env_lossy(); + let _ = tracing_subscriber::fmt() - .with_env_filter(EnvFilter::from_default_env()) + .with_env_filter(env_filter) .try_init(); + + init_telemetry().await?; let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); From 4ba5c90ce21f28601426d483395daf1919a3aa9c Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 25 Oct 2023 14:32:51 +1100 Subject: [PATCH 074/105] Fix compile errors --- protocols/dcutr/src/behaviour_impl.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/protocols/dcutr/src/behaviour_impl.rs b/protocols/dcutr/src/behaviour_impl.rs index 86a16387b09..38030dfdf07 100644 --- a/protocols/dcutr/src/behaviour_impl.rs +++ b/protocols/dcutr/src/behaviour_impl.rs @@ -301,9 +301,7 @@ impl NetworkBehaviour for Behaviour { )]); } Either::Left(handler::relayed::Event::InboundConnectNegotiated(remote_addrs)) => { - log::debug!( - "Attempting to hole-punch as dialer to {event_source} using {remote_addrs:?}" - ); + tracing::debug!(target=%event_source, addresses=?remote_addrs, "Attempting to hole-punch as dialer"); let opts = DialOpts::peer_id(event_source) .addresses(remote_addrs) @@ -326,9 +324,7 @@ impl NetworkBehaviour for Behaviour { )); } Either::Left(handler::relayed::Event::OutboundConnectNegotiated { remote_addrs }) => { - log::debug!( - "Attempting to hole-punch as listener to {event_source} using {remote_addrs:?}" - ); + tracing::debug!(target=%event_source, addresses=?remote_addrs, "Attempting to hole-punch as dialer"); let opts = DialOpts::peer_id(event_source) .condition(dial_opts::PeerCondition::Always) From 9f856a31574bc7484e41f7327d9858bc2248a373 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 25 Oct 2023 14:37:21 +1100 Subject: [PATCH 075/105] Revert bad updates --- Cargo.lock | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 59fff74781c..2db866f89ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3770,9 +3770,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] @@ -4523,9 +4523,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.20" +version = "0.11.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" +checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" dependencies = [ "base64 0.21.4", "bytes", @@ -4548,6 +4548,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", + "system-configuration", "tokio", "tokio-native-tls", "tower-service", @@ -6133,9 +6134,9 @@ dependencies = [ [[package]] name = "webpki" -version = "0.22.1" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0e74f82d49d545ad128049b7e88f6576df2da6b02e9ce565c6f533be576957e" +checksum = "07ecc0cd7cac091bf682ec5efa18b1cff79d617b84181f38b3951dbe135f607f" dependencies = [ "ring", "untrusted", From 651da5a510303dbfe60b84555dcd5c8022eda1f9 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 25 Oct 2023 15:45:54 +1100 Subject: [PATCH 076/105] Add more spans and extend metrics example --- Cargo.lock | 212 ++++++++++++++++++++ core/src/muxing/boxed.rs | 4 + examples/metrics/Cargo.toml | 8 +- examples/metrics/README.md | 16 +- examples/metrics/docker-compose.yml | 23 +++ examples/metrics/otel-collector-config.yaml | 25 +++ examples/metrics/src/http_service.rs | 16 +- examples/metrics/src/main.rs | 77 ++++--- protocols/identify/src/handler.rs | 1 + protocols/ping/src/handler.rs | 1 + swarm/src/connection.rs | 46 +++-- swarm/src/connection/pool.rs | 5 +- swarm/src/handler/select.rs | 1 + 13 files changed, 376 insertions(+), 59 deletions(-) create mode 100644 examples/metrics/docker-compose.yml create mode 100644 examples/metrics/otel-collector-config.yaml diff --git a/Cargo.lock b/Cargo.lock index 2db866f89ef..4e6b628c9fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2038,6 +2038,18 @@ dependencies = [ "tokio-rustls 0.23.4", ] +[[package]] +name = "hyper-timeout" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" +dependencies = [ + "hyper", + "pin-project-lite", + "tokio", + "tokio-io-timeout", +] + [[package]] name = "hyper-tls" version = "0.5.0" @@ -3493,9 +3505,13 @@ dependencies = [ "futures", "hyper", "libp2p", + "opentelemetry", + "opentelemetry-otlp", + "opentelemetry_api", "prometheus-client", "tokio", "tracing", + "tracing-opentelemetry", "tracing-subscriber", ] @@ -3867,6 +3883,104 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "opentelemetry" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9591d937bc0e6d2feb6f71a559540ab300ea49955229c347a517a28d27784c54" +dependencies = [ + "opentelemetry_api", + "opentelemetry_sdk", +] + +[[package]] +name = "opentelemetry-otlp" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e5e5a5c4135864099f3faafbe939eb4d7f9b80ebf68a8448da961b32a7c1275" +dependencies = [ + "async-trait", + "futures-core", + "http", + "opentelemetry-proto", + "opentelemetry-semantic-conventions", + "opentelemetry_api", + "opentelemetry_sdk", + "prost", + "thiserror", + "tokio", + "tonic", +] + +[[package]] +name = "opentelemetry-proto" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1e3f814aa9f8c905d0ee4bde026afd3b2577a97c10e1699912e3e44f0c4cbeb" +dependencies = [ + "opentelemetry_api", + "opentelemetry_sdk", + "prost", + "tonic", +] + +[[package]] +name = "opentelemetry-semantic-conventions" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73c9f9340ad135068800e7f1b24e9e09ed9e7143f5bf8518ded3d3ec69789269" +dependencies = [ + "opentelemetry", +] + +[[package]] +name = "opentelemetry_api" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a81f725323db1b1206ca3da8bb19874bbd3f57c3bcd59471bfb04525b265b9b" +dependencies = [ + "futures-channel", + "futures-util", + "indexmap 1.9.3", + "js-sys", + "once_cell", + "pin-project-lite", + "thiserror", + "urlencoding", +] + +[[package]] +name = "opentelemetry_sdk" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa8e705a0612d48139799fcbaba0d4a90f06277153e43dd2bdc16c6f0edd8026" +dependencies = [ + "async-trait", + "crossbeam-channel", + "futures-channel", + "futures-executor", + "futures-util", + "once_cell", + "opentelemetry_api", + "ordered-float", + "percent-encoding", + "rand 0.8.5", + "regex", + "serde_json", + "thiserror", + "tokio", + "tokio-stream", +] + +[[package]] +name = "ordered-float" +version = "3.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1e1c390732d15f1d48471625cd92d154e66db2c56645e29a9cd26f4699f72dc" +dependencies = [ + "num-traits", +] + [[package]] name = "overload" version = "0.1.1" @@ -4193,6 +4307,29 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "prost" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "quick-error" version = "1.2.3" @@ -5525,6 +5662,16 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "tokio-io-timeout" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" +dependencies = [ + "pin-project-lite", + "tokio", +] + [[package]] name = "tokio-macros" version = "2.1.0" @@ -5567,6 +5714,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-stream" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.9" @@ -5582,6 +5740,34 @@ dependencies = [ "tracing", ] +[[package]] +name = "tonic" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3082666a3a6433f7f511c7192923fa1fe07c69332d3c6a2e6bb040b569199d5a" +dependencies = [ + "async-trait", + "axum", + "base64 0.21.4", + "bytes", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-timeout", + "percent-encoding", + "pin-project", + "prost", + "tokio", + "tokio-stream", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "tower" version = "0.4.13" @@ -5590,9 +5776,13 @@ checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" dependencies = [ "futures-core", "futures-util", + "indexmap 1.9.3", "pin-project", "pin-project-lite", + "rand 0.8.5", + "slab", "tokio", + "tokio-util", "tower-layer", "tower-service", "tracing", @@ -5679,6 +5869,22 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-opentelemetry" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75327c6b667828ddc28f5e3f169036cb793c3f588d83bf0f262a7f062ffed3c8" +dependencies = [ + "once_cell", + "opentelemetry", + "opentelemetry_sdk", + "smallvec", + "tracing", + "tracing-core", + "tracing-log", + "tracing-subscriber", +] + [[package]] name = "tracing-subscriber" version = "0.3.17" @@ -5911,6 +6117,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + [[package]] name = "utf8parse" version = "0.2.1" diff --git a/core/src/muxing/boxed.rs b/core/src/muxing/boxed.rs index e909fb9fbf1..b0781856d0d 100644 --- a/core/src/muxing/boxed.rs +++ b/core/src/muxing/boxed.rs @@ -43,6 +43,7 @@ where type Substream = SubstreamBox; type Error = io::Error; + #[tracing::instrument(level = "info", name = "StreamMuxer::poll_inbound", skip(self, cx))] fn poll_inbound( self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -54,6 +55,7 @@ where .map_err(into_io_error) } + #[tracing::instrument(level = "info", name = "StreamMuxer::poll_outbound", skip(self, cx))] fn poll_outbound( self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -66,10 +68,12 @@ where } #[inline] + #[tracing::instrument(level = "info", name = "StreamMuxer::poll_close", skip(self, cx))] fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { self.project().inner.poll_close(cx).map_err(into_io_error) } + #[tracing::instrument(level = "info", name = "StreamMuxer::poll", skip(self, cx))] fn poll( self: Pin<&mut Self>, cx: &mut Context<'_>, diff --git a/examples/metrics/Cargo.toml b/examples/metrics/Cargo.toml index a5f59088095..0cf155718ee 100644 --- a/examples/metrics/Cargo.toml +++ b/examples/metrics/Cargo.toml @@ -11,10 +11,14 @@ release = false [dependencies] futures = "0.3.27" hyper = { version = "0.14", features = ["server", "tcp", "http1"] } -libp2p = { path = "../../libp2p", features = ["async-std", "metrics", "ping", "noise", "identify", "tcp", "yamux", "macros"] } -tokio = { version = "1", features = ["rt-multi-thread"] } +libp2p = { path = "../../libp2p", features = ["tokio", "metrics", "ping", "noise", "identify", "tcp", "yamux", "macros"] } +opentelemetry = { version = "0.20.0", features = ["rt-tokio", "metrics"] } +opentelemetry-otlp = { version = "0.13.0", features = ["metrics"]} +opentelemetry_api = "0.20.0" prometheus-client = "0.21.2" +tokio = { version = "1", features = ["full"] } tracing = "0.1.37" +tracing-opentelemetry = "0.21.0" tracing-subscriber = { version = "0.3", features = ["env-filter"] } [lints] diff --git a/examples/metrics/README.md b/examples/metrics/README.md index fc73cbd7410..69732a0db45 100644 --- a/examples/metrics/README.md +++ b/examples/metrics/README.md @@ -1,6 +1,6 @@ ## Description -The example showcases how to run a p2p network with **libp2p** and collect metrics using `libp2p-metrics`. +The example showcases how to run a p2p network with **libp2p** and collect metrics using `libp2p-metrics` as well as span data via `opentelemetry`. It sets up multiple nodes in the network and measures various metrics, such as `libp2p_ping`, to evaluate the network's performance. ## Usage @@ -10,13 +10,13 @@ To run the example, follow these steps: 1. Run the following command to start the first node: ```sh - cargo run + RUST_LOG=info cargo run ``` 2. Open a second terminal and run the following command to start a second node: ```sh - cargo run -- + RUST_LOG=info cargo run -- ``` Replace `` with the listen address of the first node reported in the first terminal. @@ -34,6 +34,16 @@ To run the example, follow these steps: After executing the command, you should see a long list of metrics printed to the terminal. Make sure to check the `libp2p_ping` metrics, which should have a value greater than zero (`>0`). +## Opentelemetry + +To see the span data collected as part of the `Swarm`s activity, start up an opentelemetry collector: + +```sh +docker compose up +``` + + + ## Conclusion This example demonstrates how to utilize the `libp2p-metrics` crate to collect and analyze metrics in a libp2p network. diff --git a/examples/metrics/docker-compose.yml b/examples/metrics/docker-compose.yml new file mode 100644 index 00000000000..06d8d5becfe --- /dev/null +++ b/examples/metrics/docker-compose.yml @@ -0,0 +1,23 @@ +version: "2" +services: + # Jaeger + jaeger-all-in-one: + image: jaegertracing/all-in-one:latest + restart: always + ports: + - "16686:16686" + - "14268" + - "14250" + + # Collector + otel-collector: + image: otel/opentelemetry-collector:0.88.0 + restart: always + command: ["--config=/etc/otel-collector-config.yaml"] + volumes: + - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml + ports: + - "13133:13133" # health_check extension + - "4317:4317" # OTLP gRPC receiver + depends_on: + - jaeger-all-in-one diff --git a/examples/metrics/otel-collector-config.yaml b/examples/metrics/otel-collector-config.yaml new file mode 100644 index 00000000000..8755848cd6e --- /dev/null +++ b/examples/metrics/otel-collector-config.yaml @@ -0,0 +1,25 @@ +receivers: + otlp: + protocols: + grpc: + endpoint: 0.0.0.0:4317 + +exporters: + debug: + otlp: + endpoint: jaeger-all-in-one:4317 + tls: + insecure: true + +processors: + batch: + +service: + telemetry: + logs: + level: "debug" + pipelines: + traces: + receivers: [otlp] + processors: [batch] + exporters: [debug, otlp] diff --git a/examples/metrics/src/http_service.rs b/examples/metrics/src/http_service.rs index b1d64e8a76a..ac4a39a9c2a 100644 --- a/examples/metrics/src/http_service.rs +++ b/examples/metrics/src/http_service.rs @@ -34,16 +34,12 @@ pub(crate) async fn metrics_server(registry: Registry) -> Result<(), std::io::Er // Serve on localhost. let addr = ([127, 0, 0, 1], 8080).into(); - // Use the tokio runtime to run the hyper server. - let rt = tokio::runtime::Runtime::new()?; - rt.block_on(async { - let server = Server::bind(&addr).serve(MakeMetricService::new(registry)); - tracing::info!(metrics_server=%format!("http://{}/metrics", server.local_addr())); - if let Err(e) = server.await { - tracing::error!("server error: {}", e); - } - Ok(()) - }) + let server = Server::bind(&addr).serve(MakeMetricService::new(registry)); + tracing::info!(metrics_server=%format!("http://{}/metrics", server.local_addr())); + if let Err(e) = server.await { + tracing::error!("server error: {}", e); + } + Ok(()) } pub(crate) struct MetricService { diff --git a/examples/metrics/src/main.rs b/examples/metrics/src/main.rs index 0f0b366b166..18db1084d2f 100644 --- a/examples/metrics/src/main.rs +++ b/examples/metrics/src/main.rs @@ -20,30 +20,28 @@ #![doc = include_str!("../README.md")] -use futures::{executor::block_on, StreamExt}; +use futures::StreamExt; use libp2p::core::Multiaddr; use libp2p::metrics::{Metrics, Recorder}; use libp2p::swarm::{NetworkBehaviour, SwarmEvent}; use libp2p::{identify, identity, noise, ping, tcp, yamux}; +use opentelemetry::sdk; +use opentelemetry_api::KeyValue; use prometheus_client::registry::Registry; use std::error::Error; -use std::thread; use std::time::Duration; -use tracing_subscriber::{filter::LevelFilter, EnvFilter}; +use tracing_subscriber::layer::SubscriberExt; +use tracing_subscriber::util::SubscriberInitExt; +use tracing_subscriber::{EnvFilter, Layer}; mod http_service; -fn main() -> Result<(), Box> { - let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::DEBUG.into()) - .from_env_lossy(); - - let _ = tracing_subscriber::fmt() - .with_env_filter(env_filter) - .try_init(); +#[tokio::main] +async fn main() -> Result<(), Box> { + setup_tracing()?; let mut swarm = libp2p::SwarmBuilder::with_new_identity() - .with_async_std() + .with_tokio() .with_tcp( tcp::Config::default(), noise::Config::new, @@ -63,26 +61,47 @@ fn main() -> Result<(), Box> { let mut metric_registry = Registry::default(); let metrics = Metrics::new(&mut metric_registry); - thread::spawn(move || block_on(http_service::metrics_server(metric_registry))); + tokio::spawn(http_service::metrics_server(metric_registry)); - block_on(async { - loop { - match swarm.select_next_some().await { - SwarmEvent::Behaviour(BehaviourEvent::Ping(ping_event)) => { - tracing::info!(?ping_event); - metrics.record(&ping_event); - } - SwarmEvent::Behaviour(BehaviourEvent::Identify(identify_event)) => { - tracing::info!(?identify_event); - metrics.record(&identify_event); - } - swarm_event => { - tracing::info!(?swarm_event); - metrics.record(&swarm_event); - } + loop { + match swarm.select_next_some().await { + SwarmEvent::Behaviour(BehaviourEvent::Ping(ping_event)) => { + tracing::info!(?ping_event); + metrics.record(&ping_event); + } + SwarmEvent::Behaviour(BehaviourEvent::Identify(identify_event)) => { + tracing::info!(?identify_event); + metrics.record(&identify_event); + } + swarm_event => { + tracing::info!(?swarm_event); + metrics.record(&swarm_event); } } - }); + } +} + +fn setup_tracing() -> Result<(), Box> { + let tracer = opentelemetry_otlp::new_pipeline() + .tracing() + .with_exporter(opentelemetry_otlp::new_exporter().tonic()) + .with_trace_config( + sdk::trace::Config::default().with_resource(sdk::Resource::new(vec![KeyValue::new( + "service.name", + "libp2p", + )])), + ) + .install_batch(opentelemetry::runtime::Tokio)?; + + tracing_subscriber::registry() + .with(tracing_subscriber::fmt::layer().with_filter(EnvFilter::from_default_env())) + .with( + tracing_opentelemetry::layer() + .with_tracer(tracer) + .with_filter(EnvFilter::from_default_env()), + ) + .try_init()?; + Ok(()) } diff --git a/protocols/identify/src/handler.rs b/protocols/identify/src/handler.rs index 82d9ac8e7e6..1cf1d645d0c 100644 --- a/protocols/identify/src/handler.rs +++ b/protocols/identify/src/handler.rs @@ -326,6 +326,7 @@ impl ConnectionHandler for Handler { KeepAlive::No } + #[tracing::instrument(level = "info", name = "identify::Handler::poll", skip(self, cx))] fn poll( &mut self, cx: &mut Context<'_>, diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index f5de5f7325f..57a7c249255 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -225,6 +225,7 @@ impl ConnectionHandler for Handler { KeepAlive::No } + #[tracing::instrument(level = "info", name = "ping::Handler::poll", skip(self, cx))] fn poll( &mut self, cx: &mut Context<'_>, diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index a10f82a474f..85b9ea1e191 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -60,7 +60,6 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::task::Waker; use std::time::Duration; use std::{fmt, io, mem, pin::Pin, task::Context, task::Poll}; -use tracing::Span; static NEXT_CONNECTION_ID: AtomicUsize = AtomicUsize::new(1); @@ -158,7 +157,9 @@ where local_supported_protocols: HashSet, remote_supported_protocols: HashSet, idle_timeout: Duration, - span: Span, + connection_id: ConnectionId, + remote_peer_id: PeerId, + remote_addr: Multiaddr, } impl fmt::Debug for Connection @@ -181,13 +182,16 @@ where { /// Builds a new `Connection` from the given substream multiplexer /// and connection handler. + #[allow(clippy::too_many_arguments)] pub(crate) fn new( muxer: StreamMuxerBox, mut handler: THandler, substream_upgrade_protocol_override: Option, max_negotiating_inbound_streams: usize, idle_timeout: Duration, - span: Span, + connection_id: ConnectionId, + remote_peer_id: PeerId, + remote_addr: Multiaddr, ) -> Self { let initial_protocols = gather_supported_protocols(&handler); if !initial_protocols.is_empty() { @@ -207,7 +211,9 @@ where local_supported_protocols: initial_protocols, remote_supported_protocols: Default::default(), idle_timeout, - span, + connection_id, + remote_peer_id, + remote_addr, } } @@ -224,6 +230,7 @@ where /// Polls the handler and the substream, forwarding events from the former to the latter and /// vice versa. + #[tracing::instrument(level = "info", name = "Connection::poll", skip(self, cx), fields(id = %self.connection_id, peer = %self.remote_peer_id, remote_address = %self.remote_addr))] pub(crate) fn poll( self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -240,10 +247,9 @@ where local_supported_protocols: supported_protocols, remote_supported_protocols, idle_timeout, - span, + .. } = self.get_mut(); - let _guard = span.enter(); loop { match requested_substreams.poll_next_unpin(cx) { Poll::Ready(Some(Ok(()))) => continue, @@ -790,7 +796,9 @@ mod tests { None, max_negotiating_inbound_streams, Duration::ZERO, - tracing::Span::none(), + ConnectionId::new_unchecked(0), + PeerId::random(), + Multiaddr::empty(), ); let result = connection.poll_noop_waker(); @@ -815,7 +823,9 @@ mod tests { None, 2, Duration::ZERO, - tracing::Span::none(), + ConnectionId::new_unchecked(0), + PeerId::random(), + Multiaddr::empty(), ); connection.handler.open_new_outbound(); @@ -839,7 +849,9 @@ mod tests { None, 0, Duration::ZERO, - tracing::Span::none(), + ConnectionId::new_unchecked(0), + PeerId::random(), + Multiaddr::empty(), ); // First, start listening on a single protocol. @@ -879,7 +891,9 @@ mod tests { None, 0, Duration::ZERO, - tracing::Span::none(), + ConnectionId::new_unchecked(0), + PeerId::random(), + Multiaddr::empty(), ); // First, remote supports a single protocol. @@ -933,7 +947,9 @@ mod tests { None, 0, idle_timeout, - tracing::Span::none(), + ConnectionId::new_unchecked(0), + PeerId::random(), + Multiaddr::empty(), ); assert!(connection.poll_noop_waker().is_pending()); @@ -958,7 +974,9 @@ mod tests { None, 0, idle_timeout, - tracing::Span::none(), + ConnectionId::new_unchecked(0), + PeerId::random(), + Multiaddr::empty(), ); assert!(connection.poll_noop_waker().is_pending()); @@ -990,7 +1008,9 @@ mod tests { None, 0, idle_timeout, - tracing::Span::none(), + ConnectionId::new_unchecked(0), + PeerId::random(), + Multiaddr::empty(), ); assert!(connection.poll_noop_waker().is_pending()); diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index 37e7153e98e..f98793b3e46 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -516,14 +516,15 @@ where waker.wake(); } - let span = tracing::error_span!("Connection::poll", id = %id, peer = %obtained_peer_id, remote_address = %endpoint.get_remote_address()); let connection = Connection::new( connection, handler, self.substream_upgrade_protocol_override, self.max_negotiating_inbound_streams, self.idle_connection_timeout, - span, + id, + obtained_peer_id, + endpoint.get_remote_address().clone(), ); self.executor.spawn(task::new_for_established_connection( diff --git a/swarm/src/handler/select.rs b/swarm/src/handler/select.rs index 65db4ab525b..b953ff7dc3d 100644 --- a/swarm/src/handler/select.rs +++ b/swarm/src/handler/select.rs @@ -215,6 +215,7 @@ where ) } + #[tracing::instrument(level = "info", name = "ConnectionHandlerSelect::poll", skip(self, cx), fields(first = %std::any::type_name::(), second = %std::any::type_name::()))] fn poll( &mut self, cx: &mut Context<'_>, From 70a8e266cc8df46215892c192c5d42e59005d323 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 25 Oct 2023 15:47:07 +1100 Subject: [PATCH 077/105] Add more docs --- examples/metrics/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/metrics/README.md b/examples/metrics/README.md index 69732a0db45..620166dc8e2 100644 --- a/examples/metrics/README.md +++ b/examples/metrics/README.md @@ -42,7 +42,8 @@ To see the span data collected as part of the `Swarm`s activity, start up an ope docker compose up ``` - +Next, (re)-start the two example for it to connect to the OTEL collector. +Finally, open the Jaeger UI in a browser and explore the spans: http://localhost:16686. ## Conclusion From 8839f368c8e316240496482c78391a46591b81ae Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 25 Oct 2023 15:49:50 +1100 Subject: [PATCH 078/105] Remove span from select --- swarm/src/handler/select.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/swarm/src/handler/select.rs b/swarm/src/handler/select.rs index b953ff7dc3d..65db4ab525b 100644 --- a/swarm/src/handler/select.rs +++ b/swarm/src/handler/select.rs @@ -215,7 +215,6 @@ where ) } - #[tracing::instrument(level = "info", name = "ConnectionHandlerSelect::poll", skip(self, cx), fields(first = %std::any::type_name::(), second = %std::any::type_name::()))] fn poll( &mut self, cx: &mut Context<'_>, From 4c574f3b27af6c6798430c0920cace70db0c7c3a Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 25 Oct 2023 16:10:41 +1100 Subject: [PATCH 079/105] Move muxer spans into `Connection` --- core/src/muxing/boxed.rs | 4 ---- examples/metrics/README.md | 32 +++++++++++++++++++++++++++-- protocols/identify/src/behaviour.rs | 1 + protocols/identify/src/handler.rs | 2 +- protocols/ping/src/handler.rs | 2 +- protocols/ping/src/lib.rs | 1 + swarm/src/connection.rs | 32 +++++++++++++++++++++-------- 7 files changed, 57 insertions(+), 17 deletions(-) diff --git a/core/src/muxing/boxed.rs b/core/src/muxing/boxed.rs index b0781856d0d..e909fb9fbf1 100644 --- a/core/src/muxing/boxed.rs +++ b/core/src/muxing/boxed.rs @@ -43,7 +43,6 @@ where type Substream = SubstreamBox; type Error = io::Error; - #[tracing::instrument(level = "info", name = "StreamMuxer::poll_inbound", skip(self, cx))] fn poll_inbound( self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -55,7 +54,6 @@ where .map_err(into_io_error) } - #[tracing::instrument(level = "info", name = "StreamMuxer::poll_outbound", skip(self, cx))] fn poll_outbound( self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -68,12 +66,10 @@ where } #[inline] - #[tracing::instrument(level = "info", name = "StreamMuxer::poll_close", skip(self, cx))] fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { self.project().inner.poll_close(cx).map_err(into_io_error) } - #[tracing::instrument(level = "info", name = "StreamMuxer::poll", skip(self, cx))] fn poll( self: Pin<&mut Self>, cx: &mut Context<'_>, diff --git a/examples/metrics/README.md b/examples/metrics/README.md index 620166dc8e2..e7ded9e5e88 100644 --- a/examples/metrics/README.md +++ b/examples/metrics/README.md @@ -10,13 +10,13 @@ To run the example, follow these steps: 1. Run the following command to start the first node: ```sh - RUST_LOG=info cargo run + cargo run ``` 2. Open a second terminal and run the following command to start a second node: ```sh - RUST_LOG=info cargo run -- + cargo run -- ``` Replace `` with the listen address of the first node reported in the first terminal. @@ -42,9 +42,37 @@ To see the span data collected as part of the `Swarm`s activity, start up an ope docker compose up ``` +Then, configure tracing to output spans: + +```shell +export RUST_LOG=info,[ConnectionHandler::poll]=trace,[NetworkBehaviour::poll]=trace +``` + Next, (re)-start the two example for it to connect to the OTEL collector. Finally, open the Jaeger UI in a browser and explore the spans: http://localhost:16686. +### Filtering spans + +For a precise documentation, please see the following documentation in tracing: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives. + +`rust-libp2p` consistently applies spans to the following functions: + +- `ConnectionHandler::poll` implementations +- `NetworkBehaviour::poll` implementations + +The above spans are all called exactly that: `ConnectionHandler::poll` and `NetworkBehaviour::poll`. +You can activate _all_ of them by setting: + +``` +RUST_LOG=[ConnectionHandler::poll]=trace +``` + +If you just wanted to see the spans of the `libp2p_ping` crate, you can filter like this: + +``` +RUST_LOG=libp2p_ping[ConnectionHandler::poll]=trace +``` + ## Conclusion This example demonstrates how to utilize the `libp2p-metrics` crate to collect and analyze metrics in a libp2p network. diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index 369cfd1adf5..463f4ee7101 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -312,6 +312,7 @@ impl NetworkBehaviour for Behaviour { } } + #[tracing::instrument(level = "trace", name = "NetworkBehaviour::poll", skip(self))] fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { if let Some(event) = self.events.pop_front() { return Poll::Ready(event); diff --git a/protocols/identify/src/handler.rs b/protocols/identify/src/handler.rs index 1cf1d645d0c..96ee90d6629 100644 --- a/protocols/identify/src/handler.rs +++ b/protocols/identify/src/handler.rs @@ -326,7 +326,7 @@ impl ConnectionHandler for Handler { KeepAlive::No } - #[tracing::instrument(level = "info", name = "identify::Handler::poll", skip(self, cx))] + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, cx))] fn poll( &mut self, cx: &mut Context<'_>, diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index 57a7c249255..c6fb06e35bb 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -225,7 +225,7 @@ impl ConnectionHandler for Handler { KeepAlive::No } - #[tracing::instrument(level = "info", name = "ping::Handler::poll", skip(self, cx))] + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, cx))] fn poll( &mut self, cx: &mut Context<'_>, diff --git a/protocols/ping/src/lib.rs b/protocols/ping/src/lib.rs index ec5b7714e5c..892553db1f4 100644 --- a/protocols/ping/src/lib.rs +++ b/protocols/ping/src/lib.rs @@ -141,6 +141,7 @@ impl NetworkBehaviour for Behaviour { }) } + #[tracing::instrument(level = "trace", name = "NetworkBehaviour::poll", skip(self))] fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { if let Some(e) = self.events.pop_back() { Poll::Ready(ToSwarm::GenerateEvent(e)) diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 85b9ea1e191..f7a4f46a6d7 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -60,6 +60,7 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::task::Waker; use std::time::Duration; use std::{fmt, io, mem, pin::Pin, task::Context, task::Poll}; +use tracing::Instrument; static NEXT_CONNECTION_ID: AtomicUsize = AtomicUsize::new(1); @@ -225,12 +226,17 @@ where /// Begins an orderly shutdown of the connection, returning the connection /// handler and a `Future` that resolves when connection shutdown is complete. pub(crate) fn close(self) -> (THandler, impl Future>) { - (self.handler, self.muxing.close()) + ( + self.handler, + self.muxing + .close() + .instrument(tracing::trace_span!("StreamMuxer::poll_close")), + ) } /// Polls the handler and the substream, forwarding events from the former to the latter and /// vice versa. - #[tracing::instrument(level = "info", name = "Connection::poll", skip(self, cx), fields(id = %self.connection_id, peer = %self.remote_peer_id, remote_address = %self.remote_addr))] + #[tracing::instrument(level = "debug", name = "Connection::poll", skip(self, cx), fields(id = %self.connection_id, peer = %self.remote_peer_id, remote_address = %self.remote_addr))] pub(crate) fn poll( self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -380,17 +386,23 @@ where } } - match muxing.poll_unpin(cx)? { - Poll::Pending => {} - Poll::Ready(StreamMuxerEvent::AddressChange(address)) => { - handler.on_connection_event(ConnectionEvent::AddressChange(AddressChange { - new_address: &address, - })); - return Poll::Ready(Ok(Event::AddressChange(address))); + { + let _span = tracing::trace_span!("StreamMuxer::poll").entered(); + match muxing.poll_unpin(cx)? { + Poll::Pending => {} + Poll::Ready(StreamMuxerEvent::AddressChange(address)) => { + handler.on_connection_event(ConnectionEvent::AddressChange( + AddressChange { + new_address: &address, + }, + )); + return Poll::Ready(Ok(Event::AddressChange(address))); + } } } if let Some(requested_substream) = requested_substreams.iter_mut().next() { + let _span = tracing::trace_span!("StreamMuxer::poll_outbound").entered(); match muxing.poll_outbound_unpin(cx)? { Poll::Pending => {} Poll::Ready(substream) => { @@ -410,6 +422,8 @@ where } if negotiating_in.len() < *max_negotiating_inbound_streams { + let _span = tracing::trace_span!("StreamMuxer::poll_inbound").entered(); + match muxing.poll_inbound_unpin(cx)? { Poll::Pending => {} Poll::Ready(substream) => { From d5ebef01f059759ad0273bee695efb2bacf71f9c Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 25 Oct 2023 16:13:12 +1100 Subject: [PATCH 080/105] Add spans for `Swarm` --- swarm/src/lib.rs | 60 +++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 90a4de7773e..a27b80b0d05 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -1161,6 +1161,7 @@ where /// Internal function used by everything event-related. /// /// Polls the `Swarm` for the next event. + #[tracing::instrument(level = "debug", name = "Swarm::poll", skip(self, cx))] fn poll_next_event( mut self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -1205,39 +1206,52 @@ where } }, // No pending event. Allow the [`NetworkBehaviour`] to make progress. - None => match this.behaviour.poll(cx) { + None => { + let _span = tracing::trace_span!("NetworkBehaviour::poll").entered(); + + match this.behaviour.poll(cx) { + Poll::Pending => {} + Poll::Ready(behaviour_event) => { + if let Some(swarm_event) = this.handle_behaviour_event(behaviour_event) + { + return Poll::Ready(swarm_event); + } + + continue; + } + } + } + } + + { + let _span = tracing::trace_span!("Pool::poll").entered(); + + // Poll the known peers. + match this.pool.poll(cx) { Poll::Pending => {} - Poll::Ready(behaviour_event) => { - if let Some(swarm_event) = this.handle_behaviour_event(behaviour_event) { + Poll::Ready(pool_event) => { + if let Some(swarm_event) = this.handle_pool_event(pool_event) { return Poll::Ready(swarm_event); } continue; } - }, - } - - // Poll the known peers. - match this.pool.poll(cx) { - Poll::Pending => {} - Poll::Ready(pool_event) => { - if let Some(swarm_event) = this.handle_pool_event(pool_event) { - return Poll::Ready(swarm_event); - } - - continue; } }; - // Poll the listener(s) for new connections. - match Pin::new(&mut this.transport).poll(cx) { - Poll::Pending => {} - Poll::Ready(transport_event) => { - if let Some(swarm_event) = this.handle_transport_event(transport_event) { - return Poll::Ready(swarm_event); - } + { + let _span = tracing::trace_span!("Transport::poll").entered(); + + // Poll the listener(s) for new connections. + match Pin::new(&mut this.transport).poll(cx) { + Poll::Pending => {} + Poll::Ready(transport_event) => { + if let Some(swarm_event) = this.handle_transport_event(transport_event) { + return Poll::Ready(swarm_event); + } - continue; + continue; + } } } From 52048e63ab2bc57239a68c7c3a9cb7b16ba1300b Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 25 Oct 2023 16:13:59 +1100 Subject: [PATCH 081/105] Add local peer id to `Swarm::poll` span --- swarm/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index a27b80b0d05..111ee125431 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -1161,7 +1161,7 @@ where /// Internal function used by everything event-related. /// /// Polls the `Swarm` for the next event. - #[tracing::instrument(level = "debug", name = "Swarm::poll", skip(self, cx))] + #[tracing::instrument(level = "debug", name = "Swarm::poll", skip(self, cx), fields(local_peer_id = %self.local_peer_id))] fn poll_next_event( mut self: Pin<&mut Self>, cx: &mut Context<'_>, From ffe04d422ca7ce990fb52201dd0f04fa1d31bbbf Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 25 Oct 2023 16:35:31 +1100 Subject: [PATCH 082/105] Move spans to concrete `poll` functions --- swarm/src/connection/pool.rs | 1 + swarm/src/lib.rs | 60 +++++++++++++++--------------------- transports/tcp/src/lib.rs | 1 + 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index f98793b3e46..c6d4f6bb06f 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -537,6 +537,7 @@ where } /// Polls the connection pool for events. + #[tracing::instrument(level = "debug", name = "Pool::poll", skip(self, cx))] pub(crate) fn poll(&mut self, cx: &mut Context<'_>) -> Poll> where THandler: ConnectionHandler + 'static, diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 111ee125431..98ee29d8ce7 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -155,6 +155,7 @@ use std::{ pin::Pin, task::{Context, Poll}, }; +use tracing::Span; /// Substream for which a protocol has been chosen. /// @@ -1206,52 +1207,39 @@ where } }, // No pending event. Allow the [`NetworkBehaviour`] to make progress. - None => { - let _span = tracing::trace_span!("NetworkBehaviour::poll").entered(); - - match this.behaviour.poll(cx) { - Poll::Pending => {} - Poll::Ready(behaviour_event) => { - if let Some(swarm_event) = this.handle_behaviour_event(behaviour_event) - { - return Poll::Ready(swarm_event); - } - - continue; - } - } - } - } - - { - let _span = tracing::trace_span!("Pool::poll").entered(); - - // Poll the known peers. - match this.pool.poll(cx) { + None => match this.behaviour.poll(cx) { Poll::Pending => {} - Poll::Ready(pool_event) => { - if let Some(swarm_event) = this.handle_pool_event(pool_event) { + Poll::Ready(behaviour_event) => { + if let Some(swarm_event) = this.handle_behaviour_event(behaviour_event) { return Poll::Ready(swarm_event); } continue; } - } - }; + }, + } - { - let _span = tracing::trace_span!("Transport::poll").entered(); + // Poll the known peers. + match this.pool.poll(cx) { + Poll::Pending => {} + Poll::Ready(pool_event) => { + if let Some(swarm_event) = this.handle_pool_event(pool_event) { + return Poll::Ready(swarm_event); + } - // Poll the listener(s) for new connections. - match Pin::new(&mut this.transport).poll(cx) { - Poll::Pending => {} - Poll::Ready(transport_event) => { - if let Some(swarm_event) = this.handle_transport_event(transport_event) { - return Poll::Ready(swarm_event); - } + continue; + } + } - continue; + // Poll the listener(s) for new connections. + match Pin::new(&mut this.transport).poll(cx) { + Poll::Pending => {} + Poll::Ready(transport_event) => { + if let Some(swarm_event) = this.handle_transport_event(transport_event) { + return Poll::Ready(swarm_event); } + + continue; } } diff --git a/transports/tcp/src/lib.rs b/transports/tcp/src/lib.rs index 6664c9e0b78..b466f387ba4 100644 --- a/transports/tcp/src/lib.rs +++ b/transports/tcp/src/lib.rs @@ -538,6 +538,7 @@ where } /// Poll all listeners. + #[tracing::instrument(level = "trace", name = "Transport::poll", skip(self, cx))] fn poll( mut self: Pin<&mut Self>, cx: &mut Context<'_>, From 5a3514b8d71dcd37eaaafbfed093667144ee5455 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 25 Oct 2023 16:36:55 +1100 Subject: [PATCH 083/105] Move stream muxer spans to concrete impl --- muxers/yamux/src/lib.rs | 4 ++++ swarm/src/connection.rs | 29 ++++++++--------------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/muxers/yamux/src/lib.rs b/muxers/yamux/src/lib.rs index e1c618fd843..d10cdfa244c 100644 --- a/muxers/yamux/src/lib.rs +++ b/muxers/yamux/src/lib.rs @@ -81,6 +81,7 @@ where type Substream = Stream; type Error = Error; + #[tracing::instrument(level = "trace", name = "StreamMuxer::poll_inbound", skip(self, cx))] fn poll_inbound( mut self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -97,6 +98,7 @@ where Poll::Pending } + #[tracing::instrument(level = "trace", name = "StreamMuxer::poll_outbound", skip(self, cx))] fn poll_outbound( mut self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -106,12 +108,14 @@ where Poll::Ready(Ok(Stream(stream))) } + #[tracing::instrument(level = "trace", name = "StreamMuxer::poll_close", skip(self, cx))] fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { ready!(self.connection.poll_close(cx).map_err(Error)?); Poll::Ready(Ok(())) } + #[tracing::instrument(level = "trace", name = "StreamMuxer::poll", skip(self, cx))] fn poll( self: Pin<&mut Self>, cx: &mut Context<'_>, diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index f7a4f46a6d7..eb146339564 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -226,12 +226,7 @@ where /// Begins an orderly shutdown of the connection, returning the connection /// handler and a `Future` that resolves when connection shutdown is complete. pub(crate) fn close(self) -> (THandler, impl Future>) { - ( - self.handler, - self.muxing - .close() - .instrument(tracing::trace_span!("StreamMuxer::poll_close")), - ) + (self.handler, self.muxing.close()) } /// Polls the handler and the substream, forwarding events from the former to the latter and @@ -386,23 +381,17 @@ where } } - { - let _span = tracing::trace_span!("StreamMuxer::poll").entered(); - match muxing.poll_unpin(cx)? { - Poll::Pending => {} - Poll::Ready(StreamMuxerEvent::AddressChange(address)) => { - handler.on_connection_event(ConnectionEvent::AddressChange( - AddressChange { - new_address: &address, - }, - )); - return Poll::Ready(Ok(Event::AddressChange(address))); - } + match muxing.poll_unpin(cx)? { + Poll::Pending => {} + Poll::Ready(StreamMuxerEvent::AddressChange(address)) => { + handler.on_connection_event(ConnectionEvent::AddressChange(AddressChange { + new_address: &address, + })); + return Poll::Ready(Ok(Event::AddressChange(address))); } } if let Some(requested_substream) = requested_substreams.iter_mut().next() { - let _span = tracing::trace_span!("StreamMuxer::poll_outbound").entered(); match muxing.poll_outbound_unpin(cx)? { Poll::Pending => {} Poll::Ready(substream) => { @@ -422,8 +411,6 @@ where } if negotiating_in.len() < *max_negotiating_inbound_streams { - let _span = tracing::trace_span!("StreamMuxer::poll_inbound").entered(); - match muxing.poll_inbound_unpin(cx)? { Poll::Pending => {} Poll::Ready(substream) => { From ccf60a45a5b37946519322dfcdca6b132783277b Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 25 Oct 2023 16:39:57 +1100 Subject: [PATCH 084/105] Remove unused imports --- swarm/src/connection.rs | 1 - swarm/src/lib.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index eb146339564..955f2406ed1 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -60,7 +60,6 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::task::Waker; use std::time::Duration; use std::{fmt, io, mem, pin::Pin, task::Context, task::Poll}; -use tracing::Instrument; static NEXT_CONNECTION_ID: AtomicUsize = AtomicUsize::new(1); diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 98ee29d8ce7..684226f35c1 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -155,7 +155,6 @@ use std::{ pin::Pin, task::{Context, Poll}, }; -use tracing::Span; /// Substream for which a protocol has been chosen. /// From 20beaadfd0f2fe66f7d04f4cf5c2088a5ec255a6 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 25 Oct 2023 16:52:34 +1100 Subject: [PATCH 085/105] Instrument dialing of new connections --- swarm/src/connection/pool.rs | 26 +++++++++++++++----------- swarm/src/lib.rs | 14 +++++++++++--- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index c6d4f6bb06f..a2df1ff7d00 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -49,6 +49,7 @@ use std::{ task::Context, task::Poll, }; +use tracing::Instrument; use void::Void; mod concurrent_dial; @@ -426,20 +427,21 @@ where dial_concurrency_factor_override: Option, connection_id: ConnectionId, ) { - let dial = ConcurrentDial::new( - dials, - dial_concurrency_factor_override.unwrap_or(self.dial_concurrency_factor), - ); + let concurrency_factor = + dial_concurrency_factor_override.unwrap_or(self.dial_concurrency_factor); + let span = tracing::debug_span!("new_outgoing_connection", %concurrency_factor, num_dials=%dials.len(), id = %connection_id); let (abort_notifier, abort_receiver) = oneshot::channel(); - self.executor - .spawn(task::new_for_pending_outgoing_connection( + self.executor.spawn( + task::new_for_pending_outgoing_connection( connection_id, - dial, + ConcurrentDial::new(dials, concurrency_factor), abort_receiver, self.pending_connection_events_tx.clone(), - )); + ) + .instrument(span), + ); let endpoint = PendingPoint::Dialer { role_override }; @@ -469,13 +471,15 @@ where let (abort_notifier, abort_receiver) = oneshot::channel(); - self.executor - .spawn(task::new_for_pending_incoming_connection( + self.executor.spawn( + task::new_for_pending_incoming_connection( connection_id, future, abort_receiver, self.pending_connection_events_tx.clone(), - )); + ) + .instrument(tracing::debug_span!("new_incoming_connection", remote_addr = %info.send_back_addr, id = %connection_id)), + ); self.counters.inc_pending_incoming(); self.pending.insert( diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 684226f35c1..3fc963ed26d 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -155,6 +155,7 @@ use std::{ pin::Pin, task::{Context, Poll}, }; +use tracing::Instrument; /// Substream for which a protocol has been chosen. /// @@ -529,13 +530,20 @@ where .into_iter() .map(|a| match p2p_addr(peer_id, a) { Ok(address) => { - let dial = match dial_opts.role_override() { - Endpoint::Dialer => self.transport.dial(address.clone()), - Endpoint::Listener => self.transport.dial_as_listener(address.clone()), + let (dial, span) = match dial_opts.role_override() { + Endpoint::Dialer => ( + self.transport.dial(address.clone()), + tracing::debug_span!("Transport::dial", %address), + ), + Endpoint::Listener => ( + self.transport.dial_as_listener(address.clone()), + tracing::debug_span!("Transport::dial_as_listener", %address), + ), }; match dial { Ok(fut) => fut .map(|r| (address, r.map_err(TransportError::Other))) + .instrument(span) .boxed(), Err(err) => futures::future::ready((address, Err(err))).boxed(), } From fee64854cab1d0426379a0b42603c39afeb12d73 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 25 Oct 2023 17:00:33 +1100 Subject: [PATCH 086/105] Remove parents These spans are going to spawned into an executor so they shouldn't prolong the span they are started in. --- swarm/src/connection/pool.rs | 4 ++-- swarm/src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index a2df1ff7d00..c8e609cb008 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -429,7 +429,7 @@ where ) { let concurrency_factor = dial_concurrency_factor_override.unwrap_or(self.dial_concurrency_factor); - let span = tracing::debug_span!("new_outgoing_connection", %concurrency_factor, num_dials=%dials.len(), id = %connection_id); + let span = tracing::debug_span!(parent: tracing::Span::none(), "new_outgoing_connection", %concurrency_factor, num_dials=%dials.len(), id = %connection_id); let (abort_notifier, abort_receiver) = oneshot::channel(); @@ -478,7 +478,7 @@ where abort_receiver, self.pending_connection_events_tx.clone(), ) - .instrument(tracing::debug_span!("new_incoming_connection", remote_addr = %info.send_back_addr, id = %connection_id)), + .instrument(tracing::debug_span!(parent: tracing::Span::none(), "new_incoming_connection", remote_addr = %info.send_back_addr, id = %connection_id)), ); self.counters.inc_pending_incoming(); diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 3fc963ed26d..0f5754ea0a5 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -533,11 +533,11 @@ where let (dial, span) = match dial_opts.role_override() { Endpoint::Dialer => ( self.transport.dial(address.clone()), - tracing::debug_span!("Transport::dial", %address), + tracing::debug_span!(parent: tracing::Span::none(), "Transport::dial", %address), ), Endpoint::Listener => ( self.transport.dial_as_listener(address.clone()), - tracing::debug_span!("Transport::dial_as_listener", %address), + tracing::debug_span!(parent: tracing::Span::none(), "Transport::dial_as_listener", %address), ), }; match dial { From eac2630424f4c0ffcf58327ff1afe6822198cb50 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 25 Oct 2023 17:03:19 +1100 Subject: [PATCH 087/105] Set `follows_from` instead --- swarm/src/connection/pool.rs | 6 +++++- swarm/src/lib.rs | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index c8e609cb008..7ee34d5bc3b 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -430,6 +430,7 @@ where let concurrency_factor = dial_concurrency_factor_override.unwrap_or(self.dial_concurrency_factor); let span = tracing::debug_span!(parent: tracing::Span::none(), "new_outgoing_connection", %concurrency_factor, num_dials=%dials.len(), id = %connection_id); + span.follows_from(tracing::Span::current()); let (abort_notifier, abort_receiver) = oneshot::channel(); @@ -471,6 +472,9 @@ where let (abort_notifier, abort_receiver) = oneshot::channel(); + let span = tracing::debug_span!(parent: tracing::Span::none(), "new_incoming_connection", remote_addr = %info.send_back_addr, id = %connection_id); + span.follows_from(tracing::Span::current()); + self.executor.spawn( task::new_for_pending_incoming_connection( connection_id, @@ -478,7 +482,7 @@ where abort_receiver, self.pending_connection_events_tx.clone(), ) - .instrument(tracing::debug_span!(parent: tracing::Span::none(), "new_incoming_connection", remote_addr = %info.send_back_addr, id = %connection_id)), + .instrument(span), ); self.counters.inc_pending_incoming(); diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 0f5754ea0a5..37271e5702f 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -540,6 +540,8 @@ where tracing::debug_span!(parent: tracing::Span::none(), "Transport::dial_as_listener", %address), ), }; + span.follows_from(tracing::Span::current()); + match dial { Ok(fut) => fut .map(|r| (address, r.map_err(TransportError::Other))) From d6e8eb7733a9b42abecc8de7a6cf6370a9d0412f Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 25 Oct 2023 17:30:18 +1100 Subject: [PATCH 088/105] Fix doc link --- examples/metrics/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/metrics/README.md b/examples/metrics/README.md index e7ded9e5e88..160536985f1 100644 --- a/examples/metrics/README.md +++ b/examples/metrics/README.md @@ -53,7 +53,7 @@ Finally, open the Jaeger UI in a browser and explore the spans: http://localhost ### Filtering spans -For a precise documentation, please see the following documentation in tracing: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives. +For a precise documentation, please see the following documentation in tracing: . `rust-libp2p` consistently applies spans to the following functions: From 40c75177ce1257ac5e23f126efcc26054fa00949 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 25 Oct 2023 17:39:44 +1100 Subject: [PATCH 089/105] Fix libp2p doc tests --- libp2p/src/tutorials/ping.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libp2p/src/tutorials/ping.rs b/libp2p/src/tutorials/ping.rs index a00a1645cac..cd47f8beb81 100644 --- a/libp2p/src/tutorials/ping.rs +++ b/libp2p/src/tutorials/ping.rs @@ -72,10 +72,11 @@ //! //! ```rust //! use std::error::Error; +//! use tracing_subscriber::EnvFilter; //! //! #[async_std::main] //! async fn main() -> Result<(), Box> { -//! env_logger::init(); +//! tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); //! //! let mut swarm = libp2p::SwarmBuilder::with_new_identity(); //! @@ -96,10 +97,11 @@ //! ```rust //! use libp2p::{identity, PeerId}; //! use std::error::Error; +//! use tracing_subscriber::EnvFilter; //! //! #[async_std::main] //! async fn main() -> Result<(), Box> { -//! env_logger::init(); +//! tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); //! //! let mut swarm = libp2p::SwarmBuilder::with_new_identity() //! .with_async_std() @@ -139,6 +141,7 @@ //! use libp2p::swarm::NetworkBehaviour; //! use libp2p::{identity, ping, PeerId}; //! use std::error::Error; +//! use tracing_subscriber::EnvFilter; //! //! #[async_std::main] //! async fn main() -> Result<(), Box> { @@ -165,7 +168,7 @@ //! to the [`Transport`] as well as events from the [`Transport`] to the [`NetworkBehaviour`]. //! //! ```rust -//! use libp2p::swarm::{NetworkBehaviour, SwarmBuilder}; +//! use libp2p::swarm::NetworkBehaviour; //! use libp2p::{identity, ping, PeerId}; //! use std::error::Error; //! use tracing_subscriber::EnvFilter; @@ -199,10 +202,11 @@ //! Thus, without any other behaviour in place, we would not be able to observe the pings. //! //! ```rust -//! use libp2p::swarm::{NetworkBehaviour, SwarmBuilder}; +//! use libp2p::swarm::NetworkBehaviour; //! use libp2p::{identity, ping, PeerId}; //! use std::error::Error; //! use std::time::Duration; +//! use tracing_subscriber::EnvFilter; //! //! #[async_std::main] //! async fn main() -> Result<(), Box> { @@ -250,7 +254,7 @@ //! remote peer. //! //! ```rust -//! use libp2p::swarm::{NetworkBehaviour, SwarmBuilder}; +//! use libp2p::swarm::NetworkBehaviour; //! use libp2p::{identity, ping, Multiaddr, PeerId}; //! use std::error::Error; //! use std::time::Duration; @@ -295,13 +299,13 @@ //! //! ```no_run //! use futures::prelude::*; -//! use libp2p::swarm::{NetworkBehaviour, SwarmEvent, SwarmBuilder}; +//! use libp2p::swarm::{NetworkBehaviour, SwarmEvent}; //! use libp2p::{identity, ping, Multiaddr, PeerId}; //! use std::error::Error; //! use std::time::Duration; //! use tracing_subscriber::EnvFilter; //! -//! #[async_std::main] +//! #[async_std::main]F //! async fn main() -> Result<(), Box> { //! tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); //! From c6e2222a262e8c0efcfae3b26dab38acf4e38f03 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 25 Oct 2023 17:39:54 +1100 Subject: [PATCH 090/105] Fix bad char --- libp2p/src/tutorials/ping.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libp2p/src/tutorials/ping.rs b/libp2p/src/tutorials/ping.rs index cd47f8beb81..7b81459bb85 100644 --- a/libp2p/src/tutorials/ping.rs +++ b/libp2p/src/tutorials/ping.rs @@ -305,7 +305,7 @@ //! use std::time::Duration; //! use tracing_subscriber::EnvFilter; //! -//! #[async_std::main]F +//! #[async_std::main] //! async fn main() -> Result<(), Box> { //! tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); //! From c75d2659c425d5291a7953d1e860ad54d64a455f Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 31 Oct 2023 12:14:07 +1100 Subject: [PATCH 091/105] Fix formatting --- examples/open-telemetry/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/open-telemetry/src/main.rs b/examples/open-telemetry/src/main.rs index 22a3c58bd61..7457b0a818a 100644 --- a/examples/open-telemetry/src/main.rs +++ b/examples/open-telemetry/src/main.rs @@ -102,7 +102,7 @@ async fn main() -> Result<(), Box> { let _ = tracing_subscriber::fmt() .with_env_filter(env_filter) .try_init(); - + init_telemetry().await?; let local_key = identity::Keypair::generate_ed25519(); From 4874464663202d7576b70f37ca449afada657e72 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 31 Oct 2023 12:17:26 +1100 Subject: [PATCH 092/105] Fix compile errors and delete otel-example --- Cargo.lock | 233 ++------------------ Cargo.toml | 1 - examples/open-telemetry/Cargo.toml | 18 -- examples/open-telemetry/DOCKERFILE | 30 --- examples/open-telemetry/docker-compose.yaml | 46 ---- examples/open-telemetry/src/main.rs | 145 ------------ protocols/identify/tests/smoke.rs | 4 +- swarm-test/src/lib.rs | 4 +- 8 files changed, 22 insertions(+), 459 deletions(-) delete mode 100644 examples/open-telemetry/Cargo.toml delete mode 100644 examples/open-telemetry/DOCKERFILE delete mode 100644 examples/open-telemetry/docker-compose.yaml delete mode 100644 examples/open-telemetry/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index d156fcadb0b..bc39a19e552 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -415,28 +415,6 @@ dependencies = [ "trust-dns-resolver", ] -[[package]] -name = "async-stream" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" -dependencies = [ - "async-stream-impl", - "futures-core", - "pin-project-lite", -] - -[[package]] -name = "async-stream-impl" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - [[package]] name = "async-task" version = "4.4.0" @@ -1216,19 +1194,6 @@ dependencies = [ "syn 2.0.38", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown 0.14.0", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "data-encoding" version = "2.4.0" @@ -3551,13 +3516,13 @@ dependencies = [ "futures", "hyper", "libp2p", - "opentelemetry 0.20.0", - "opentelemetry-otlp 0.13.0", - "opentelemetry_api 0.20.0", + "opentelemetry", + "opentelemetry-otlp", + "opentelemetry_api", "prometheus-client", "tokio", "tracing", - "tracing-opentelemetry 0.21.0", + "tracing-opentelemetry", "tracing-subscriber", ] @@ -3885,22 +3850,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" -[[package]] -name = "open-telemetry-example" -version = "0.1.0" -dependencies = [ - "async-std", - "async-trait", - "futures", - "libp2p", - "opentelemetry 0.19.0", - "opentelemetry-otlp 0.12.0", - "tokio", - "tracing", - "tracing-opentelemetry 0.19.0", - "tracing-subscriber", -] - [[package]] name = "openssl" version = "0.10.55" @@ -3945,42 +3894,14 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "opentelemetry" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f4b8347cc26099d3aeee044065ecc3ae11469796b4d65d065a23a584ed92a6f" -dependencies = [ - "opentelemetry_api 0.19.0", - "opentelemetry_sdk 0.19.0", -] - [[package]] name = "opentelemetry" version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9591d937bc0e6d2feb6f71a559540ab300ea49955229c347a517a28d27784c54" dependencies = [ - "opentelemetry_api 0.20.0", - "opentelemetry_sdk 0.20.0", -] - -[[package]] -name = "opentelemetry-otlp" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8af72d59a4484654ea8eb183fea5ae4eb6a41d7ac3e3bae5f4d2a282a3a7d3ca" -dependencies = [ - "async-trait", - "futures", - "futures-util", - "http", - "opentelemetry 0.19.0", - "opentelemetry-proto 0.2.0", - "prost", - "thiserror", - "tokio", - "tonic 0.8.3", + "opentelemetry_api", + "opentelemetry_sdk", ] [[package]] @@ -3992,27 +3913,14 @@ dependencies = [ "async-trait", "futures-core", "http", - "opentelemetry-proto 0.3.0", + "opentelemetry-proto", "opentelemetry-semantic-conventions", - "opentelemetry_api 0.20.0", - "opentelemetry_sdk 0.20.0", + "opentelemetry_api", + "opentelemetry_sdk", "prost", "thiserror", "tokio", - "tonic 0.9.2", -] - -[[package]] -name = "opentelemetry-proto" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "045f8eea8c0fa19f7d48e7bc3128a39c2e5c533d5c61298c548dfefc1064474c" -dependencies = [ - "futures", - "futures-util", - "opentelemetry 0.19.0", - "prost", - "tonic 0.8.3", + "tonic", ] [[package]] @@ -4021,10 +3929,10 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1e3f814aa9f8c905d0ee4bde026afd3b2577a97c10e1699912e3e44f0c4cbeb" dependencies = [ - "opentelemetry_api 0.20.0", - "opentelemetry_sdk 0.20.0", + "opentelemetry_api", + "opentelemetry_sdk", "prost", - "tonic 0.9.2", + "tonic", ] [[package]] @@ -4033,23 +3941,7 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73c9f9340ad135068800e7f1b24e9e09ed9e7143f5bf8518ded3d3ec69789269" dependencies = [ - "opentelemetry 0.20.0", -] - -[[package]] -name = "opentelemetry_api" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed41783a5bf567688eb38372f2b7a8530f5a607a4b49d38dd7573236c23ca7e2" -dependencies = [ - "fnv", - "futures-channel", - "futures-util", - "indexmap 1.9.3", - "once_cell", - "pin-project-lite", - "thiserror", - "urlencoding", + "opentelemetry", ] [[package]] @@ -4068,28 +3960,6 @@ dependencies = [ "urlencoding", ] -[[package]] -name = "opentelemetry_sdk" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b3a2a91fdbfdd4d212c0dcc2ab540de2c2bcbbd90be17de7a7daf8822d010c1" -dependencies = [ - "async-trait", - "crossbeam-channel", - "dashmap", - "fnv", - "futures-channel", - "futures-executor", - "futures-util", - "once_cell", - "opentelemetry_api 0.19.0", - "percent-encoding", - "rand 0.8.5", - "thiserror", - "tokio", - "tokio-stream", -] - [[package]] name = "opentelemetry_sdk" version = "0.20.0" @@ -4102,7 +3972,7 @@ dependencies = [ "futures-executor", "futures-util", "once_cell", - "opentelemetry_api 0.20.0", + "opentelemetry_api", "ordered-float", "percent-encoding", "rand 0.8.5", @@ -5899,38 +5769,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "tonic" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f219fad3b929bef19b1f86fbc0358d35daed8f2cac972037ac0dc10bbb8d5fb" -dependencies = [ - "async-stream", - "async-trait", - "axum", - "base64 0.13.1", - "bytes", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "hyper", - "hyper-timeout", - "percent-encoding", - "pin-project", - "prost", - "prost-derive", - "tokio", - "tokio-stream", - "tokio-util", - "tower", - "tower-layer", - "tower-service", - "tracing", - "tracing-futures", -] - [[package]] name = "tonic" version = "0.9.2" @@ -6049,16 +5887,6 @@ dependencies = [ "valuable", ] -[[package]] -name = "tracing-futures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project", - "tracing", -] - [[package]] name = "tracing-log" version = "0.1.3" @@ -6070,20 +5898,6 @@ dependencies = [ "tracing-core", ] -[[package]] -name = "tracing-opentelemetry" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00a39dcf9bfc1742fa4d6215253b33a6e474be78275884c216fc2a06267b3600" -dependencies = [ - "once_cell", - "opentelemetry 0.19.0", - "tracing", - "tracing-core", - "tracing-log", - "tracing-subscriber", -] - [[package]] name = "tracing-opentelemetry" version = "0.21.0" @@ -6091,8 +5905,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75327c6b667828ddc28f5e3f169036cb793c3f588d83bf0f262a7f062ffed3c8" dependencies = [ "once_cell", - "opentelemetry 0.20.0", - "opentelemetry_sdk 0.20.0", + "opentelemetry", + "opentelemetry_sdk", "smallvec", "tracing", "tracing-core", @@ -6100,16 +5914,6 @@ dependencies = [ "tracing-subscriber", ] -[[package]] -name = "tracing-serde" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" -dependencies = [ - "serde", - "tracing-core", -] - [[package]] name = "tracing-subscriber" version = "0.3.17" @@ -6120,15 +5924,12 @@ dependencies = [ "nu-ansi-term", "once_cell", "regex", - "serde", - "serde_json", "sharded-slab", "smallvec", "thread_local", "tracing", "tracing-core", "tracing-log", - "tracing-serde", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 144f76012ff..2c823756bbe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ members = [ "examples/ipfs-kad", "examples/ipfs-private", "examples/metrics", - "examples/open-telemetry", "examples/ping", "examples/relay-server", "examples/rendezvous", diff --git a/examples/open-telemetry/Cargo.toml b/examples/open-telemetry/Cargo.toml deleted file mode 100644 index 6b44aa0797d..00000000000 --- a/examples/open-telemetry/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "open-telemetry-example" -version = "0.1.0" -edition = "2021" -publish = false -license = "MIT" - -[dependencies] -async-std = { version = "1.12", features = ["attributes"] } -async-trait = "0.1" -futures = "0.3.28" -libp2p = { path = "../../libp2p", features = ["async-std", "dns", "macros", "noise", "ping", "tcp", "websocket", "yamux"] } -opentelemetry = { version = "0.19.0", features = ["rt-tokio", "metrics"] } -opentelemetry-otlp = { version = "0.12.0", features = ["metrics"]} -tokio = { version = "1.32", features = ["full"] } -tracing = "0.1.37" -tracing-subscriber = { version = "0.3", features = ["env-filter", "json", "fmt"] } -tracing-opentelemetry = "0.19.0" \ No newline at end of file diff --git a/examples/open-telemetry/DOCKERFILE b/examples/open-telemetry/DOCKERFILE deleted file mode 100644 index 51a9ba76b35..00000000000 --- a/examples/open-telemetry/DOCKERFILE +++ /dev/null @@ -1,30 +0,0 @@ -FROM rust:1.70-slim as BUILDER -ARG PACKAGE -WORKDIR /build/ -COPY . ./ -RUN --mount=type=cache,target=./target \ - --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \ - --mount=type=cache,target=/usr/local/rustup,sharing=locked \ - cargo build -p $PACKAGE --release - -RUN --mount=type=cache,target=./target \ - mv ./target/release/$PACKAGE /usr/local/bin/$PACKAGE - -FROM debian:11.7-slim -ARG PACKAGE -WORKDIR /app/ -COPY --from=BUILDER /usr/local/bin/$PACKAGE . -RUN ln -s ./${PACKAGE} ./app -COPY ./docker-init.sh . -ENV RUST_BACKTRACE=1 -ENV PATH "/app:$PATH" -ENV PACKAGE_NAME ${PACKAGE} -RUN apt-get update -y \ - && apt-get install -y iputils-ping iptables lsof iproute2 curl iperf3 ca-certificates \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -ENTRYPOINT ["docker-init.sh"] -CMD ["open-telemetry"] - - diff --git a/examples/open-telemetry/docker-compose.yaml b/examples/open-telemetry/docker-compose.yaml deleted file mode 100644 index 20f57651b73..00000000000 --- a/examples/open-telemetry/docker-compose.yaml +++ /dev/null @@ -1,46 +0,0 @@ -version: "2" -services: - - # Jaeger - jaeger-all-in-one: - image: jaegertracing/all-in-one:latest - restart: always - ports: - - "16686:16686" - - "14268" - - "14250" - - # Collector - otel-collector: - image: ${OTELCOL_IMG} - restart: always - command: ["--config=/etc/otel-collector-config.yaml", "${OTELCOL_ARGS}"] - volumes: - - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml - ports: - - "4317:4317" # OTLP gRPC receiver - depends_on: - - jaeger-all-in-one - - demo-client: - build: - dockerfile: Dockerfile - context: ./client - restart: always - environment: - - OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317 - - DEMO_SERVER_ENDPOINT=http://demo-server:7080/hello - depends_on: - - demo-server - - demo-server: - build: - dockerfile: Dockerfile - context: ./server - restart: always - environment: - - OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317 - ports: - - "7080" - depends_on: - - otel-collector \ No newline at end of file diff --git a/examples/open-telemetry/src/main.rs b/examples/open-telemetry/src/main.rs deleted file mode 100644 index 7457b0a818a..00000000000 --- a/examples/open-telemetry/src/main.rs +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright 2018 Parity Technologies (UK) Ltd. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -use libp2p::core::transport::upgrade; -use libp2p::mdns; -use libp2p::swarm::NetworkBehaviour; -use opentelemetry::sdk; -use opentelemetry::sdk::export::metrics; -use opentelemetry_otlp::WithExportConfig; -use std::error::Error; -use tracing::Dispatch; -use tracing_subscriber::filter::LevelFilter; -use tracing_subscriber::EnvFilter; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, Layer}; - -use futures::prelude::*; -use libp2p::{ - identity, noise, ping, - swarm::{SwarmBuilder, SwarmEvent}, - tcp, yamux, PeerId, Transport, -}; -use std::time::Duration; - -// We create a custom network behaviour that combines Ping and Mdns. -#[derive(NetworkBehaviour)] -struct MyBehaviour { - ping: ping::Behaviour, - mdns: mdns::tokio::Behaviour, -} - -async fn init_telemetry() -> Result<(), Box> { - let grpc_endpoint = format!("http://localhost:4317"); - - tracing::trace!(%grpc_endpoint, "Setting up OTLP exporter for collector"); - - let exporter = opentelemetry_otlp::new_exporter() - .tonic() - .with_endpoint(grpc_endpoint.clone()); - - let tracer = opentelemetry_otlp::new_pipeline() - .tracing() - .with_exporter(exporter) - .with_trace_config(sdk::trace::Config::default()) - .install_batch(opentelemetry::runtime::Tokio)?; - - tracing::trace!("Successfully initialized trace provider on tokio runtime"); - - let exporter = opentelemetry_otlp::new_exporter() - .tonic() - .with_endpoint(grpc_endpoint); - - opentelemetry_otlp::new_pipeline() - .metrics( - sdk::metrics::selectors::simple::inexpensive(), - metrics::aggregation::cumulative_temporality_selector(), - opentelemetry::runtime::Tokio, - ) - .with_exporter(exporter) - .build()?; - - tracing::trace!("Successfully initialized metric controller on tokio runtime"); - - let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::INFO.into()) - .from_env_lossy(); - - let dispatch: Dispatch = tracing_subscriber::registry() - .with( - tracing_opentelemetry::layer() - .with_tracer(tracer) - .with_filter(env_filter), - ) - .into(); - - let _ = dispatch.try_init(); - - Ok(()) -} -#[tokio::main] -async fn main() -> Result<(), Box> { - let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::INFO.into()) - .from_env_lossy(); - - let _ = tracing_subscriber::fmt() - .with_env_filter(env_filter) - .try_init(); - - init_telemetry().await?; - - let local_key = identity::Keypair::generate_ed25519(); - let local_peer_id = PeerId::from(local_key.public()); - - // Set up an encrypted DNS-enabled TCP Transport over the yamux protocol. - let tcp_transport = tcp::tokio::Transport::new(tcp::Config::default().nodelay(true)) - .upgrade(upgrade::Version::V1Lazy) - .authenticate(noise::Config::new(&local_key)?) - .multiplex(yamux::Config::default()) - .timeout(std::time::Duration::from_secs(20)) - .boxed(); - - let mut swarm = { - let mdns = mdns::tokio::Behaviour::new(mdns::Config::default(), local_peer_id)?; - let behaviour = MyBehaviour { - mdns, - ping: ping::Behaviour::default(), - }; - SwarmBuilder::with_tokio_executor(tcp_transport, behaviour, local_peer_id) - .idle_connection_timeout(Duration::from_secs(60)) - .build() - }; - - swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?; - - loop { - match swarm.select_next_some().await { - SwarmEvent::NewListenAddr { address, .. } => println!("Listening on {address:?}"), - SwarmEvent::Behaviour(MyBehaviourEvent::Mdns(mdns::Event::Discovered(list))) => { - for (_, addr) in list { - swarm.dial(addr.clone())?; - println!("Dialed {addr}") - } - } - SwarmEvent::Behaviour(event) => println!("{event:?}"), - _ => {} - } - } -} diff --git a/protocols/identify/tests/smoke.rs b/protocols/identify/tests/smoke.rs index 2a6d8a0ea87..085e2b2626d 100644 --- a/protocols/identify/tests/smoke.rs +++ b/protocols/identify/tests/smoke.rs @@ -190,7 +190,9 @@ async fn discover_peer_after_disconnect() { #[async_std::test] async fn configured_interval_starts_after_first_identify() { - let _ = env_logger::try_init(); + let _ = tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .try_init(); let identify_interval = Duration::from_secs(5); diff --git a/swarm-test/src/lib.rs b/swarm-test/src/lib.rs index ef8e468c469..ee4058d530d 100644 --- a/swarm-test/src/lib.rs +++ b/swarm-test/src/lib.rs @@ -325,7 +325,7 @@ where { Either::Left(((), _)) => panic!("Swarm did not emit an event within 10s"), Either::Right((event, _)) => { - log::trace!("Swarm produced: {:?}", event); + tracing::trace!(?event); event } @@ -342,7 +342,7 @@ where async fn loop_on_next(mut self) { while let Some(event) = self.next().await { - log::trace!("Swarm produced: {:?}", event); + tracing::trace!(?event); } } } From 94f9caad11df7a4a7f90e6d2c443f4ee3078f278 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 31 Oct 2023 12:21:05 +1100 Subject: [PATCH 093/105] Add spans for durations of connections --- swarm/src/connection/pool.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index f3eb700371e..4432f7029c8 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -534,13 +534,19 @@ where endpoint.get_remote_address().clone(), ); - self.executor.spawn(task::new_for_established_connection( - id, - obtained_peer_id, - connection, - command_receiver, - event_sender, - )) + let span = tracing::debug_span!(parent: tracing::Span::none(), "new_established_connection", remote_addr = %endpoint.get_remote_address(), %id, peer = %obtained_peer_id); + span.follows_from(tracing::Span::current()); + + self.executor.spawn( + task::new_for_established_connection( + id, + obtained_peer_id, + connection, + command_receiver, + event_sender, + ) + .instrument(span), + ) } /// Polls the connection pool for events. From 8d84da4f1c5aa968afd2f4fe4d63344a161a03dc Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 31 Oct 2023 12:22:11 +1100 Subject: [PATCH 094/105] Remove fields already present in parent span --- swarm/src/connection.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 5e8f75f7f1d..da711df7427 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -244,7 +244,7 @@ where /// Polls the handler and the substream, forwarding events from the former to the latter and /// vice versa. - #[tracing::instrument(level = "debug", name = "Connection::poll", skip(self, cx), fields(id = %self.connection_id, peer = %self.remote_peer_id, remote_address = %self.remote_addr))] + #[tracing::instrument(level = "debug", name = "Connection::poll", skip(self, cx))] pub(crate) fn poll( self: Pin<&mut Self>, cx: &mut Context<'_>, From 93350b167d6fddc6893e90ec122d45702b34f6cd Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 31 Oct 2023 12:24:11 +1100 Subject: [PATCH 095/105] Fix link --- examples/metrics/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/metrics/README.md b/examples/metrics/README.md index e7ded9e5e88..160536985f1 100644 --- a/examples/metrics/README.md +++ b/examples/metrics/README.md @@ -53,7 +53,7 @@ Finally, open the Jaeger UI in a browser and explore the spans: http://localhost ### Filtering spans -For a precise documentation, please see the following documentation in tracing: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives. +For a precise documentation, please see the following documentation in tracing: . `rust-libp2p` consistently applies spans to the following functions: From e827911ab872042aebd5343a1d555d0817a38754 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 31 Oct 2023 12:35:08 +1100 Subject: [PATCH 096/105] Fix doc tests and warnings --- libp2p/src/tutorials/ping.rs | 8 ++++++-- swarm/src/connection.rs | 25 ------------------------- swarm/src/connection/pool.rs | 3 --- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/libp2p/src/tutorials/ping.rs b/libp2p/src/tutorials/ping.rs index 453ef683979..db515595bfc 100644 --- a/libp2p/src/tutorials/ping.rs +++ b/libp2p/src/tutorials/ping.rs @@ -72,10 +72,11 @@ //! //! ```rust //! use std::error::Error; +//! use tracing_subscriber::EnvFilter; //! //! #[async_std::main] //! async fn main() -> Result<(), Box> { -//! env_logger::init(); +//! tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); //! //! let mut swarm = libp2p::SwarmBuilder::with_new_identity(); //! @@ -96,10 +97,11 @@ //! ```rust //! use libp2p::{identity, PeerId}; //! use std::error::Error; +//! use tracing_subscriber::EnvFilter; //! //! #[async_std::main] //! async fn main() -> Result<(), Box> { -//! env_logger::init(); +//! tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init(); //! //! let mut swarm = libp2p::SwarmBuilder::with_new_identity() //! .with_async_std() @@ -138,6 +140,7 @@ //! ```rust //! use libp2p::swarm::NetworkBehaviour; //! use libp2p::{identity, ping, PeerId}; +//! use tracing_subscriber::EnvFilter; //! use std::error::Error; //! //! #[async_std::main] @@ -203,6 +206,7 @@ //! use libp2p::{identity, ping, PeerId}; //! use std::error::Error; //! use std::time::Duration; +//! use tracing_subscriber::EnvFilter; //! //! #[async_std::main] //! async fn main() -> Result<(), Box> { diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index da711df7427..35cc71d5354 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -157,9 +157,6 @@ where remote_supported_protocols: HashSet, idle_timeout: Duration, stream_counter: ActiveStreamCounter, - connection_id: ConnectionId, - remote_peer_id: PeerId, - remote_addr: Multiaddr, } impl fmt::Debug for Connection @@ -182,16 +179,12 @@ where { /// Builds a new `Connection` from the given substream multiplexer /// and connection handler. - #[allow(clippy::too_many_arguments)] pub(crate) fn new( muxer: StreamMuxerBox, mut handler: THandler, substream_upgrade_protocol_override: Option, max_negotiating_inbound_streams: usize, idle_timeout: Duration, - connection_id: ConnectionId, - remote_peer_id: PeerId, - remote_addr: Multiaddr, ) -> Self { let initial_protocols = gather_supported_protocols(&handler); if !initial_protocols.is_empty() { @@ -212,9 +205,6 @@ where remote_supported_protocols: Default::default(), idle_timeout, stream_counter: ActiveStreamCounter::default(), - connection_id, - remote_peer_id, - remote_addr, } } @@ -785,9 +775,6 @@ mod tests { None, max_negotiating_inbound_streams, Duration::ZERO, - ConnectionId::new_unchecked(0), - PeerId::random(), - Multiaddr::empty(), ); let result = connection.poll_noop_waker(); @@ -812,9 +799,6 @@ mod tests { None, 2, Duration::ZERO, - ConnectionId::new_unchecked(0), - PeerId::random(), - Multiaddr::empty(), ); connection.handler.open_new_outbound(); @@ -838,9 +822,6 @@ mod tests { None, 0, Duration::ZERO, - ConnectionId::new_unchecked(0), - PeerId::random(), - Multiaddr::empty(), ); // First, start listening on a single protocol. @@ -880,9 +861,6 @@ mod tests { None, 0, Duration::ZERO, - ConnectionId::new_unchecked(0), - PeerId::random(), - Multiaddr::empty(), ); // First, remote supports a single protocol. @@ -936,9 +914,6 @@ mod tests { None, 0, idle_timeout, - ConnectionId::new_unchecked(0), - PeerId::random(), - Multiaddr::empty(), ); assert!(connection.poll_noop_waker().is_pending()); diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index 4432f7029c8..cfa3fb7ea3c 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -529,9 +529,6 @@ where self.substream_upgrade_protocol_override, self.max_negotiating_inbound_streams, self.idle_connection_timeout, - id, - obtained_peer_id, - endpoint.get_remote_address().clone(), ); let span = tracing::debug_span!(parent: tracing::Span::none(), "new_established_connection", remote_addr = %endpoint.get_remote_address(), %id, peer = %obtained_peer_id); From b136d49a7ccc2350a48c3964450927fcc1e10866 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 31 Oct 2023 12:45:00 +1100 Subject: [PATCH 097/105] Remove `local_peer_id` from `Swarm::poll` This is too noisy. --- swarm/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 9fcb9b08617..5ff728d72fe 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -1159,7 +1159,7 @@ where /// Internal function used by everything event-related. /// /// Polls the `Swarm` for the next event. - #[tracing::instrument(level = "debug", name = "Swarm::poll", skip(self, cx), fields(local_peer_id = %self.local_peer_id))] + #[tracing::instrument(level = "debug", name = "Swarm::poll", skip(self, cx))] fn poll_next_event( mut self: Pin<&mut Self>, cx: &mut Context<'_>, From eccc6c1760d4b0f486745d3cdadc96dc56044890 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 1 Nov 2023 17:30:25 +0200 Subject: [PATCH 098/105] dont upgrade debug to error --- protocols/ping/src/handler.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index baba33777f6..71ebcd97261 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -251,7 +251,7 @@ impl ConnectionHandler for Handler { match fut.poll_unpin(cx) { Poll::Pending => {} Poll::Ready(Err(e)) => { - tracing::error!("Inbound ping error: {:?}", e); + tracing::debug!("Inbound ping error: {:?}", e); self.inbound = None; } Poll::Ready(Ok(stream)) => { @@ -266,7 +266,7 @@ impl ConnectionHandler for Handler { loop { // Check for outbound ping failures. if let Some(error) = self.pending_errors.pop_back() { - tracing::error!("Ping failure: {:?}", error); + tracing::debug!("Ping failure: {:?}", error); self.failures += 1; From 0f34558ec0466e34940d99498e544e8e4cf4d619 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 1 Nov 2023 17:36:46 +0200 Subject: [PATCH 099/105] add tracing decorator to handlers --- protocols/dcutr/src/handler/relayed.rs | 1 + protocols/kad/src/handler.rs | 3 ++- protocols/perf/src/client/handler.rs | 1 + protocols/perf/src/server/handler.rs | 1 + protocols/relay/src/behaviour/handler.rs | 1 + protocols/relay/src/priv_client/handler.rs | 1 + protocols/request-response/src/handler.rs | 1 + 7 files changed, 8 insertions(+), 1 deletion(-) diff --git a/protocols/dcutr/src/handler/relayed.rs b/protocols/dcutr/src/handler/relayed.rs index e1e9ffbff7a..b0155d34636 100644 --- a/protocols/dcutr/src/handler/relayed.rs +++ b/protocols/dcutr/src/handler/relayed.rs @@ -257,6 +257,7 @@ impl ConnectionHandler for Handler { false } + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, cx))] fn poll( &mut self, cx: &mut Context<'_>, diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 8084830bf39..cba28eb4aab 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -705,7 +705,8 @@ impl ConnectionHandler for Handler { } } } - + + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, cx))] fn poll( &mut self, cx: &mut Context<'_>, diff --git a/protocols/perf/src/client/handler.rs b/protocols/perf/src/client/handler.rs index a9bb0c7d483..d5d05284a85 100644 --- a/protocols/perf/src/client/handler.rs +++ b/protocols/perf/src/client/handler.rs @@ -153,6 +153,7 @@ impl ConnectionHandler for Handler { } } + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, cx))] fn poll( &mut self, cx: &mut Context<'_>, diff --git a/protocols/perf/src/server/handler.rs b/protocols/perf/src/server/handler.rs index c91aff9bee0..7f262ac4820 100644 --- a/protocols/perf/src/server/handler.rs +++ b/protocols/perf/src/server/handler.rs @@ -115,6 +115,7 @@ impl ConnectionHandler for Handler { } } + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, cx))] fn poll( &mut self, cx: &mut Context<'_>, diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index 777b942e3cb..4babfbd1d7e 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -603,6 +603,7 @@ impl ConnectionHandler for Handler { Instant::now().duration_since(idle_at) <= Duration::from_secs(10) } + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, cx))] fn poll( &mut self, cx: &mut Context<'_>, diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs index dde8c303c73..45505936c8b 100644 --- a/protocols/relay/src/priv_client/handler.rs +++ b/protocols/relay/src/priv_client/handler.rs @@ -317,6 +317,7 @@ impl ConnectionHandler for Handler { self.reservation.is_some() } + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, cx))] fn poll( &mut self, cx: &mut Context<'_>, diff --git a/protocols/request-response/src/handler.rs b/protocols/request-response/src/handler.rs index 13a8929143c..ef4b5b44fe0 100644 --- a/protocols/request-response/src/handler.rs +++ b/protocols/request-response/src/handler.rs @@ -386,6 +386,7 @@ where self.pending_outbound.push_back(request); } + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, cx))] fn poll( &mut self, cx: &mut Context<'_>, From 88f256e1fcdb17bc88ba636ae9a591538e210364 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 1 Nov 2023 17:44:18 +0200 Subject: [PATCH 100/105] add tracing decorator to network behaviours --- protocols/autonat/src/behaviour.rs | 1 + protocols/gossipsub/src/behaviour.rs | 1 + protocols/gossipsub/src/handler.rs | 1 + protocols/kad/src/behaviour.rs | 1 + protocols/mdns/src/behaviour.rs | 1 + protocols/perf/src/client/behaviour.rs | 1 + protocols/perf/src/server/behaviour.rs | 3 ++- protocols/relay/src/behaviour.rs | 3 ++- protocols/upnp/src/behaviour.rs | 1 + 9 files changed, 11 insertions(+), 2 deletions(-) diff --git a/protocols/autonat/src/behaviour.rs b/protocols/autonat/src/behaviour.rs index e9a73fd3fcb..06c945eb888 100644 --- a/protocols/autonat/src/behaviour.rs +++ b/protocols/autonat/src/behaviour.rs @@ -435,6 +435,7 @@ impl NetworkBehaviour for Behaviour { as NetworkBehaviour>::ConnectionHandler; type ToSwarm = Event; + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, cx))] fn poll( &mut self, cx: &mut Context<'_>, diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 935d6e5de0b..f1069658b73 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -3426,6 +3426,7 @@ where } } + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, cx))] fn poll( &mut self, cx: &mut Context<'_>, diff --git a/protocols/gossipsub/src/handler.rs b/protocols/gossipsub/src/handler.rs index 24b535e3914..4f3dd5c9f63 100644 --- a/protocols/gossipsub/src/handler.rs +++ b/protocols/gossipsub/src/handler.rs @@ -429,6 +429,7 @@ impl ConnectionHandler for Handler { matches!(self, Handler::Enabled(h) if h.in_mesh) } + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, cx))] fn poll( &mut self, cx: &mut Context<'_>, diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index 969219b79fd..cc80b9c1be9 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -2413,6 +2413,7 @@ where }; } + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, cx))] fn poll( &mut self, cx: &mut Context<'_>, diff --git a/protocols/mdns/src/behaviour.rs b/protocols/mdns/src/behaviour.rs index 3ac6188c24e..e1652db4762 100644 --- a/protocols/mdns/src/behaviour.rs +++ b/protocols/mdns/src/behaviour.rs @@ -282,6 +282,7 @@ where .on_swarm_event(&event); } + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, cx))] fn poll( &mut self, cx: &mut Context<'_>, diff --git a/protocols/perf/src/client/behaviour.rs b/protocols/perf/src/client/behaviour.rs index a4dc354fac0..79c73d55102 100644 --- a/protocols/perf/src/client/behaviour.rs +++ b/protocols/perf/src/client/behaviour.rs @@ -145,6 +145,7 @@ impl NetworkBehaviour for Behaviour { .push_back(ToSwarm::GenerateEvent(Event { id, result })); } + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, _cx))] fn poll( &mut self, _cx: &mut Context<'_>, diff --git a/protocols/perf/src/server/behaviour.rs b/protocols/perf/src/server/behaviour.rs index c699f706d87..35b213bab3b 100644 --- a/protocols/perf/src/server/behaviour.rs +++ b/protocols/perf/src/server/behaviour.rs @@ -104,7 +104,8 @@ impl NetworkBehaviour for Behaviour { stats, })) } - + + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self,_cx))] fn poll( &mut self, _cx: &mut Context<'_>, diff --git a/protocols/relay/src/behaviour.rs b/protocols/relay/src/behaviour.rs index 256bb463b5a..5da16fde37b 100644 --- a/protocols/relay/src/behaviour.rs +++ b/protocols/relay/src/behaviour.rs @@ -687,7 +687,8 @@ impl NetworkBehaviour for Behaviour { } } - fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, _cx))] + fn poll(&mut self, _cx: &mut Context<'_>) -> Poll>> { if let Some(to_swarm) = self.queued_actions.pop_front() { return Poll::Ready(to_swarm); } diff --git a/protocols/upnp/src/behaviour.rs b/protocols/upnp/src/behaviour.rs index 7609fed33db..5410b8dd13f 100644 --- a/protocols/upnp/src/behaviour.rs +++ b/protocols/upnp/src/behaviour.rs @@ -374,6 +374,7 @@ impl NetworkBehaviour for Behaviour { void::unreachable(event) } + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, cx))] fn poll( &mut self, cx: &mut Context<'_>, From 7b5518596ed94be91ff870dc6777e98beda75ed8 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 2 Nov 2023 16:45:16 +1100 Subject: [PATCH 101/105] Remove unused imports --- transports/plaintext/src/handshake.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/transports/plaintext/src/handshake.rs b/transports/plaintext/src/handshake.rs index 57e3a5fa989..ddd5f7f8a9b 100644 --- a/transports/plaintext/src/handshake.rs +++ b/transports/plaintext/src/handshake.rs @@ -25,7 +25,6 @@ use asynchronous_codec::{Framed, FramedParts}; use bytes::Bytes; use futures::prelude::*; use libp2p_identity::{PeerId, PublicKey}; -use quick_protobuf::{BytesReader, MessageRead, MessageWrite, Writer}; use std::io::{Error as IoError, ErrorKind as IoErrorKind}; pub(crate) async fn handshake(socket: S, config: Config) -> Result<(S, PublicKey, Bytes), Error> From 949ae15859a73eeabbbd7b30a46b5a736c121fcd Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 2 Nov 2023 16:45:56 +1100 Subject: [PATCH 102/105] Fix logger init in test --- protocols/identify/tests/smoke.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/protocols/identify/tests/smoke.rs b/protocols/identify/tests/smoke.rs index e6fb58f23f2..5cccc09d863 100644 --- a/protocols/identify/tests/smoke.rs +++ b/protocols/identify/tests/smoke.rs @@ -86,7 +86,9 @@ async fn periodic_identify() { } #[async_std::test] async fn only_emits_address_candidate_once_per_connection() { - let _ = env_logger::try_init(); + let _ = tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .try_init(); let mut swarm1 = Swarm::new_ephemeral(|identity| { identify::Behaviour::new( From c3595da0e05c108fa4248339a557bf15952fcceb Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 2 Nov 2023 16:50:29 +1100 Subject: [PATCH 103/105] Unify init of subscriber across examples --- Cargo.lock | 1 + examples/chat/src/main.rs | 8 ++------ examples/distributed-key-value-store/src/main.rs | 8 ++------ examples/file-sharing/src/main.rs | 8 ++------ examples/ipfs-kad/src/main.rs | 8 ++------ examples/ipfs-private/src/main.rs | 8 ++------ examples/relay-server/src/main.rs | 8 ++------ examples/rendezvous/src/bin/rzv-discover.rs | 8 ++------ examples/rendezvous/src/bin/rzv-identify.rs | 8 ++------ examples/rendezvous/src/bin/rzv-register.rs | 8 ++------ examples/rendezvous/src/main.rs | 8 ++------ examples/upnp/Cargo.toml | 1 + examples/upnp/src/main.rs | 5 +++++ protocols/kad/src/handler.rs | 2 +- protocols/perf/src/server/behaviour.rs | 4 ++-- protocols/relay/src/behaviour.rs | 5 ++++- protocols/relay/tests/lib.rs | 8 ++++++-- 17 files changed, 40 insertions(+), 66 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4bec0e388da..0c7605e652b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6132,6 +6132,7 @@ dependencies = [ "futures", "libp2p", "tokio", + "tracing-subscriber", ] [[package]] diff --git a/examples/chat/src/main.rs b/examples/chat/src/main.rs index 50f98bba8c7..24f8b19d0c4 100644 --- a/examples/chat/src/main.rs +++ b/examples/chat/src/main.rs @@ -27,7 +27,7 @@ use std::error::Error; use std::hash::{Hash, Hasher}; use std::time::Duration; use tokio::{io, io::AsyncBufReadExt, select}; -use tracing_subscriber::{filter::LevelFilter, EnvFilter}; +use tracing_subscriber::EnvFilter; // We create a custom network behaviour that combines Gossipsub and Mdns. #[derive(NetworkBehaviour)] @@ -38,12 +38,8 @@ struct MyBehaviour { #[tokio::main] async fn main() -> Result<(), Box> { - let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::DEBUG.into()) - .from_env_lossy(); - let _ = tracing_subscriber::fmt() - .with_env_filter(env_filter) + .with_env_filter(EnvFilter::from_default_env()) .try_init(); let mut swarm = libp2p::SwarmBuilder::with_new_identity() diff --git a/examples/distributed-key-value-store/src/main.rs b/examples/distributed-key-value-store/src/main.rs index f6668493ff0..1843520838b 100644 --- a/examples/distributed-key-value-store/src/main.rs +++ b/examples/distributed-key-value-store/src/main.rs @@ -31,16 +31,12 @@ use libp2p::{ tcp, yamux, }; use std::error::Error; -use tracing_subscriber::{filter::LevelFilter, EnvFilter}; +use tracing_subscriber::EnvFilter; #[async_std::main] async fn main() -> Result<(), Box> { - let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::DEBUG.into()) - .from_env_lossy(); - let _ = tracing_subscriber::fmt() - .with_env_filter(env_filter) + .with_env_filter(EnvFilter::from_default_env()) .try_init(); // We create a custom network behaviour that combines Kademlia and mDNS. diff --git a/examples/file-sharing/src/main.rs b/examples/file-sharing/src/main.rs index 19bb900ba03..ad1a12b3b02 100644 --- a/examples/file-sharing/src/main.rs +++ b/examples/file-sharing/src/main.rs @@ -31,16 +31,12 @@ use libp2p::{core::Multiaddr, multiaddr::Protocol}; use std::error::Error; use std::io::Write; use std::path::PathBuf; -use tracing_subscriber::{filter::LevelFilter, EnvFilter}; +use tracing_subscriber::EnvFilter; #[async_std::main] async fn main() -> Result<(), Box> { - let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::DEBUG.into()) - .from_env_lossy(); - let _ = tracing_subscriber::fmt() - .with_env_filter(env_filter) + .with_env_filter(EnvFilter::from_default_env()) .try_init(); let opt = Opt::parse(); diff --git a/examples/ipfs-kad/src/main.rs b/examples/ipfs-kad/src/main.rs index abe7cca70a5..0d11bdd851a 100644 --- a/examples/ipfs-kad/src/main.rs +++ b/examples/ipfs-kad/src/main.rs @@ -28,7 +28,7 @@ use anyhow::{bail, Result}; use clap::Parser; use futures::StreamExt; use libp2p::{bytes::BufMut, identity, kad, noise, swarm::SwarmEvent, tcp, yamux, PeerId}; -use tracing_subscriber::{filter::LevelFilter, EnvFilter}; +use tracing_subscriber::EnvFilter; const BOOTNODES: [&str; 4] = [ "QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN", @@ -39,12 +39,8 @@ const BOOTNODES: [&str; 4] = [ #[tokio::main] async fn main() -> Result<()> { - let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::DEBUG.into()) - .from_env_lossy(); - let _ = tracing_subscriber::fmt() - .with_env_filter(env_filter) + .with_env_filter(EnvFilter::from_default_env()) .try_init(); // Create a random key for ourselves. diff --git a/examples/ipfs-private/src/main.rs b/examples/ipfs-private/src/main.rs index 6b653753e24..12bd985cdf0 100644 --- a/examples/ipfs-private/src/main.rs +++ b/examples/ipfs-private/src/main.rs @@ -33,7 +33,7 @@ use libp2p::{ }; use std::{env, error::Error, fs, path::Path, str::FromStr}; use tokio::{io, io::AsyncBufReadExt, select}; -use tracing_subscriber::{filter::LevelFilter, EnvFilter}; +use tracing_subscriber::EnvFilter; /// Get the current ipfs repo path, either from the IPFS_PATH environment variable or /// from the default $HOME/.ipfs @@ -88,12 +88,8 @@ fn parse_legacy_multiaddr(text: &str) -> Result> { #[tokio::main] async fn main() -> Result<(), Box> { - let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::DEBUG.into()) - .from_env_lossy(); - let _ = tracing_subscriber::fmt() - .with_env_filter(env_filter) + .with_env_filter(EnvFilter::from_default_env()) .try_init(); let ipfs_path = get_ipfs_path(); diff --git a/examples/relay-server/src/main.rs b/examples/relay-server/src/main.rs index 220276d4356..bf5817454f8 100644 --- a/examples/relay-server/src/main.rs +++ b/examples/relay-server/src/main.rs @@ -33,15 +33,11 @@ use libp2p::{ }; use std::error::Error; use std::net::{Ipv4Addr, Ipv6Addr}; -use tracing_subscriber::{filter::LevelFilter, EnvFilter}; +use tracing_subscriber::EnvFilter; fn main() -> Result<(), Box> { - let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::DEBUG.into()) - .from_env_lossy(); - let _ = tracing_subscriber::fmt() - .with_env_filter(env_filter) + .with_env_filter(EnvFilter::from_default_env()) .try_init(); let opt = Opt::parse(); diff --git a/examples/rendezvous/src/bin/rzv-discover.rs b/examples/rendezvous/src/bin/rzv-discover.rs index a895ac186d0..edd3d10a0ce 100644 --- a/examples/rendezvous/src/bin/rzv-discover.rs +++ b/examples/rendezvous/src/bin/rzv-discover.rs @@ -27,18 +27,14 @@ use libp2p::{ }; use std::error::Error; use std::time::Duration; -use tracing_subscriber::{filter::LevelFilter, EnvFilter}; +use tracing_subscriber::EnvFilter; const NAMESPACE: &str = "rendezvous"; #[tokio::main] async fn main() -> Result<(), Box> { - let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::DEBUG.into()) - .from_env_lossy(); - let _ = tracing_subscriber::fmt() - .with_env_filter(env_filter) + .with_env_filter(EnvFilter::from_default_env()) .try_init(); let rendezvous_point_address = "/ip4/127.0.0.1/tcp/62649".parse::().unwrap(); diff --git a/examples/rendezvous/src/bin/rzv-identify.rs b/examples/rendezvous/src/bin/rzv-identify.rs index 62db5424cb4..1d545592829 100644 --- a/examples/rendezvous/src/bin/rzv-identify.rs +++ b/examples/rendezvous/src/bin/rzv-identify.rs @@ -25,16 +25,12 @@ use libp2p::{ tcp, yamux, Multiaddr, }; use std::time::Duration; -use tracing_subscriber::{filter::LevelFilter, EnvFilter}; +use tracing_subscriber::EnvFilter; #[tokio::main] async fn main() { - let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::DEBUG.into()) - .from_env_lossy(); - let _ = tracing_subscriber::fmt() - .with_env_filter(env_filter) + .with_env_filter(EnvFilter::from_default_env()) .try_init(); let rendezvous_point_address = "/ip4/127.0.0.1/tcp/62649".parse::().unwrap(); diff --git a/examples/rendezvous/src/bin/rzv-register.rs b/examples/rendezvous/src/bin/rzv-register.rs index 275fc01b382..bd848238d4a 100644 --- a/examples/rendezvous/src/bin/rzv-register.rs +++ b/examples/rendezvous/src/bin/rzv-register.rs @@ -25,16 +25,12 @@ use libp2p::{ tcp, yamux, Multiaddr, }; use std::time::Duration; -use tracing_subscriber::{filter::LevelFilter, EnvFilter}; +use tracing_subscriber::EnvFilter; #[tokio::main] async fn main() { - let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::DEBUG.into()) - .from_env_lossy(); - let _ = tracing_subscriber::fmt() - .with_env_filter(env_filter) + .with_env_filter(EnvFilter::from_default_env()) .try_init(); let rendezvous_point_address = "/ip4/127.0.0.1/tcp/62649".parse::().unwrap(); diff --git a/examples/rendezvous/src/main.rs b/examples/rendezvous/src/main.rs index 8d8a80e7037..a15bc1ca2d3 100644 --- a/examples/rendezvous/src/main.rs +++ b/examples/rendezvous/src/main.rs @@ -28,16 +28,12 @@ use libp2p::{ }; use std::error::Error; use std::time::Duration; -use tracing_subscriber::{filter::LevelFilter, EnvFilter}; +use tracing_subscriber::EnvFilter; #[tokio::main] async fn main() -> Result<(), Box> { - let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::DEBUG.into()) - .from_env_lossy(); - let _ = tracing_subscriber::fmt() - .with_env_filter(env_filter) + .with_env_filter(EnvFilter::from_default_env()) .try_init(); // Results in PeerID 12D3KooWDpJ7As7BWAwRMfu1VU2WCqNjvq387JEYKDBj4kx6nXTN which is diff --git a/examples/upnp/Cargo.toml b/examples/upnp/Cargo.toml index 02110c33840..940f3dff65f 100644 --- a/examples/upnp/Cargo.toml +++ b/examples/upnp/Cargo.toml @@ -12,6 +12,7 @@ release = false tokio = { version = "1", features = ["rt-multi-thread", "macros"] } futures = "0.3.29" libp2p = { path = "../../libp2p", features = ["tokio", "dns", "macros", "noise", "ping", "tcp", "yamux", "upnp"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } [lints] workspace = true diff --git a/examples/upnp/src/main.rs b/examples/upnp/src/main.rs index c602a687db7..fd0764990d1 100644 --- a/examples/upnp/src/main.rs +++ b/examples/upnp/src/main.rs @@ -23,9 +23,14 @@ use futures::prelude::*; use libp2p::{noise, swarm::SwarmEvent, upnp, yamux, Multiaddr}; use std::error::Error; +use tracing_subscriber::EnvFilter; #[tokio::main] async fn main() -> Result<(), Box> { + let _ = tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .try_init(); + let mut swarm = libp2p::SwarmBuilder::with_new_identity() .with_tokio() .with_tcp( diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index cba28eb4aab..0f36800a904 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -705,7 +705,7 @@ impl ConnectionHandler for Handler { } } } - + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, cx))] fn poll( &mut self, diff --git a/protocols/perf/src/server/behaviour.rs b/protocols/perf/src/server/behaviour.rs index 35b213bab3b..370bc2ae188 100644 --- a/protocols/perf/src/server/behaviour.rs +++ b/protocols/perf/src/server/behaviour.rs @@ -104,8 +104,8 @@ impl NetworkBehaviour for Behaviour { stats, })) } - - #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self,_cx))] + + #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, _cx))] fn poll( &mut self, _cx: &mut Context<'_>, diff --git a/protocols/relay/src/behaviour.rs b/protocols/relay/src/behaviour.rs index 297445416d0..98e2a5a53bb 100644 --- a/protocols/relay/src/behaviour.rs +++ b/protocols/relay/src/behaviour.rs @@ -708,7 +708,10 @@ impl NetworkBehaviour for Behaviour { } #[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, _cx))] - fn poll(&mut self, _cx: &mut Context<'_>) -> Poll>> { + fn poll( + &mut self, + _cx: &mut Context<'_>, + ) -> Poll>> { if let Some(to_swarm) = self.queued_actions.pop_front() { return Poll::Ready(to_swarm); } diff --git a/protocols/relay/tests/lib.rs b/protocols/relay/tests/lib.rs index c693dab570d..d57ab144e9f 100644 --- a/protocols/relay/tests/lib.rs +++ b/protocols/relay/tests/lib.rs @@ -285,7 +285,9 @@ fn handle_dial_failure() { #[test] fn propagate_reservation_error_to_listener() { - let _ = env_logger::try_init(); + let _ = tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .try_init(); let mut pool = LocalPool::new(); let relay_addr = Multiaddr::empty().with(Protocol::Memory(rand::random::())); @@ -332,7 +334,9 @@ fn propagate_reservation_error_to_listener() { #[test] fn propagate_connect_error_to_unknown_peer_to_dialer() { - let _ = env_logger::try_init(); + let _ = tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .try_init(); let mut pool = LocalPool::new(); let relay_addr = Multiaddr::empty().with(Protocol::Memory(rand::random::())); From 6df4a941e119d6bbb2c72361f8d570f25659c03c Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 2 Nov 2023 16:51:18 +1100 Subject: [PATCH 104/105] Serve metrics on random port to avoid panic --- examples/metrics/src/http_service.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/metrics/src/http_service.rs b/examples/metrics/src/http_service.rs index ac4a39a9c2a..8c77d724ea3 100644 --- a/examples/metrics/src/http_service.rs +++ b/examples/metrics/src/http_service.rs @@ -32,7 +32,7 @@ const METRICS_CONTENT_TYPE: &str = "application/openmetrics-text;charset=utf-8;v pub(crate) async fn metrics_server(registry: Registry) -> Result<(), std::io::Error> { // Serve on localhost. - let addr = ([127, 0, 0, 1], 8080).into(); + let addr = ([127, 0, 0, 1], 0).into(); let server = Server::bind(&addr).serve(MakeMetricService::new(registry)); tracing::info!(metrics_server=%format!("http://{}/metrics", server.local_addr())); From b5c22335277ab1ee04ae96e50b5a76f1d06c8ee4 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 2 Nov 2023 16:55:34 +1100 Subject: [PATCH 105/105] Fix bad merge --- libp2p/src/tutorials/ping.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/libp2p/src/tutorials/ping.rs b/libp2p/src/tutorials/ping.rs index f4aa970ad3f..db515595bfc 100644 --- a/libp2p/src/tutorials/ping.rs +++ b/libp2p/src/tutorials/ping.rs @@ -142,7 +142,6 @@ //! use libp2p::{identity, ping, PeerId}; //! use tracing_subscriber::EnvFilter; //! use std::error::Error; -//! use tracing_subscriber::EnvFilter; //! //! #[async_std::main] //! async fn main() -> Result<(), Box> {