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

event!(parent: span, …) (instead of parent: &span) logs event with no parent #1873

Open
lilyball opened this issue Jan 28, 2022 · 1 comment
Milestone

Comments

@lilyball
Copy link
Contributor

lilyball commented Jan 28, 2022

Bug Report

Version

├── tracing v0.1.29
│   ├── tracing-attributes v0.1.18 (proc-macro)
│   └── tracing-core v0.1.21
└── tracing-subscriber v0.3.7
    ├── tracing-core v0.1.21 (*)
    └── tracing-log v0.1.2
        └── tracing-core v0.1.21 (*)

Platform

macOS 12.1 (21C52)

Crates

tracing

Description

The event macros (event!, info!, warn!, etc) accept an optional parent: argument for specifying the parent span. It takes anything that can be passed to Event::child_of(), which means anything that implements Into<Option<Id>>.

Typical usage looks like info!(parent: &span, "message"), but it turns out that Span itself implements Into<Option<Id>>, which means you can write info!(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 of Event::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 both Span and &Span, but this would produce an error message about Borrow 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).

@hawkw
Copy link
Member

hawkw commented Jan 29, 2022

See also #688. This will be fixed in 0.2; unfortunately there's no good way to fix it without a breaking change.

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

No branches or pull requests

3 participants