Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

docs: add a step-by-step example for top-level lib documentation #12

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

ErichDonGubler
Copy link

@ErichDonGubler ErichDonGubler commented Nov 6, 2020

This shouldn't be the place where documentation stops being written (which is being discussed in #7), but it might be a good start. This is very similar to code you can already find in this repo's examples/basic.rs and documentation in other places, like the doc example for tracing_opentelemetry::OpenTelemetryLayer::new. The focus of these docs, though, is to demonstrate the usage of the API in an incremental style, so that single steps are as easy as possible to understand.

Things to do before merging:

  • This PR currently uses default rustfmt style, which is not the same as the rest of this project's style configuration. Problem?

  • --autosquash fixup! and squash! commits.

  • This currently won't be doctested because of this:

    #![cfg(not(doctest))]
    // unfortunately the proto code includes comments from the google proto files
    // that are interpreted as "doc tests" and will fail to build.
    // When this PR is merged we should be able to remove this attribute:
    // https://github.com/danburkert/prost/pull/291

    How problematic is this right now?

This shouldn't be the place where documentation stops being written, but
it might be a good start. adapting [the `basic` example][basic-example]
to have local imports (to make the source of symbols abundantly clear)
and changing the code's style to be as incremental as possible.

[basic-example]: https://github.com/vivint-smarthome/opentelemetry-stackdriver/blob/102ab6242a891798a8316db5f7bfca463c818507/examples/basic.rs
Copy link
Contributor

@djc djc left a comment

Choose a reason for hiding this comment

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

I definitely think this would be a good start. I would also appreciate more reference-style documentation about what each of the arguments mean.

src/lib.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
Move args for `StackDriverExporter::connect` to an order that matches
their usage.
Fix up remaining issues that would have been caught if doctests were
actually getting compiled right now. :<
New commit message:

This shouldn't be the place where documentation stops being written
(which is being discussed in vivint-smarthome#7), but it might be a good start. This is
very similar to code you can already find in this repo's
[`examples/basic.rs`][basic-example] and documentation in other places,
like [the doc example for
`tracing_opentelemetry::OpenTelemetryLayer::new`][open_telemetry_layer-new].
The focus of these docs, though, is to demonstrate the usage of the API
in an incremental style, so that single steps are as easy as possible to
understand.

[basic-example]: https://github.com/vivint-smarthome/opentelemetry-stackdriver/blob/102ab6242a891798a8316db5f7bfca463c818507/examples/basic.rs
[open_telemetry_layer-new]: https://docs.rs/tracing-opentelemetry/0.8.0/tracing_opentelemetry/struct.OpenTelemetryLayer.html#examples
//!
//! // An implementation of `futures::task::Spawn`, which allows our `StackDriverExporter` to
//! // run new tasks in an `async` runtime, as part of its work.
//! let spawn = {
Copy link
Contributor

Choose a reason for hiding this comment

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

So I think opentelemetry-stackdriver actually includes this under a feature flag. Maybe you should mention that and just use it here, because it's pretty much a distraction from the purpose of this example?

//! &spawn,
//! maximum_shutdown_duration,
//! num_concurrent_requests,
//! ).await.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be useful/interesting to point out why this is async in the first place. And also maybe mention explicitly (even if it's alluded to in the part about the Spawner) that this spawns a background task that's actually responsible for schlepping spans off to Stackdriver.

//! // A `tracing_subscriber::Registry` is a local backing store for span data -- it
//! let registry = tracing_subscriber::Registry::default();
//!
//! let subscriber = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I find the extra scope introduction distracting here, maybe skip that?

@djc
Copy link
Contributor

djc commented Nov 8, 2020

More remarks -- I'm a bit of a perfectionist, sorry, but this would definitely make for a large improvement in the overall documentation situation for this crate!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants