event!(parent: span, …)
(instead of parent: &span
) logs event with no parent
#1873
Milestone
event!(parent: span, …)
(instead of parent: &span
) logs event with no parent
#1873
Bug Report
Version
Platform
macOS 12.1 (21C52)
Crates
tracing
Description
The event macros (
event!
,info!
,warn!
, etc) accept an optionalparent:
argument for specifying the parent span. It takes anything that can be passed toEvent::child_of()
, which means anything that implementsInto<Option<Id>>
.Typical usage looks like
info!(parent: &span, "message")
, but it turns out thatSpan
itself implementsInto<Option<Id>>
, which means you can writeinfo!(parent: span, "message")
and this compiles cleanly.Unfortunately, writing that means the event is logged with no parent span at all. My assumption is that
span.into()
results in the span being immediately closed, and therefore not available when formatting the event. This also means there's no contextual span either.The proper fix is to remove the
impl From<Span> for Option<Id>
impl. This is the correct fix because it also fixes direct usage ofEvent::child_of
/Event::new_child_of
. This is of course a breaking change. And unfortunately Rust doesn't let you deprecate trait impls so we can't even do that.In the meantime, the macros could potentially do something like
Event::child_of(span.borrow(), …)
. Experimentally, tossing a.borrow()
on there works for bothSpan
and&Span
, but this would produce an error message aboutBorrow
itself if I try using e.g.&&Span
, which is not great (&&Span
isn't supported today, but the error message it produces is more relevant).The text was updated successfully, but these errors were encountered: