Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

lunchboxav
Copy link
Contributor

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.

Copy link
Member

@hawkw hawkw left a 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"
Copy link
Member

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:

Suggested change
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

Suggested change
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

```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add

Suggested change
```
```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.

```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add

Suggested change
```
```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.

```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```
```rust

README.md Outdated

```
fn main() {
// this creates subscriber with an environment filter
Copy link
Member

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.

```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```
```rust


Finally, we can run the function that prints out the tracing message while it's being run

```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```
```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();
...
Copy link
Member

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:

Suggested change
...
// ...

README.md Outdated

```
fn main() {
...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, consider:

Suggested change
...
// ...

@lunchboxav
Copy link
Contributor Author

Thank you very much for the thorough comments @hawkw. I'll improve the PR :)

@hawkw
Copy link
Member

hawkw commented Nov 7, 2019

hi @lunchboxav, now that the "batteries-included" init and try_init functions in tracing-subscriber::fmt have been released in version 0.1.6, can we use them in the introductory docs when applicable? should be more ergonomic for simple tasks

@lunchboxav
Copy link
Contributor Author

sure thing @hawkw . I'll play around with init and try-init and I'll update the doc. Should be good for setting up subscriber for getting started.

Signed-off-by: Adityo Pratomo <adityo@tetrate.io>
@lunchboxav
Copy link
Contributor Author

PTAL @hawkw. I'm torn between keeping example of using subscriber's default or just remove it since we have init. I'm keeping both for now, but I'm open to the idea of just use init as a preferred way to get started with tracing.

@hawkw hawkw added the meta/finish-line PRs that need just a bit more work to be ready to merge. label Dec 20, 2019
@lunchboxav
Copy link
Contributor Author

Should I close this PR as well @hawkw? Considering that the issue this PR wanted to solve has already solved.

@hawkw
Copy link
Member

hawkw commented Jan 9, 2020

@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!

@lunchboxav
Copy link
Contributor Author

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 :)

@hawkw hawkw closed this Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta/finish-line PRs that need just a bit more work to be ready to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants