Skip to content

Commit a79c505

Browse files
authored
docs(subscriber): add a README (and lib.rs docs) (#202)
This branch adds a README file to `console-subscriber`, and uses it as docs in `lib.rs` as well. I also fixed some minor docs issues in the `console-api` documentation. Signed-off-by: Eliza Weisman <[email protected]>
1 parent 457f525 commit a79c505

File tree

3 files changed

+200
-2
lines changed

3 files changed

+200
-2
lines changed

Diff for: console-api/README.md

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# tokio-console API
22

3-
[Tonic] bindings for the [`tokio-console`] protobuf wire format.
3+
&#x1f6f0; [Tonic] bindings for the [`tokio-console`] [protobuf] wire format.
44

55
[![crates.io][crates-badge]][crates-url]
66
[![Documentation][docs-badge]][docs-url]
@@ -16,7 +16,7 @@
1616
[docs-badge]: https://docs.rs/console-api/badge.svg
1717
[docs-url]: https://docs.rs/console-api
1818
[docs-main-badge]: https://img.shields.io/netlify/0e5ffd50-e1fa-416e-b147-a04dab28cfb1?label=docs%20%28main%20branch%29
19-
[docs-main-url]: https://tokio-console.netlify.app/tokio_console_api/
19+
[docs-main-url]: https://tokio-console.netlify.app/console_api/
2020
[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg
2121
[mit-url]: ../LICENSE
2222
[actions-badge]: https://github.com/tokio-rs/console/workflows/CI/badge.svg
@@ -29,6 +29,21 @@ This crate contains generated [protobuf] bindings for the [`tokio-console`] wire
2929
format. The wire format is used to export diagnostic data from instrumented
3030
applications to consumers that aggregate and display that data.
3131

32+
[`tokio-console`] is a debugging and profiling tool for asynchronous Rust
33+
applications, which collects and displays in-depth diagnostic data on the
34+
asynchronous tasks, resources, and operations in an application. The console
35+
system consists of two primary components:
36+
37+
* _instrumentation_, embedded in the application, which collects data from the
38+
async runtime and exposes it over the console's wire format
39+
* _consumers_, such as the [`tokio-console`] command-line application, which
40+
connect to the instrumented application, recieve telemetry data, and display
41+
it to the user
42+
43+
The wire format [protobuf] bindings in this crate are used by both the
44+
instrumentation in the [`console-subscriber`] crate, which emits telemetry in
45+
this format, and by the clients that consume that telemetry.
46+
3247
In general, most [`tokio-console`] users will *not* depend on this crate
3348
directly. Applications are typically instrumented using the
3449
[`console-subscriber`] crate, which collects data and exports it using

Diff for: console-subscriber/README.md

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# tokio-console subscriber
2+
3+
&#x1F4E1;&#xFE0F; A [`tracing-subscriber`] [`Layer`] for collecting
4+
[`tokio-console`] instrumentation.
5+
6+
[![crates.io][crates-badge]][crates-url]
7+
[![Documentation][docs-badge]][docs-url]
8+
[![Documentation (`main` branch)][docs-main-badge]][docs-main-url]
9+
[![MIT licensed][mit-badge]][mit-url]
10+
[![Build Status][actions-badge]][actions-url]
11+
[![Discord chat][discord-badge]][discord-url]
12+
13+
[Website](https://tokio.rs) | [Chat][discord-url] | [API Documentation][docs-url]
14+
15+
[crates-badge]: https://img.shields.io/crates/v/console-subscriber.svg
16+
[crates-url]: https://crates.io/crates/console-subscriber
17+
[docs-badge]: https://docs.rs/console-subscriber/badge.svg
18+
[docs-url]: https://docs.rs/console-subscriber
19+
[docs-main-badge]: https://img.shields.io/netlify/0e5ffd50-e1fa-416e-b147-a04dab28cfb1?label=docs%20%28main%20branch%29
20+
[docs-main-url]: https://tokio-console.netlify.app/console_subscriber/
21+
[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg
22+
[mit-url]: ../LICENSE
23+
[actions-badge]: https://github.com/tokio-rs/console/workflows/CI/badge.svg
24+
[actions-url]:https://github.com/tokio-rs/console/actions?query=workflow%3ACI
25+
[discord-badge]: https://img.shields.io/discord/500028886025895936?logo=discord&label=discord&logoColor=white
26+
27+
## Overview
28+
29+
[`tokio-console`] is a debugging and profiling tool for asynchronous Rust
30+
applications, which collects and displays in-depth diagnostic data on the
31+
asynchronous tasks, resources, and operations in an application. The console
32+
system consists of two primary components:
33+
34+
* _instrumentation_, embedded in the application, which collects data from the
35+
async runtime and exposes it over the console's [wire format]
36+
* _consumers_, such as the [`tokio-console`] command-line application, which
37+
connect to the instrumented application, recieve telemetry data, and display
38+
it to the user
39+
40+
This crate implements the instrumentation-side interface using data
41+
emitted by the async runtime using the [`tracing`]. It provides a type
42+
implementing the [`Layer`] trait from [`tracing-subscriber`], for collecting and
43+
aggregating the runtime's [`tracing`] data, and a gRPC server that exports
44+
telemetry to clients.
45+
46+
[wire format]: https://crates.io/crates/console-api
47+
48+
## Getting Started
49+
50+
To instrument your asynchronous application, you must be using an async runtime
51+
that supports the [`tracing`] instrumentation required by the console.
52+
Currently, the only runtime that implements this instrumentation is [Tokio]
53+
version 1.7.0 and newer.
54+
55+
### Enabling Tokio Instrumentation
56+
57+
&#x26A0;&#xFE0F; Currently, the [`tracing`] support in the [`tokio`
58+
runtime][Tokio] is considered *experimental*. In order to use
59+
`console-subscriber` with Tokio, the following is required:
60+
61+
* Tokio's optional `tracing` dependency must be enabled. For example:
62+
```toml
63+
[dependencies]
64+
# ...
65+
tokio = { version = "1.15", features = ["full", "tracing"] }
66+
```
67+
68+
* The `tokio_unstable` cfg flag, which enables experimental APIs in Tokio, must
69+
be enabled. It can be enabled by setting the `RUSTFLAGS` environment variable
70+
at build-time:
71+
```shell
72+
$ RUSTFLAGS="--cfg tokio_unstable" cargo build
73+
```
74+
or, by adding the following to the `.cargo/config` file in a Cargo workspace:
75+
```toml
76+
[build]
77+
rustflags = ["--cfg", "tokio_unstable"]
78+
```
79+
### Adding the Console Subscriber
80+
81+
If the runtime emits compatible `tracing` events, enabling the console is as
82+
simple as adding the following line to your `main` function:
83+
84+
```rust
85+
console_subscriber::init();
86+
```
87+
88+
This sets the [default `tracing` subscriber][default] to serve console telemetry
89+
(as well as logging to stdout based on the `RUST_LOG` environment variable). The
90+
console subscriber's behavior can be configured via a set of
91+
[environment variables][env].
92+
93+
For programmatic configuration, a [builder interface][builder] is also provided:
94+
95+
```rust
96+
use std::time::Duration;
97+
98+
console_subscriber::TasksLayer::builder()
99+
// set how long the console will retain data from completed tasks
100+
.retention(Duration::from_secs(60))
101+
// set the address the server is bound to
102+
.server_addr(([127, 0, 0, 1], 5555))
103+
// ... other configurations ...
104+
.init();
105+
```
106+
107+
The layer provided by this crate can also be combined with other [`Layer`]s from
108+
other crates:
109+
110+
```rust
111+
use tracing_subscriber::prelude::*;
112+
113+
// spawn the console server in the background,
114+
// returning a `Layer`:
115+
let console_layer = console_subscriber::spawn();
116+
117+
// build a `Subscriber` by combining layers with a
118+
// `tracing_subscriber::Registry`:
119+
tracing_subscriber::registry()
120+
// add the console layer to the subscriber
121+
.with(console_layer)
122+
// add other layers...
123+
.with(tracing_subscriber::fmt::layer())
124+
// .with(...)
125+
.init();
126+
```
127+
128+
[`tracing`]: https://crates.io/crates/tracing
129+
[`tracing-subscriber`]: https://crates.io/crates/tracing-subscriber
130+
[`Layer`]:https://docs.rs/tracing-subscriber/0.3/tracing_subscriber/layer/index.html
131+
[default]: https://docs.rs/tracing/latest/0.1/dispatcher/index.html#setting-the-default-subscriber
132+
[env]: https://docs.rs/console-subscriber/0.1/console-subscriber/struct.builder#method.with_default_env
133+
[builder]: https://docs.rs/console-subscriber/0.1/console-subscriber/struct.builder
134+
[`tokio-console`]: https://github.com/tokio-rs/console
135+
[Tokio]: https://tokio.rs
136+
137+
### Crate Feature Flags
138+
139+
This crate provides the following feature flags and optional dependencies:
140+
141+
* [`parking_lot`]: Use the [`parking_lot`] crate's locks, rather than `std::sync`.
142+
Using [`parking_lot`] may result in improved performance, especially in highly
143+
concurrent applications. Disabled by default.
144+
145+
[`parking_lot`]: https://crates.io/crates/parking_lot
146+
147+
## Getting Help
148+
149+
First, see if the answer to your question can be found in the
150+
[API documentation]. If the answer is not there, there is an active community in
151+
the [Tokio Discord server][discord-url]. We would be happy to try to answer your
152+
question. You can also ask your question on [the discussions page][discussions].
153+
154+
[API documentation]: https://docs.rs/console-subscriber
155+
[discussions]: https://github.com/tokio-rs/console/discussions
156+
[discord-url]: https://discord.gg/tokio
157+
158+
## Contributing
159+
160+
&#x1f388; Thanks for your help improving the project! We are so happy to have
161+
you! We have a [contributing guide][guide] to help you get involved in the Tokio
162+
console project.
163+
164+
[guide]: https://github.com/tokio-rs/console/blob/main/CONTRIBUTING.md
165+
166+
## Supported Rust Versions
167+
168+
The Tokio console is built against the latest stable release. The minimum
169+
supported version is 1.56. The current Tokio console version is not guaranteed
170+
to build on Rust versions earlier than the minimum supported version.
171+
172+
## License
173+
174+
This project is licensed under the [MIT license].
175+
176+
[MIT license]: https://github.com/tokio-rs/console/blob/main/LICENSE
177+
178+
### Contribution
179+
180+
Unless you explicitly state otherwise, any contribution intentionally submitted
181+
for inclusion in Tokio by you, shall be licensed as MIT, without any additional
182+
terms or conditions.

Diff for: console-subscriber/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![doc = include_str!("../README.md")]
12
use console_api as proto;
23
use proto::resources::resource;
34
use serde::Serialize;

0 commit comments

Comments
 (0)