-
Notifications
You must be signed in to change notification settings - Fork 701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Getting Started section in the README #403
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a good start, thanks for working on this! Here are some suggestions for improving the docs.
I've not had the chance to review the entire PR yet, so I'll probably have more notes later today.
README.md
Outdated
|
||
``` | ||
[dependencies] | ||
tracing = "0.1.5" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be the latest release version:
tracing = "0.1.5" | |
tracing = "0.1.10" |
README.md
Outdated
@@ -34,12 +34,93 @@ Application-level tracing for Rust. | |||
structured, event-based diagnostic information. `tracing` is maintained by the | |||
Tokio project, but does _not_ require the `tokio` runtime to be used. | |||
|
|||
## Getting Started | |||
|
|||
To get started, configure `Cargo.toml` to include `tracing` and `tracing-subscriber` as dependencies. `tracing` is the core library, while `tracing-subscriber` is the part that implements `Subscriber`, which will record the trace. Take a look at the [Project layout](#Project layout) section. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
To get started, configure `Cargo.toml` to include `tracing` and `tracing-subscriber` as dependencies. `tracing` is the core library, while `tracing-subscriber` is the part that implements `Subscriber`, which will record the trace. Take a look at the [Project layout](#Project layout) section. | |
To get started, add dependencies on `tracing` and `tracing-subscriber` to your `Cargo.toml`. The `tracing` crate provides the _instrumentation_ APIs for emitting traces, while `tracing-subscriber` provides implementations of the `Subscriber` trait, which will record the trace. For more information on the crates that make up the `tracing` project, take a look at the [Project layout](#Project layout) section. |
README.md
Outdated
|
||
Next, in our `main.rs` file, we will start by adding the libraries | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
``` | |
```rust |
to get Rust syntax highlighting here.
README.md
Outdated
|
||
To get started, configure `Cargo.toml` to include `tracing` and `tracing-subscriber` as dependencies. `tracing` is the core library, while `tracing-subscriber` is the part that implements `Subscriber`, which will record the trace. Take a look at the [Project layout](#Project layout) section. | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
``` | |
```toml |
to get toml syntax highlighting.
README.md
Outdated
|
||
For this simple example, we will create a function that prints sequence of numbers and we will instrument that cod to enable tracing. Tracing is enabled by initiating a span and the `#[instrument]` attribute, implicitly create a span for that function. | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``` | |
```rust |
README.md
Outdated
|
||
``` | ||
fn main() { | ||
// this creates subscriber with an environment filter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I'd prefer to start by introducing how to create and set a subscriber with the default filter
let subscriber = fmt::Subscriber::default();
tracing::subscriber::with_default(subscriber, || {
// ...
});
and then introduce customizing the filter after we demonstrate the default...
|
||
Then, in our `main()` function, we can create a subscriber, that records the trace. The subscriber employs an environment filter that we can utilize to filter the level of tracing message. | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``` | |
```rust |
|
||
Finally, we can run the function that prints out the tracing message while it's being run | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``` | |
```rust |
README.md
Outdated
let filter = tracing_subscriber::EnvFilter::try_from_default_env() | ||
.unwrap_or_else(|_| DEFAULT_FILTER.into()); | ||
let subscriber = fmt::Subscriber::builder().with_env_filter(filter).finish(); | ||
... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be nice if this was valid rust code that actually compiles...we could make the "..." a comment so it's not a syntax error:
... | |
// ... |
README.md
Outdated
|
||
``` | ||
fn main() { | ||
... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, consider:
... | |
// ... |
Thank you very much for the thorough comments @hawkw. I'll improve the PR :) |
hi @lunchboxav, now that the "batteries-included" |
sure thing @hawkw . I'll play around with |
Signed-off-by: Adityo Pratomo <adityo@tetrate.io>
PTAL @hawkw. I'm torn between keeping example of using subscriber's |
Should I close this PR as well @hawkw? Considering that the issue this PR wanted to solve has already solved. |
@lunchboxav hmm... sorry about that! i'll have to take a closer look at the examples in this PR vs the ones added in #496, as we may still want to add some of the examples in this branch as well! |
That’s completely fine @hawkw. I haven’t had the time too keep up with the recent movement in this repo, so I may missed some significant bits. Just let me know what I can help in this PR :) |
This PR addresses #384.
Motivation
I'm adding a Getting Started section in the README, which includes code and explanation. Hopefully, this will ease new users of tracing to get up to speed. The current doc is amazing, but adding an explicit Getting Started section might also be useful.
Solution
a Getting Started section with code example and a brief explanation of what the code does.