Skip to content

Commit

Permalink
subscriber: fix bug in new_span for fmt layer
Browse files Browse the repository at this point in the history
  • Loading branch information
yaahc committed Mar 13, 2020
1 parent 77624f0 commit 5d95481
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions tracing-subscriber/src/fmt/fmt_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,19 +440,18 @@ where
fn new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) {
let span = ctx.span(id).expect("Span not found, this is a bug");
let mut extensions = span.extensions_mut();
if let Some(FormattedFields { ref mut fields, .. }) =
extensions.get_mut::<FormattedFields<N>>()
{
let _ = self.fmt_fields.format_fields(fields, attrs);
} else {
let mut buf = String::new();
if self.fmt_fields.format_fields(&mut buf, attrs).is_ok() {
let fmt_fields = FormattedFields {
fields: buf,
_format_event: PhantomData::<fn(N)>,
};
extensions.insert(fmt_fields);
}

if extensions.get_mut::<FormattedFields<N>>().is_some() {
return;
}

let mut buf = String::new();
if self.fmt_fields.format_fields(&mut buf, attrs).is_ok() {
let fmt_fields = FormattedFields {
fields: buf,
_format_event: PhantomData::<fn(N)>,
};
extensions.insert(fmt_fields);
}
}

Expand Down

0 comments on commit 5d95481

Please sign in to comment.