-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
trace: Improve documentation #1148
Conversation
@jonhoo and @LucioFranco, since a lot of the additions here are from improvements you suggested, I'd love to get your feedback on this when you have the chance. |
tokio-trace/src/lib.rs
Outdated
@@ -27,9 +27,9 @@ | |||
//! The core of `tokio-trace`'s API is composed of `Event`s, `Span`s, and | |||
//! `Subscriber`s. We'll cover these in turn. |
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.
nit: maybe make the order here the same as the order they're explained in below?
@@ -49,153 +49,7 @@ | |||
//! # } |
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.
I think if we're not going to give any more stuff here on spans, it'd be good to make this example a little more expansive. I would also avoid using the word "context" here, because as far as I've gathered, it's entirely up to the subscriber whether or not work done below .enter()
is considered "in the context of" the span. The span only serves to build a pair of start and end events, and does not say anything about events "contained" within that.
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.
I think if we're not going to give any more stuff here on spans, it'd be good to make this example a little more expansive
I thought the docs would be more readable if more of the content in the lib-level docs was pulled out into module-level docs, so the reader isn't immediately presented with a massive wall of text. The hope was that the lib docs would serve as an overview/table of contents, and most of the actual documentation would live in the appropriate module. I'd love to know if you think this is actually a good way to structure things, or if it's not working for you?
That said, I can definitely add a more complete example here. I wasn't sure about including an example that shows a lot of concepts that haven't been introduced yet in the documentation, though?
I would also avoid using the word "context" here, because as far as I've gathered, it's entirely up to the subscriber whether or not work done below .enter() is considered "in the context of" the span. The span only serves to build a pair of start and end events, and does not say anything about events "contained" within that.
I think there is an expectation that there's some concept of "context", but the policy of what a "context" means is up to the subscriber. I'll try and edit these docs to make it clearer that this is provided by the subscriber implementation.
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.
Oh, sorry, let me rephrase: I think it's great to move things out of the top-level docs the way you have. I meant more that given that you're going to do that, the examples that are left behind should probably be slightly more elaborate than the examples that were there before. I don't think it's too problematic to have more complex concepts in the example here, since the user will know that to get a detailed explanation they should go to the module-level docs.
//! create a single span around the entire loop; whereas if we wanted to know how | ||
//! much time was spent in each individual iteration, we would enter a new span | ||
//! on every iteration. | ||
//! The [`span` module]'s documentation provides further details on how to use spans. | ||
//! | ||
//! ## Events |
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 section reinforces the belief that a span establishes a "context", which again does not match my understand of what Spans actually mean?
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.
Further down, this text also says:
Events are represented as a special case of spans — they are created, they may have fields added, and then they close immediately, without being entered.
Is that true? I thought events weren't just "immediate spans"?
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.
Is that true? I thought events weren't just "immediate spans"?
That sentence is no longer correct, I think it was written when this was the case and then it was never removed. I must've missed that while working on this branch, since I was mostly just looking at the span docs. Thanks for catching that!
Reading through it now! As a note for a possibly later PR, I think the "In libraries" is one of the most important and difficult sections, and it is currently basically empty. |
tokio-trace/src/macros.rs
Outdated
/// ``` | ||
/// | ||
/// By default, the module path to the current Rust module will be used | ||
/// as the target, and the parent will be [determined contextually]. |
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.
I don't think that what this links to is useful. Is "contextual spans" explained anywhere else (like in the Span
docs)?
@@ -1,6 +1,50 @@ | |||
//! Spans represent periods of time in the execution of a program. | |||
//! Spans represent periods of time in which a program was executing in a | |||
//! particular context. |
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.
I thought a span explicitly did not establish context, and was only a period of time? Anything else is up to the subscriber, no?
//! | ||
//! # Entering a Span | ||
//! A span consists of [fields], user-defined key-value pairs of arbitrary data | ||
//! that describe the context the span represents, and [metadata], a fixed set |
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.
Other docs refer to these just as attributes. Should we use "metadata" everywhere, or "attributes" everywhere?
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.
Actually, aren't the two distinct? Is there a difference between Attributes
and Metadata
? What is it? Which do you mean here?
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.
Is Metadata
attributes and fields maybe?
//! | ||
//! The [`Attributes`] type contains data associated with a span, and is | ||
//! provided to the [`Subscriber`] when a new span is created. It contains | ||
//! the span's metadata, the ID of the span's parent if one was explicitly set, |
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.
I think somewhere needs to talk about the relationship between spans and how it is or is not determined. When reading this sentence, I had several questions:
- What if it isn't set?
- What happens if I set it to something "wrong"?
- What are the implications of setting one span as another's "parent"?
//! the span's metadata, the ID of the span's parent if one was explicitly set, | ||
//! and any fields whose values were recorded when the span was constructed. | ||
//! The subscriber may then choose to cache the data for future use, record | ||
//! it in some manner, or discard it completely. |
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 last sentence is pretty vague given that I (currently) have no idea what a subscriber is if I have followed the docs thus far. I think elaborating a bit here would be worthwhile.
//! | ||
//! # The Span Lifecycle | ||
//! | ||
//! ## Entering a Span | ||
//! | ||
//! A thread of execution is said to _enter_ a span when it begins executing, | ||
//! and _exit_ the span when it switches to another context. Spans may be |
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.
What does "switches to another context" mean?
//! | ||
//! # The Span Lifecycle | ||
//! | ||
//! ## Entering a Span |
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.
I think this is missing an explanation of what "entering a span" even means in the first place.
//! | ||
//! Spans form a tree structure — unless it is a root span, all spans have a | ||
//! _parent_, and may have one or more _children_. When a new span is created, | ||
//! the current span becomes the new span's parent. The total execution time of |
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 answers some of the questions from above, but raises a few more:
- How is the "current" span determined?
- What if I have entered multiple spans?
- Is this actually guaranteed, or dependent on the subscriber?
//! the current span becomes the new span's parent. The total execution time of | ||
//! a span consists of the time spent in that span and in the entire subtree | ||
//! represented by its children. Thus, a parent span always lasts for at least | ||
//! as long as the longest-executing span in its subtree. |
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.
Is that true? That seems weird. What if I have the following:
let a = trace_span!("a");
let b = trace_span!("b");
let ag = a.enter();
let bg = b.enter();
drop(ag);
// what happens to events here? are they in a or not? is this behavior guaranteed?
drop(bg);
//! A child span should typically be considered _part_ of its parent. For | ||
//! example, if a subscriber is recording the length of time spent in various | ||
//! spans, it should generally include the time spent in a span's children as | ||
//! part of that span's duration. |
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.
Does that mean that time in children is double-counted? Once in the parent and once in the child?
@@ -7,8 +7,21 @@ use std::fmt; | |||
|
|||
/// Metadata describing a [span] or [event]. |
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.
The [event]
link here is broken.
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.
Sorry, it is broken in tokio-trace::Metadata
, not in tokio-trace-core::Metadata
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.
Related to that, is there any way for the two to be the same? Why are they distinct types with different docs (the docs for tokio-trace::Metadata
haven't been updated to reflect the change below for example.
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.
They're the same type; tokio-trace::Metadata
is a re-export of tokio-trace-core::Metadata
. I think the issue is that tokio-trace
depends on the crates.io version of tokio-trace-core
, rather than the local version, so the changes I've made to the -core
docs since the last crates.io release aren't reflected in the tokio-trace
docs.
I'll publish a tokio-trace-core
point release before publishing tokio-trace
0.2, so I think this should be resolved. In the meantime, you can patch tokio-trace
's dependency on tokio-trace-core
to see the docs as they should be.
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.
Ohh, I see. No worries, I just generated docs for tokio-trace-core
explicitly. I think the [event]
link is still broken though.
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.
I'll double check that one!
The link to "metadata" from |
Changes look good overall! I left some notes :) |
I took a quick look through it looks great! Unfortunetly wont have time to review this but thank you for all the work @hawkw! |
@jonhoo thanks so much for the extremely thorough review, I really appreciate it! |
Fixes #1065 Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Fixes #1064 Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Fixes #985 Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Co-Authored-By: Jon Gjengset <jon@thesquareplanet.com>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
74273d4
to
2d9657c
Compare
@jonhoo in order to prepare for the repo move to |
Opened tokio-rs/tracing#93 to track applying the rest of @jonhoo's suggestions. |
Motivation
Currently, some parts of the
tokio-trace
documentation is unclear, andsome concepts are not described adequately. In addition, the
organization of the docs can be improved and made less redundant. For
example, the lib-level documentation has examples of the shorthand
syntax for fields that is repeated in the span macro's documentation.
This could be changed so that the lib and module-level documentation
provides an overview and the individual items go into greater detail.
Solution
This branch reorganizes the documentation and adds better explanations
of some concepts that were previously unclear. In particular, I've
added:
macros
it differs from parent/child relationships
I've also fixed up some typos and broken links.
Fixes #1063
Fixes #1064
Fixes #1065
Fixes #985
Fixes #907