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

trace: Improve documentation #1148

Merged
merged 10 commits into from
Jun 25, 2019
Merged

trace: Improve documentation #1148

merged 10 commits into from
Jun 25, 2019

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Jun 13, 2019

Motivation

Currently, some parts of the tokio-trace documentation is unclear, and
some 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:

  • examples of setting metadata and overriding span parents in the
    macros
  • an explanation of what targets are,
  • added an explanation of the span follows-from relationship, and how
    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

@hawkw hawkw added T-docs Topic: documentation tokio-trace labels Jun 13, 2019
@hawkw hawkw added this to the tokio-trace v0.2 (breaking changes) milestone Jun 13, 2019
@hawkw hawkw requested review from jonhoo and LucioFranco June 13, 2019 22:25
@hawkw hawkw self-assigned this Jun 13, 2019
@hawkw
Copy link
Member Author

hawkw commented Jun 13, 2019

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

@@ -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.
Copy link
Sponsor Contributor

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 @@
//! # }
Copy link
Sponsor Contributor

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.

Copy link
Member Author

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.

Copy link
Sponsor Contributor

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
Copy link
Sponsor Contributor

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?

Copy link
Sponsor Contributor

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"?

Copy link
Member Author

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!

@jonhoo
Copy link
Sponsor Contributor

jonhoo commented Jun 14, 2019

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.

/// ```
///
/// By default, the module path to the current Rust module will be used
/// as the target, and the parent will be [determined contextually].
Copy link
Sponsor Contributor

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

tokio-trace/src/macros.rs Outdated Show resolved Hide resolved
tokio-trace/src/macros.rs Outdated Show resolved Hide resolved
tokio-trace/src/macros.rs Outdated Show resolved Hide resolved
tokio-trace/src/macros.rs Outdated Show resolved Hide resolved
tokio-trace/src/macros.rs Outdated Show resolved Hide resolved
tokio-trace/src/macros.rs Outdated Show resolved Hide resolved
tokio-trace/src/macros.rs Outdated Show resolved Hide resolved
@@ -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.
Copy link
Sponsor Contributor

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
Copy link
Sponsor Contributor

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?

Copy link
Sponsor Contributor

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?

Copy link
Sponsor Contributor

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?

tokio-trace/src/span.rs Outdated Show resolved Hide resolved
//!
//! 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,
Copy link
Sponsor Contributor

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.
Copy link
Sponsor Contributor

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
Copy link
Sponsor Contributor

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
Copy link
Sponsor Contributor

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
Copy link
Sponsor Contributor

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.
Copy link
Sponsor Contributor

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.
Copy link
Sponsor Contributor

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?

tokio-trace/src/span.rs Outdated Show resolved Hide resolved
@@ -7,8 +7,21 @@ use std::fmt;

/// Metadata describing a [span] or [event].
Copy link
Sponsor Contributor

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.

Copy link
Sponsor Contributor

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

Copy link
Sponsor Contributor

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.

Copy link
Member Author

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.

Copy link
Sponsor Contributor

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.

Copy link
Member Author

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!

@jonhoo
Copy link
Sponsor Contributor

jonhoo commented Jun 14, 2019

The link to "metadata" from Span::metadata is broken (the one from Event::metadata is not).

@jonhoo
Copy link
Sponsor Contributor

jonhoo commented Jun 14, 2019

Changes look good overall! I left some notes :)

@LucioFranco
Copy link
Member

I took a quick look through it looks great! Unfortunetly wont have time to review this but thank you for all the work @hawkw!

@hawkw
Copy link
Member Author

hawkw commented Jun 14, 2019

@jonhoo thanks so much for the extremely thorough review, I really appreciate it!

hawkw and others added 10 commits June 24, 2019 14:56
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>
@hawkw
Copy link
Member Author

hawkw commented Jun 24, 2019

@jonhoo in order to prepare for the repo move to tokio-rs/tracing, I'd like to merge these changes as-is (since I think they're better than the previous docs) and make some of your suggestions in a follow-up branch after the move. WDYT?

@davidbarsky
Copy link
Member

Opened tokio-rs/tracing#93 to track applying the rest of @jonhoo's suggestions.

@davidbarsky davidbarsky merged commit 448302c into master Jun 25, 2019
hawkw added a commit that referenced this pull request Jun 25, 2019
@carllerche carllerche deleted the eliza/improve-trace-docs branch June 27, 2019 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-docs Topic: documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants