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

subscriber: if error occurs when formatting event, write error to Writer #2102

Merged

Conversation

bryangarza
Copy link
Member

@bryangarza bryangarza commented Apr 29, 2022

Motivation

When Format_event::format_event(...) returns an error, we are currently silently dropping that Event. tokio-rs/valuable#88 explains one such case in which this was encountered (due to a bug in valuable-serde). We want to be made aware whenever an Event is dropped.

Solution

Write to the Writer with an error message to let the user know that we were unable to format a specific event. If writing to the Writer fails, we fall back to writing to stderr. We are not emitting an actual tracing Event, to avoid the risk of a cycle (the new Event could trigger the same formatting error again).

Resolves #1965.

Testing

Added unit tests in fmt_layer.rs.

I also tested using @jaskij's repo: https://github.com/jaskij/valuable-serde-bug-reproduction.

diff --git a/not_working/Cargo.toml b/not_working/Cargo.toml
index 8907c81..9459e33 100644
--- a/not_working/Cargo.toml
+++ b/not_working/Cargo.toml
@@ -11,5 +11,5 @@ serde_json = "1.0.79"
 valuable = "0.1.0"
 valuable-derive = "0.1.0"
 valuable-serde = "0.1.0"
-tracing = "0.1.31"
-tracing-subscriber = { version = "0.3.9", features = ["json", "valuable"] }
+tracing = { path = "../../tracing/tracing" }
+tracing-subscriber = { path = "../../tracing/tracing-subscriber", features = ["json", "valuable"] }
% cargo run --bin tracing
    Finished dev [unoptimized + debuginfo] target(s) in 1.41s
     Running `/local/home/garzbrya/code/rs/valuable-serde-bug-reproduction/target/debug/tracing`
Unable to format the following event. Name: event not_working/src/bin/tracing.rs:17; Fields: Iter { idxs: 0..1, fields: FieldSet { names: ["test"], callsite: Identifier(0x55ba2bde4008) } }

I tried adding a Span, which then panics (when debug_assertions=true):

    Finished dev [unoptimized + debuginfo] target(s) in 1.61s
     Running `/local/home/garzbrya/code/rs/valuable-serde-bug-reproduction/target/debug/tracing`
thread 'main' panicked at 'internal error: entered unreachable code: `valuable::Valuable` implementations should always serialize successfully, but an error occurred: asdf FOO', /local/home/garzbrya/code/rs/tracing/tracing-subscriber/src/fmt/format/json.rs:484:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I think the Span case should be good enough (without addressing it in this PR)? I think anyone testing their code will hit the panic, because non-release builds do have debug_assertions=true by default.

Open Questions

Should I add a method to SubscriberBuilder to be able to enable/disable this behavior? If so, what should be the default, on or off?

Something like:

tracing_subscriber::fmt()
    .with_writer(std::io::stdout)
    .with_silence_errors(true) // This line
    .json()
    .init();

Edit: I did update the builder, in my second commit.

@bryangarza bryangarza requested review from hawkw and a team as code owners April 29, 2022 18:00
@jaskij
Copy link

jaskij commented Apr 29, 2022

I looked again at my code (albeit a quick look on mobile), and there's only info!, which is an event (exactly the same as the one you added), not a span.

@bryangarza
Copy link
Member Author

Oh, yeah you're right. Will retest..

Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

This seems like a fine solution!

One thought, though, is that it would be really nice to be able to expose any actual error message as well. However, doing that would be a bit more complex. For all the text-based formatters, the error generated would just be a fmt::Error, which doesn't have any interesting information attached to it. On the other hand, when using the JSON formatter, we get a potentially more useful serde serialization error...which, unfortunately, is currently always just discarded and replaced with fmt::Error, discarding any information about the error:

visit().map_err(|_| fmt::Error)?;

We could potentially print that error information if we changed the approach so that it's the FormatEvent implementations that are responsible for printing the error instead. However, this would mean that any arbitrary user-provided FormatEvent implementations would have to remember to add that themselves, while in your approach, tracing-subscriber would always ensure that the error is printed. So, there's a tradeoff there that's worth thinking about.

A third solution is to change the FormatEvent trait to allow it to return any arbitrary error type, rather than hard-coding fmt::Error. This would permit the JSON formatter to return serialization errors directly. However, this would be a breaking API change, so we'd have to save that for tracing-subscriber 0.4...

