-
Notifications
You must be signed in to change notification settings - Fork 717
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
tracing-core: registering a callsite from within dispatcher::get_default()
sets interest to Never
#2400
Comments
Hmm I think it's not actually This makes sense as upon further investigation I don't even get to the point of constructing the event before I've run into the never interest. |
I figured it out. I was calling Skimming the code it appears to be a consequence of the optimization in In fact, just applying the following diff, which disables this optimization, causes my code to work: builder.init();
+tracing_core::dispatcher::with_default(&tracing_subscriber::fmt().finish().into(), || {}); This causes the most recent dispatch registration to occur when there's two dispatches, and therefore it skips the optimization. It's mildly interesting here that this also demonstrates that a dispatch going out of scope doesn't recalculate the optimization, it only does it when registering a new dispatch, which means temporarily switching to another dispatch will break the optimization. |
To clarify, in the broken case, my code basically did: tracing_core::dispatcher::get_default(|dispatch| {
let callsite = registry::callsite(record);
let interest = callsite.interest();
if !interest.is_never() {
if interest.is_always() || dispatch.enabled(callsite.metadata()) {
// … The fix in my code was to move the first two lines out of the call to |
dispatcher::get_default()
sets interest to Never
Bug Report
Version
Platform
darwin (macOS 13)
Crates
tracing-core
Description
I have an internal crate that implements a bridge to
tracing
, which includes its ownCallsite
implementation (this predates the introduction ofDefaultCallsite
). This was originally written againsttracing-core 0.1.20
. When testing today, it now registers an interest ofNever
against my callsites, thus disabling them.This occurs when logging events created with
tracing_core::Event::new(metadata, fields)
. If I create events withtracing_core::Event::new_child_of(Some(parent_id), metadata, fields)
then it works fine (I haven't explicitly testednew_child_of(None, metadata, fields)
but from the internal issue, I believe that fails also).This code worked fine up through
tracing-core 0.1.26
and breaks intracing-core 0.1.27
(still broken in0.1.30
). I haven't narrowed down the cause yet, all I know so far is that whenset_interest
is called it's givenInterest(Never)
. The call stack looks roughly likeIn particular, my code is following the pattern where the logging code fetches/constructs the callsite, then calls
interest()
, which checks for cached interest, and since it has none it callsself.register()
, which invokestracing_core::callsite::register()
if it hasn't already done so. This then invokesset_interest()
with theInterest(Never)
value.I need to dig into this further, but I don't understand why I'm getting an
Interest(Never)
here, I've already set up the global subscriber. It feels almost like it thinks I have no subscriber yet, except this is only affecting my custom log bridge and isn't affecting nativetracing
events.I think
DefaultCallsite
might be able to replace my custom one, so I'll try that, and if it doesn't work then I'll keep looking. But the fact thattracing-core 0.1.27
broke my existing code is very concerning.The text was updated successfully, but these errors were encountered: