File: README.md

package info (click to toggle)
rust-libp2p-identity 0.2.10%2B20250205%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 804 kB
  • sloc: makefile: 8; sh: 1
file content (79 lines) | stat: -rw-r--r-- 2,794 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
## Description

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

To run the example, follow these steps:

1. Run the following command to start the first node:

   ```sh
   cargo run
   ```

2. Open a second terminal and run the following command to start a second node:

   ```sh
   cargo run -- <listen-addr-of-first-node>
   ```

   Replace `<listen-addr-of-first-node>` with the listen address of the first node reported in the first terminal.
   Look for the line that says `NewListenAddr` to find the address.

3. Open a third terminal and run the following command to retrieve the metrics from either the first or second node:

   ```sh
   curl localhost:<metrics-port-of-first-or-second-node>/metrics
   ```

   Replace `<metrics-port-of-first-or-second-node>` with the listen port of the metrics server of either the first or second node.
   Look for the line that says `tide::server Server listening on` to find the port.

   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
```

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.
By running multiple nodes and examining the metrics, users can gain insights into the network's performance and behavior.