tracing-subscriber/src/fmt/fmt_layer.rs Outdated Show resolved Hide resolved
tracing-subscriber/src/fmt/fmt_layer.rs Outdated Show resolved Hide resolved
@hawkw
Copy link
Member

hawkw commented Apr 29, 2022

Some other things:

  • It would be nice to have some kind of test for this in tracing-subscriber itself, rather than just in the @jaskij's reproduction. We could probably test this with just a type that has a manual fmt::Debug implementation that just always returns fmt::Error --- that way, we wouldn't need to rely on valuable to test the way tracing-subscriber::fmt handles errors...
  • I think the builder option is probably a good idea? I would probably enable errors by default, I think.

@bryangarza
Copy link
Member Author

Yeah @jaskij so if I test with a span, and debug_assertions=true, we get panic

diff --git a/not_working/src/bin/tracing.rs b/not_working/src/bin/tracing.rs
index 76a1799..7861533 100644
--- a/not_working/src/bin/tracing.rs
+++ b/not_working/src/bin/tracing.rs
@@ -2,7 +2,7 @@
 mod valuable_anyhow;

 use anyhow::anyhow;
-use tracing::info;
+use tracing::{info, info_span};
 use valuable::Valuable;
 use valuable_anyhow::ValuableAnyhow;

@@ -14,5 +14,6 @@ fn main() {

     let err = anyhow!("asdf FOO");
     let va = ValuableAnyhow::from(err);
-    info!(test=va.as_value());
+    // info!(test=va.as_value());
+    info_span!("foo", test=va.as_value());
 }
thread 'main' panicked at 'internal error: entered unreachable code: `valuable::Valuable` implementations should always serialize successfully, but an error occurred: asdf FOO', /local/home/garzbrya/code/rs/tracing/tracing-subscriber/src/fmt/format/json.rs:484:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Not sure if that is good enough for the Span case, since everyone is probably building with debug_assertions=true during development (enabled by default in non-release builds)

@bryangarza
Copy link
Member Author

bryangarza commented Apr 29, 2022

@hawkw Regarding your comment about being able to actually see the original error (since we are just losing it due to fmt::Error), I do think that changing the return type to allow any arbitrary error type could be the best overall solution, because we can then take that error and use it from within tracing-subscriber itself, like we are doing in this PR. And then someone that is writing a FormatEvent impl doesn't have to deal with the error themselves.

Since that's a breaking change, one thing we could do in the meantime (maybe) would be to print the error directly for now:

 visit().map_err(|e| {
    // we can also add event.name here etc I think
    eprintln("Unable to serialize to JSON due to: {:?}", e);
    fmt::Error
})?; 

When `Format_event::format_event(...)` returns an error, we are
currently silently dropping that
Event. tokio-rs/valuable#88 explains one
such case in which this was encountered (due to a bug in
valuable-serde). We want to be made aware whenever an Event is dropped.

This patch adds a single `eprintln` line to let the user know that we
were unable to format a specific event. We are not emitting an actual
tracing Event, to avoid the risk of a cycle (the new Event could
trigger the same formatting error again).

Resolves tokio-rs#1965.
@bryangarza bryangarza force-pushed the feat-1965-stderr-for-subscriber-fmt-errors branch from 22b5873 to c725c8a Compare April 29, 2022 23:56
@bryangarza
Copy link
Member Author

I amended the original commit (wanted to correct the commit message)

@bryangarza
Copy link
Member Author

@hawkw created #2103 to track breaking change to FormatEvent, if we wanna do that separately.

@bryangarza bryangarza force-pushed the feat-1965-stderr-for-subscriber-fmt-errors branch from 533e1f1 to 9be1962 Compare April 30, 2022 00:48
…lder

Update the error-handling logic when calling `format_event` to write
the error message to the Writer. Only if that fails do we write to
stderr.

Define new method `SubscriberBuilder::with_silence_errors(bool)` so
that a user may disable this behavior. Enabled by default.

Add unit tests for both `silence_errors=true` and `false`.
@bryangarza bryangarza force-pushed the feat-1965-stderr-for-subscriber-fmt-errors branch from 9be1962 to aa64320 Compare April 30, 2022 00:51
@bryangarza
Copy link
Member Author

