Skip to content

Commit

Permalink
subscriber: don't print curly braces on spans with no fields
Browse files Browse the repository at this point in the history
Previously, when `tracing-subscriber`'s `fmt` module printed span
contexts, curly braces were only added around a span's fields. When we
replaced the previous implementation with the new `fmt::Layer`, this
behavior was lost, and empty curly braces were added to spans without
fields.

This commit fixes this by putting back the `if` conditional that used to
guard the printing of span fields.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
hawkw committed Feb 3, 2020
1 parent 506a482 commit f079f2d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tracing-subscriber/src/fmt/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,10 @@ where
let fields = &ext
.get::<FormattedFields<N>>()
.expect("Unable to find FormattedFields in extensions; this is a bug");
write!(f, "{}{}{}:", bold.paint("{"), fields, bold.paint("}"))
if !fields.is_empty() {
write!(f, "{}{}{}", bold.paint("{"), fields, bold.paint("}"))?;
}
f.pad(":")
})?;

if seen {
Expand Down

0 comments on commit f079f2d

Please sign in to comment.