-
Notifications
You must be signed in to change notification settings - Fork 745
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
a bunch more backports #1381
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This backports the following commits to
v0.1.x
:From<EnteredSpan>
forOption<Id>
(tracing: implFrom<EnteredSpan>
forOption<Id>
#1325)Arc<dyn Subscriber + ...>
tracing
in a panic hook (tracing: add an example oftracing
in a panic hook #1375)Subscriber
impl forBox<dyn Subscriber + ...>
(core: addCollect
impl forBox<dyn Collect + ...>
#1358)I'm gonna merge this when CI passes & then hopefully do some releases.