Ready for a second review :)

@bryangarza bryangarza changed the title subscriber: if error occurs when formatting event, print to stderr subscriber: if error occurs when formatting event, write error to Writer Apr 30, 2022
@bryangarza bryangarza requested a review from hawkw May 2, 2022 20:34
Copy link
Member

@davidbarsky davidbarsky left a comment

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 we should make this a toggle; this should probably be on by-default. It's not a breaking change, and if people are encountered this issue in the wild, I'd rather have subscriber break their log ingestion system loudly.

tracing-subscriber/src/fmt/fmt_layer.rs Outdated Show resolved Hide resolved
tracing-subscriber/src/fmt/mod.rs Outdated Show resolved Hide resolved
@hawkw
Copy link
Member

hawkw commented May 25, 2022

I don't think that we should make this a toggle; this should probably be on by-default. It's not a breaking change, and if people are encountered this issue in the wild, I'd rather have subscriber break their log ingestion system loudly.

I think it should definitely be possible to turn it off, but I'm fine with making it default to on.

tracing-subscriber/src/fmt/fmt_layer.rs Outdated Show resolved Hide resolved
tracing-subscriber/src/fmt/fmt_layer.rs Outdated Show resolved Hide resolved
@davidbarsky
Copy link
Member

I think it should definitely be possible to turn it off, but I'm fine with making it default to on.

Fair enough! In that case, the builder option should probably be renamed to something more descriptive. maybe .with_internal_error_logging, but I can see that being too wordy.

This patch updates `with_silence_errors` to be named
`with_silence_internal_errors`, and also updates the rustdocs so that
it's more clear what its behavior is.
@bryangarza
Copy link
Member Author

I think it should definitely be possible to turn it off, but I'm fine with making it default to on.

Fair enough! In that case, the builder option should probably be renamed to something more descriptive. maybe .with_internal_error_logging, but I can see that being too wordy.

I renamed to silence_internal_errors now 👍

This patch renames the `with_silence_internal_errors` flag to simply
`log_internal_errors`, and switches the default value to `true` since
the flag now represents the opposite idea.
@bryangarza
Copy link
Member Author

Renamed to log_internal_errors as per our Discord convo in #tracing-dev

@bryangarza bryangarza dismissed davidbarsky’s stale review July 13, 2022 22:38

All feedback up to this point has been addressed :)

