Skip to content

Commit

Permalink
subscriber: if error occurs when formatting event, print to stderr
Browse files Browse the repository at this point in the history
When `Format_event::format_event(...)` returns an errror, we are
currently silently dropping that
Span/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 a Span/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 #1965.
  • Loading branch information
bryangarza committed Apr 29, 2022
1 parent 45c0a10 commit 22b5873
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tracing-subscriber/src/fmt/fmt_layer.rs
Expand Up @@ -896,6 +896,8 @@ where
{
let mut writer = self.make_writer.make_writer_for(event.metadata());
let _ = io::Write::write_all(&mut writer, buf.as_bytes());
} else {
eprintln!("[tracing-subscriber] Unable to format the following event: {:?}", event);
}

buf.clear();
Expand Down

0 comments on commit 22b5873

Please sign in to comment.