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

a bunch more backports #1381

Merged
merged 7 commits into from
Apr 30, 2021
Merged

a bunch more backports #1381

merged 7 commits into from
Apr 30, 2021

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Apr 30, 2021

This backports the following commits to v0.1.x:

I'm gonna merge this when CI passes & then hopefully do some releases.

Folyd and others added 7 commits April 30, 2021 10:57
This PR simply fixes some cargo docs warnings.
Filtering log events using the `target[span{field=value}]=level` syntax
doesn't work when the span name contains a special char.

This PR closes #1367 by adding support for span names with any
characters other than `{` and `]` to `EnvFilter`.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
In some cases, users may wish to erase the type of a `Subscriber`
implementation, such as when it is dynamically constructed from a
complex parameterized type. When doing so, it's important to ensure that
all trait methods with default implementations are properly forwarded to
the inner erased type. For example, if the type does not implement
`try_close`, but the inner erased subscriber does, then the the
subscriber will not be notified when spans close — which could result in
a memory leak.

To avoid potential footguns resulting from users implementing
type-erased subscribers incorrectly, this branch adds a new `impl
Subscriber for Box<dyn Subscriber + Send + Sync + 'static>` in
`tracing-core`. This is also somewhat more ergonomic than any solution
in another crate, since the implementation  is for `Box<dyn Subscriber +
...>` directly, rather than some `BoxedSubscriber` newtype.
It turns out that when using the global dispatcher, emitting tracing
events in a panic hook will capture the span in which the program
panicked. This is very handy for debugging panics! Thanks a lot to
@nate_mara for pointing this out to me on twitter --- I hadn't even
thought of it!

Since it isn't necessarily immediately obvious that this works, I
thought it would be nice to add an example.
## Motivation (#1374)

Users may wish to erase the type of a `Subscriber`
implementation, such as when it is dynamically constructed from a
complex parameterized type. PR #1358 added a `Subscriber` implementation
for `Box<dyn Subscriber + Send + Sync + 'static>`, allowing the use of
type-erased trait objects. In some cases, it may also be useful to share
a type-erased subscriber, _without_ using `Dispatch` --- such as when
different sets of `tracing-subscriber` subscribers are layered on one
shared subscriber.

## Solution

This branch builds on #1358 by adding an `impl Subscriber for Arc<dyn
Subscriber + Send + Sync + 'static>`. I also added quick tests for both
`Arc`ed and `Box`ed subscribers.

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

<!--
Explain the context and why you're making that change. What is the problem
you're trying to solve? If a new feature is being added, describe the intended
use case that feature fulfills.
-->

The following code compiles failed:
```rust
use tracing;

fn main() {

    let span = tracing::info_span!("my_span").entered();
    tracing::info!(parent: &span, "test span");
}
```

```log
   Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `Option<Id>: From<&EnteredSpan>` is not satisfied
  --> src/main.rs:6:5
   |
6  |     tracing::info!(parent: &span, "test span");
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<&EnteredSpan>` is not implemented for `Option<Id>`
```

## Solution

- `impl<'a> From<&'a EnteredSpan> for Option<&'a Id>`.
- `impl<'a> From<&'a EnteredSpan> for Option<Id>`
- Add `id()` method into `EnteredSpan`.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
## Motivation

`span.in_scope()` had a link def in the main tracing docs which was
unused, this function is quite handy to know about and I almost
re-implemented something similar to it.

I almost reimplemented this as a macro.


## Solution

Document it at top-level!

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
@hawkw hawkw requested a review from a team as a code owner April 30, 2021 18:12
@hawkw hawkw merged commit 848ee2d into v0.1.x Apr 30, 2021
@hawkw hawkw deleted the eliza/backport-1368 branch April 30, 2021 18:27
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.

4 participants