@bryangarza bryangarza merged commit e4a6b57 into tokio-rs:v0.1.x Jul 25, 2022
@bryangarza bryangarza deleted the feat-1965-stderr-for-subscriber-fmt-errors branch July 25, 2022 16:44
davidbarsky added a commit that referenced this pull request Aug 24, 2022
…ter (#2102)

Motivation:
When `Format_event::format_event(...)` returns an error, we are
currently silently dropping that
Event. tokio-rs/valuable#88 explains one
such case in which this was encountered (due to a bug in
valuable-serde). We want to be made aware whenever an Event is dropped.

Solution:
Write to the Writer with an error message to let the user know that
we were unable to format a specific event. If writing to the Writer fails,
we fall back to writing to stderr. We are not emitting an actual tracing
Event, to avoid the risk of a cycle (the new Event could trigger the
same formatting error again).

Resolves #1965.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Co-authored-by: David Barsky <me@davidbarsky.com>
davidbarsky added a commit that referenced this pull request Aug 24, 2022
…ter (#2102)

Motivation:
When `Format_event::format_event(...)` returns an error, we are
currently silently dropping that
Event. tokio-rs/valuable#88 explains one
such case in which this was encountered (due to a bug in
valuable-serde). We want to be made aware whenever an Event is dropped.

Solution:
Write to the Writer with an error message to let the user know that
we were unable to format a specific event. If writing to the Writer fails,
we fall back to writing to stderr. We are not emitting an actual tracing
Event, to avoid the risk of a cycle (the new Event could trigger the
same formatting error again).

Resolves #1965.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Co-authored-by: David Barsky <me@davidbarsky.com>
davidbarsky added a commit that referenced this pull request Aug 24, 2022
…ter (#2102)

Motivation:
When `Format_event::format_event(...)` returns an error, we are
currently silently dropping that
Event. tokio-rs/valuable#88 explains one
such case in which this was encountered (due to a bug in
valuable-serde). We want to be made aware whenever an Event is dropped.

Solution:
Write to the Writer with an error message to let the user know that
we were unable to format a specific event. If writing to the Writer fails,
we fall back to writing to stderr. We are not emitting an actual tracing
Event, to avoid the risk of a cycle (the new Event could trigger the
same formatting error again).

Resolves #1965.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Co-authored-by: David Barsky <me@davidbarsky.com>
davidbarsky added a commit that referenced this pull request Aug 24, 2022
…ter (#2102)

Motivation:
When `Format_event::format_event(...)` returns an error, we are
currently silently dropping that
Event. tokio-rs/valuable#88 explains one
such case in which this was encountered (due to a bug in
valuable-serde). We want to be made aware whenever an Event is dropped.

Solution:
Write to the Writer with an error message to let the user know that
we were unable to format a specific event. If writing to the Writer fails,
we fall back to writing to stderr. We are not emitting an actual tracing
Event, to avoid the risk of a cycle (the new Event could trigger the
same formatting error again).

Resolves #1965.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Co-authored-by: David Barsky <me@davidbarsky.com>
davidbarsky added a commit that referenced this pull request Aug 24, 2022
…ter (#2102)

Motivation:
When `Format_event::format_event(...)` returns an error, we are
currently silently dropping that
Event. tokio-rs/valuable#88 explains one
such case in which this was encountered (due to a bug in
valuable-serde). We want to be made aware whenever an Event is dropped.

Solution:
Write to the Writer with an error message to let the user know that
we were unable to format a specific event. If writing to the Writer fails,
we fall back to writing to stderr. We are not emitting an actual tracing
Event, to avoid the risk of a cycle (the new Event could trigger the
same formatting error again).

Resolves #1965.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Co-authored-by: David Barsky <me@davidbarsky.com>
davidbarsky added a commit that referenced this pull request Aug 24, 2022
…ter (#2102)

Motivation:
When `Format_event::format_event(...)` returns an error, we are
currently silently dropping that
Event. tokio-rs/valuable#88 explains one
such case in which this was encountered (due to a bug in
valuable-serde). We want to be made aware whenever an Event is dropped.

Solution:
Write to the Writer with an error message to let the user know that
we were unable to format a specific event. If writing to the Writer fails,
we fall back to writing to stderr. We are not emitting an actual tracing
Event, to avoid the risk of a cycle (the new Event could trigger the
same formatting error again).

Resolves #1965.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Co-authored-by: David Barsky <me@davidbarsky.com>
davidbarsky added a commit that referenced this pull request Aug 24, 2022
…ter (#2102)

Motivation:
When `Format_event::format_event(...)` returns an error, we are
currently silently dropping that
Event. tokio-rs/valuable#88 explains one
such case in which this was encountered (due to a bug in
valuable-serde). We want to be made aware whenever an Event is dropped.

Solution:
Write to the Writer with an error message to let the user know that
we were unable to format a specific event. If writing to the Writer fails,
we fall back to writing to stderr. We are not emitting an actual tracing
Event, to avoid the risk of a cycle (the new Event could trigger the
same formatting error again).

Resolves #1965.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Co-authored-by: David Barsky <me@davidbarsky.com>
hawkw added a commit that referenced this pull request Aug 24, 2022
…ter (#2102)

Motivation:
When `Format_event::format_event(...)` returns an error, we are
currently silently dropping that
Event. tokio-rs/valuable#88 explains one
such case in which this was encountered (due to a bug in
valuable-serde). We want to be made aware whenever an Event is dropped.

Solution:
Write to the Writer with an error message to let the user know that
we were unable to format a specific event. If writing to the Writer fails,
we fall back to writing to stderr. We are not emitting an actual tracing
Event, to avoid the risk of a cycle (the new Event could trigger the
same formatting error again).

Resolves #1965.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Co-authored-by: David Barsky <me@davidbarsky.com>
hawkw added a commit that referenced this pull request Oct 6, 2022
# 0.3.16 (October 6, 2022)

This release of `tracing-subscriber` fixes a regression introduced in
[v0.3.15][subscriber-0.3.15] where `Option::None`'s `Layer`
implementation would set the max level hint to `OFF`. In addition, it
adds several new APIs, including the `Filter::event_enabled` method for
filtering events based on fields values, and the ability to log internal
errors that occur when writing a log line.

This release also replaces the dependency on the unmaintained
[`ansi-term`] crate with the [`nu-ansi-term`] crate, resolving an
*informational* security advisory ([RUSTSEC-2021-0139] for
[`ansi-term`]'s maintainance status. This increases the minimum
supported Rust version (MSRV) to Rust 1.50+, although the crate should
still compile for the previous MSRV of Rust 1.49+ when the `ansi`
feature is not enabled.

### Fixed

- **layer**: `Option::None`'s `Layer` impl always setting the
  `max_level_hint` to `LevelFilter::OFF` (#2321)
- Compilation with `-Z minimal versions` (#2246)
- **env-filter**: Clarify that disabled level warnings are emitted by
  `tracing-subscriber` (#2285)

### Added

- **fmt**: Log internal errors to `stderr` if writing a log line fails
  (#2102)
- **fmt**: `FmtLayer::log_internal_errors` and
  `FmtSubscriber::log_internal_errors` methods for configuring whether
  internal writer errors are printed to `stderr` (#2102)
- **fmt**: `#[must_use]` attributes on builders to warn if a
  `Subscriber` is configured but not set as the default subscriber
  (#2239)
- **filter**: `Filter::event_enabled` method for filtering an event
  based on its fields (#2245, #2251)
- **filter**: `Targets::default_level` accessor (#2242)

### Changed

- **ansi**: Replaced dependency on unmaintained `ansi-term` crate with
  `nu-ansi-term` ((#2287, fixes informational advisory
  [RUSTSEC-2021-0139])
- `tracing-core`: updated to [0.1.30][core-0.1.30]
- Minimum Supported Rust Version (MSRV) increased to Rust 1.50+ (when
  the `ansi`) feature flag is enabled (#2287)

### Documented

- **fmt**: Correct inaccuracies in `fmt::init` documentation (#2224)
- **filter**: Fix incorrect doc link in `filter::Not` combinator
  (#2249)

Thanks to new contributors @cgbur, @DesmondWillowbrook, @RalfJung, and
@poliorcetics, as well as returning contributors @CAD97, @connec,
@jswrenn, @guswynn, and @bryangarza, for contributing to this release!

[nu-ansi-term]: https://github.com/nushell/nu-ansi-term
[ansi_term]: https://github.com/ogham/rust-ansi-term
[RUSTSEC-2021-0139]: https://rustsec.org/advisories/RUSTSEC-2021-0139.html
[core-0.1.30]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.30
[subscriber-0.3.15]: https://github.com/tokio-rs/tracing/releases/tag/tracing-subscriber-0.3.15
hawkw added a commit that referenced this pull request Oct 6, 2022
# 0.3.16 (October 6, 2022)

This release of `tracing-subscriber` fixes a regression introduced in
[v0.3.15][subscriber-0.3.15] where `Option::None`'s `Layer`
implementation would set the max level hint to `OFF`. In addition, it
adds several new APIs, including the `Filter::event_enabled` method for
filtering events based on fields values, and the ability to log internal
errors that occur when writing a log line.

This release also replaces the dependency on the unmaintained
[`ansi-term`] crate with the [`nu-ansi-term`] crate, resolving an
*informational* security advisory ([RUSTSEC-2021-0139] for
[`ansi-term`]'s maintainance status. This increases the minimum
supported Rust version (MSRV) to Rust 1.50+, although the crate should
still compile for the previous MSRV of Rust 1.49+ when the `ansi`
feature is not enabled.

### Fixed

- **layer**: `Option::None`'s `Layer` impl always setting the
  `max_level_hint` to `LevelFilter::OFF` (#2321)
- Compilation with `-Z minimal versions` (#2246)
- **env-filter**: Clarify that disabled level warnings are emitted by
  `tracing-subscriber` (#2285)

### Added

- **fmt**: Log internal errors to `stderr` if writing a log line fails
  (#2102)
- **fmt**: `FmtLayer::log_internal_errors` and
  `FmtSubscriber::log_internal_errors` methods for configuring whether
  internal writer errors are printed to `stderr` (#2102)
- **fmt**: `#[must_use]` attributes on builders to warn if a
  `Subscriber` is configured but not set as the default subscriber
  (#2239)
- **filter**: `Filter::event_enabled` method for filtering an event
  based on its fields (#2245, #2251)
- **filter**: `Targets::default_level` accessor (#2242)

### Changed

- **ansi**: Replaced dependency on unmaintained `ansi-term` crate with
  `nu-ansi-term` ((#2287, fixes informational advisory
  [RUSTSEC-2021-0139])
- `tracing-core`: updated to [0.1.30][core-0.1.30]
- Minimum Supported Rust Version (MSRV) increased to Rust 1.50+ (when
  the `ansi`) feature flag is enabled (#2287)

### Documented

- **fmt**: Correct inaccuracies in `fmt::init` documentation (#2224)
- **filter**: Fix incorrect doc link in `filter::Not` combinator
  (#2249)

Thanks to new contributors @cgbur, @DesmondWillowbrook, @RalfJung, and
@poliorcetics, as well as returning contributors @CAD97, @connec,
@jswrenn, @guswynn, and @bryangarza, for contributing to this release!

[nu-ansi-term]: https://github.com/nushell/nu-ansi-term
[ansi_term]: https://github.com/ogham/rust-ansi-term
[RUSTSEC-2021-0139]: https://rustsec.org/advisories/RUSTSEC-2021-0139.html
[core-0.1.30]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.30
[subscriber-0.3.15]: https://github.com/tokio-rs/tracing/releases/tag/tracing-subscriber-0.3.15
hawkw added a commit that referenced this pull request Oct 6, 2022
# 0.3.16 (October 6, 2022)

This release of `tracing-subscriber` fixes a regression introduced in
[v0.3.15][subscriber-0.3.15] where `Option::None`'s `Layer`
implementation would set the max level hint to `OFF`. In addition, it
adds several new APIs, including the `Filter::event_enabled` method for
filtering events based on fields values, and the ability to log internal
errors that occur when writing a log line.

This release also replaces the dependency on the unmaintained
[`ansi-term`] crate with the [`nu-ansi-term`] crate, resolving an
*informational* security advisory ([RUSTSEC-2021-0139] for
[`ansi-term`]'s maintainance status. This increases the minimum
supported Rust version (MSRV) to Rust 1.50+, although the crate should
still compile for the previous MSRV of Rust 1.49+ when the `ansi`
feature is not enabled.

### Fixed

- **layer**: `Option::None`'s `Layer` impl always setting the
  `max_level_hint` to `LevelFilter::OFF` (#2321)
- Compilation with `-Z minimal versions` (#2246)
- **env-filter**: Clarify that disabled level warnings are emitted by
  `tracing-subscriber` (#2285)

### Added

- **fmt**: Log internal errors to `stderr` if writing a log line fails
  (#2102)
- **fmt**: `FmtLayer::log_internal_errors` and
  `FmtSubscriber::log_internal_errors` methods for configuring whether
  internal writer errors are printed to `stderr` (#2102)
- **fmt**: `#[must_use]` attributes on builders to warn if a
  `Subscriber` is configured but not set as the default subscriber
  (#2239)
- **filter**: `Filter::event_enabled` method for filtering an event
  based on its fields (#2245, #2251)
- **filter**: `Targets::default_level` accessor (#2242)

### Changed

- **ansi**: Replaced dependency on unmaintained `ansi-term` crate with
  `nu-ansi-term` ((#2287, fixes informational advisory
  [RUSTSEC-2021-0139])
- `tracing-core`: updated to [0.1.30][core-0.1.30]
- Minimum Supported Rust Version (MSRV) increased to Rust 1.50+ (when
  the `ansi`) feature flag is enabled (#2287)

### Documented

- **fmt**: Correct inaccuracies in `fmt::init` documentation (#2224)
- **filter**: Fix incorrect doc link in `filter::Not` combinator
  (#2249)

Thanks to new contributors @cgbur, @DesmondWillowbrook, @RalfJung, and
@poliorcetics, as well as returning contributors @CAD97, @connec,
@jswrenn, @guswynn, and @bryangarza, for contributing to this release!

[nu-ansi-term]: https://github.com/nushell/nu-ansi-term
[ansi_term]: https://github.com/ogham/rust-ansi-term
[RUSTSEC-2021-0139]: https://rustsec.org/advisories/RUSTSEC-2021-0139.html
[core-0.1.30]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.30
[subscriber-0.3.15]: https://github.com/tokio-rs/tracing/releases/tag/tracing-subscriber-0.3.15
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
…ter (tokio-rs#2102)

Motivation:
When `Format_event::format_event(...)` returns an error, we are
currently silently dropping that
Event. tokio-rs/valuable#88 explains one
such case in which this was encountered (due to a bug in
valuable-serde). We want to be made aware whenever an Event is dropped.

Solution:
Write to the Writer with an error message to let the user know that
we were unable to format a specific event. If writing to the Writer fails,
we fall back to writing to stderr. We are not emitting an actual tracing
Event, to avoid the risk of a cycle (the new Event could trigger the
same formatting error again).

Resolves tokio-rs#1965.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Co-authored-by: David Barsky <me@davidbarsky.com>
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
# 0.3.16 (October 6, 2022)

This release of `tracing-subscriber` fixes a regression introduced in
[v0.3.15][subscriber-0.3.15] where `Option::None`'s `Layer`
implementation would set the max level hint to `OFF`. In addition, it
adds several new APIs, including the `Filter::event_enabled` method for
filtering events based on fields values, and the ability to log internal
errors that occur when writing a log line.

This release also replaces the dependency on the unmaintained
[`ansi-term`] crate with the [`nu-ansi-term`] crate, resolving an
*informational* security advisory ([RUSTSEC-2021-0139] for
[`ansi-term`]'s maintainance status. This increases the minimum
supported Rust version (MSRV) to Rust 1.50+, although the crate should
still compile for the previous MSRV of Rust 1.49+ when the `ansi`
feature is not enabled.

### Fixed

- **layer**: `Option::None`'s `Layer` impl always setting the
  `max_level_hint` to `LevelFilter::OFF` (tokio-rs#2321)
- Compilation with `-Z minimal versions` (tokio-rs#2246)
- **env-filter**: Clarify that disabled level warnings are emitted by
  `tracing-subscriber` (tokio-rs#2285)

### Added

- **fmt**: Log internal errors to `stderr` if writing a log line fails
  (tokio-rs#2102)
- **fmt**: `FmtLayer::log_internal_errors` and
  `FmtSubscriber::log_internal_errors` methods for configuring whether
  internal writer errors are printed to `stderr` (tokio-rs#2102)
- **fmt**: `#[must_use]` attributes on builders to warn if a
  `Subscriber` is configured but not set as the default subscriber
  (tokio-rs#2239)
- **filter**: `Filter::event_enabled` method for filtering an event
  based on its fields (tokio-rs#2245, tokio-rs#2251)
- **filter**: `Targets::default_level` accessor (tokio-rs#2242)

### Changed

- **ansi**: Replaced dependency on unmaintained `ansi-term` crate with
  `nu-ansi-term` ((tokio-rs#2287, fixes informational advisory
  [RUSTSEC-2021-0139])
- `tracing-core`: updated to [0.1.30][core-0.1.30]
- Minimum Supported Rust Version (MSRV) increased to Rust 1.50+ (when
  the `ansi`) feature flag is enabled (tokio-rs#2287)

### Documented

- **fmt**: Correct inaccuracies in `fmt::init` documentation (tokio-rs#2224)
- **filter**: Fix incorrect doc link in `filter::Not` combinator
  (tokio-rs#2249)

Thanks to new contributors @cgbur, @DesmondWillowbrook, @RalfJung, and
@poliorcetics, as well as returning contributors @CAD97, @connec,
@jswrenn, @guswynn, and @bryangarza, for contributing to this release!

[nu-ansi-term]: https://github.com/nushell/nu-ansi-term
[ansi_term]: https://github.com/ogham/rust-ansi-term
[RUSTSEC-2021-0139]: https://rustsec.org/advisories/RUSTSEC-2021-0139.html
[core-0.1.30]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.30
[subscriber-0.3.15]: https://github.com/tokio-rs/tracing/releases/tag/tracing-subscriber-0.3.15
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