Skip to content

Commit d08f287

Browse files
authored
Update lib.rs
1 parent a5a35ee commit d08f287

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

misc/metrics/src/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,33 @@ impl Metrics {
9090
swarm: swarm::Metrics::new(sub_registry),
9191
}
9292
}
93+
94+
/// Create a new set of [`Metrics`] allowing to pass additional protocols
95+
/// for Identify classification (e.g. custom Gossipsub protocol IDs).
96+
pub fn new_with_identify_allowed_protocols(
97+
registry: &mut Registry,
98+
extra_allowed_protocols: impl IntoIterator<Item = libp2p_swarm::StreamProtocol>,
99+
) -> Self {
100+
let sub_registry = registry.sub_registry_with_prefix("libp2p");
101+
Self {
102+
#[cfg(feature = "dcutr")]
103+
dcutr: dcutr::Metrics::new(sub_registry),
104+
#[cfg(feature = "gossipsub")]
105+
gossipsub: gossipsub::Metrics::new(sub_registry),
106+
#[cfg(feature = "identify")]
107+
identify: identify::Metrics::new_with_allowed_protocols(
108+
sub_registry,
109+
extra_allowed_protocols,
110+
),
111+
#[cfg(feature = "kad")]
112+
kad: kad::Metrics::new(sub_registry),
113+
#[cfg(feature = "ping")]
114+
ping: ping::Metrics::new(sub_registry),
115+
#[cfg(feature = "relay")]
116+
relay: relay::Metrics::new(sub_registry),
117+
swarm: swarm::Metrics::new(sub_registry),
118+
}
119+
}
93120
}
94121

95122
/// Recorder that can record Swarm and protocol events.

0 commit comments

Comments
 (0)