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

backport boxed layer improvements ('n' stuff) #2033

Merged
merged 9 commits into from
Mar 29, 2022
Merged

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Mar 29, 2022

this branch backports the following commits to v0.1.x:

Note that I did not backport #2028 and #2030, because the the missing methods
they added are not missing on v0.1.x. Also, #2023 was changed to just include the
documentation change, because the v0.1.x impl already had correct bounds.

name1e5s and others added 9 commits March 29, 2022 14:51
## Motivation

Remove unused dev-dependencies, and update documentation
examples to use `std::future`.
... instead of `#[path = ""]` importing it everywhere.

Make sure to use a diff review tool that understands file renaming 😅
(GitHub's diff view does.)

## Motivation

Transparency: I want to use the mocking functionality in the development
of a tracing component out-of-tree.

Additionally, this reduces the use of `#[path] mod` and file
multiple-inclusion, which aren't that great of a practice.

## Solution

The tracing test support module was already well self-contained, due to
being `#[path] mod` used in multiple places. As such, extracting it to
its own crate is rather mechanical, with no surprising blockers.

We additionally move the tracing-futures support module contents into
tracing_mock, for convenience. The one function which relies on
tokio-test is made optional.

It's a reasonable result for this functionality to stay unpublished, and
only used inside the repo, but pulling it out into a directly reusable
chunk instead of abusing the module system to reuse it via
multiple-inclusion is an improvement to code structure and
modularization.
## Motivation

It took me several reads to understand why holding a guard over an await
was bad because my brain is naturally synchronous and could only think
about `my_async_function` and `some_other_async_function`

## Solution

Rather than just iterating "this is bad" use that opportunity to
introduce why. Remind the user that this is being executed concurrently
to other tasks

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Currently, there is an `impl<S: Subscriber> Layer for Box<dyn
Layer<S> + Send + Sync>` intended to allow type-erasing a subscriber.
This change improves the documentation on runtime configuration of
layers to include an example of using `Box` to type-erase a
layer.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
RustDoc didn't actually parse the link to the `Layer` impl for
`Box<dyn Layer<S> + Send + Sync>` because the link URL
contained unescaped spaces. Therefore, the link reference was treated as
normal text rather than as a link reference.

This commit replaces the link ref with the escaped version, which works
correctly. My bad!
Depends on #2023

## Motivation

Currently, `FmtLayer` holds a `PhantomData<S>` with the `Subscriber`
type it wraps. This is unfortunate because it means that the
layer's auto traits such as `Send`, `Sync`, and `'static` (as well
as `UnwindSafe`, `Unpin`, etc) depend on the `Subscriber` type's auto
traits...but the layer will never actually _store_ a value of type
`S`. While all `Subscriber` will be `Send + Sync + 'static` in practice,
the `PhantomData` means that functions returning a boxed `FmtLayer`
must unnecessarily bound the subscriber type parameter.

## Solution

This commit changes the `PhantomData` to `PhantomData<fn(S)>`, solving
the problem.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
## Motivation

PR #2023 made the `impl Layer` for boxed `dyn Layer` trait
objects actually be useful. One minor annoyance when working with boxed
trait objects is that, in some cases, in order to use `Box::new` to
erase a `Layer`'s type, it's necessary to add a type annotation like
this:
```rust
let boxed_layer: Box<dyn Layer<_> + Send + Sync + 'static>
    = Box::new(some_layer);
```

Because the trait object includes `Send + Sync + 'static`, this is a bit
wordy to type out.

## Solution

This commit adds a `Layer::boxed` method that takes `Self` and boxes
it as a type-erased `dyn Layer` trait object. This can then be
chained after a a chain of layer builder methods. Because the
`boxed` method _explicitly_ returns a `dyn Layer<_> + ...` trait
object, it's not necessary to use a wordy type annotation when
using this method.
…nsi_term (#2029)

## Motivation

EnvFilter with ansi_term will say something like the following when
statically disabled filters are present:

```
warning: some trace filter directives would enable traces ...
 = note: the static max level is `LEVEL`
 = help: to enable LEVEL logging, ...
```

Without the ansi_term feature, it instead says something like the
following:

```
warning: some trace filter directives would enable traces ...
note: the static max level is `LEVEL`
note: to enable LEVEL logging, ...
```

This is due to a simple error in cfg'd code that ignores the requested
prefix and always uses `note:` when `not(feature = "ansi_term")`.

## Solution

Use the unused `prefix` variable to do what it does when `feature =
"ansi_term"`.

The output without ansi_term is now

```
warning: some trace filter directives would enable traces ...
note: the static max level is `LEVEL`
help: to enable LEVEL logging, ...
```
@hawkw hawkw requested a review from a team as a code owner March 29, 2022 22:57
@hawkw hawkw enabled auto-merge (rebase) March 29, 2022 22:57
@hawkw hawkw merged commit 30204cb into v0.1.x Mar 29, 2022
@hawkw hawkw deleted the eliza/backport-2023 branch March 29, 2022 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants