Skip to content

Conversation

dingxiangfei2009
Copy link
Contributor

@dingxiangfei2009 dingxiangfei2009 commented Oct 12, 2025

tracing at the time of writing has a feature (?) in its Filter implementation, so that filters like EnvFilter are consulted for status of a span or event and whether it is marked as interesting for logging. Combining a Filter with another layer through the with_filter combinator produces a filtered layer that enables an event unless it is statically determined that the event is uninteresting. However, if the filter is dynamic, because of filtering on span names or field values as an example, events are always enabled by design. There is an event_enabled predicate on EnvFilter implementation but it falls back to default and, thus, the dynamic filters are unused.

Previously, RUSTC_LOG=[] or RUSTC_LOG=[garbage] enables all events, even when spans do not match.

This patch re-enables span- and field-based filters. With RUSTC_LOG=[garbage] one should expect no events are enabled again. This will help with development greatly because we can meaningfully filter internal logs again.

`tracing` at the time of writing has a feature (?) in its Filter
implementation, so that filters like EnvFilter are consulted for status
of a span or event and whether it is marked as interesting for logging.
Combining a Filter with another layer through the `with_filter`
combinator produces a filtered layer that enables an event unless it is
statically determined that the event is uninteresting.
However, if the filter is dynamic, because of filtering on span names or
field values as an example, events are **always** enabled.
There is an `event_enabled` predicate on `EnvFilter` implementation but
it falls back to default and, thus, the dynamic filters are **unused**.

This patch re-enables span- and field-based filters.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 12, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 12, 2025

r? @jdonszelmann

rustbot has assigned @jdonszelmann.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@dingxiangfei2009 dingxiangfei2009 changed the title Move EnvFilter into its own layer Make logging filters work again by moving EnvFilter into its own layer Oct 12, 2025
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
...........................................        (143/143)

======== tests/rustdoc-gui/check-stab-in-docblock.goml ========

`tests/rustdoc-gui/check-stab-in-docblock.goml` check-stab-in-docblock output:
Waiting failed: 30000ms exceeded
stack: TimeoutError: Waiting failed: 30000ms exceeded
    at new WaitTask (/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/node_modules/puppeteer-core/lib/cjs/puppeteer/common/WaitTask.js:50:34)
    at IsolatedWorld.waitForFunction (/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Realm.js:25:26)
    at CdpFrame.waitForFunction (/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Frame.js:561:43)
    at CdpFrame.<anonymous> (/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/node_modules/puppeteer-core/lib/cjs/puppeteer/util/decorators.js:98:27)
    at CdpPage.waitForFunction (/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Page.js:1366:37)
    at runAllCommands (/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/node_modules/browser-ui-test/src/index.js:418:28)
    at async innerRunTestCode (/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/node_modules/browser-ui-test/src/index.js:696:21)
    at async innerRunTests (/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/node_modules/browser-ui-test/src/index.js:633:17)
    at async runTests (/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/node_modules/browser-ui-test/src/index.js:824:27)


======== tests/rustdoc-gui/search-result-display.goml ========

[WARNING] `tests/rustdoc-gui/search-result-display.goml` line 39: Delta is 0 for "x", maybe try to use `compare-elements-position` instead?

@jieyouxu jieyouxu closed this Oct 13, 2025
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 13, 2025
@jieyouxu jieyouxu reopened this Oct 13, 2025
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 13, 2025
@jdonszelmann
Copy link
Contributor

this seems useful, @bors r+ rollup

@bors
Copy link
Collaborator

bors commented Oct 13, 2025

📌 Commit 1e382a1 has been approved by jdonszelmann

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 13, 2025
@RalfJung
Copy link
Member

Cc @Stypox -- I hope this doesn't break the Miri profiling logic.

bors added a commit that referenced this pull request Oct 13, 2025
Rollup of 7 pull requests

Successful merges:

 - #144266 (Supress swapping lhs and rhs in equality suggestion in extern macro )
 - #147471 (Assert that non-extended temporaries and `super let` bindings have scopes)
 - #147533 (Renumber return local after state transform)
 - #147566 (rewrite outlives placeholder constraints to outlives static when handling opaque types)
 - #147613 (Make logging filters work again by moving EnvFilter into its own layer)
 - #147615 (reduce calls to attr.span() in old doc attr parsing)
 - #147636 (miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 806da59 into rust-lang:master Oct 13, 2025
18 of 20 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Oct 13, 2025
rust-timer added a commit that referenced this pull request Oct 13, 2025
Rollup merge of #147613 - dingxiangfei2009:investigate-log, r=jdonszelmann

Make logging filters work again by moving EnvFilter into its own layer

`tracing` at the time of writing has a feature (?) in its Filter implementation, so that filters like EnvFilter are consulted for status of a span or event and whether it is marked as interesting for logging. Combining a Filter with another layer through the `with_filter` combinator produces a filtered layer that enables an event unless it is statically determined that the event is uninteresting. However, if the filter is dynamic, because of filtering on span names or field values as an example, events are **always** enabled by design. There is an `event_enabled` predicate on `EnvFilter` implementation but it falls back to default and, thus, the dynamic filters are **unused**.

Previously, `RUSTC_LOG=[]` or `RUSTC_LOG=[garbage]` enables all events, even when spans do not match.

This patch re-enables span- and field-based filters. With `RUSTC_LOG=[garbage]` one should expect no events are enabled again. This will help with development greatly because we can meaningfully filter internal logs again.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Oct 15, 2025
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#144266 (Supress swapping lhs and rhs in equality suggestion in extern macro )
 - rust-lang/rust#147471 (Assert that non-extended temporaries and `super let` bindings have scopes)
 - rust-lang/rust#147533 (Renumber return local after state transform)
 - rust-lang/rust#147566 (rewrite outlives placeholder constraints to outlives static when handling opaque types)
 - rust-lang/rust#147613 (Make logging filters work again by moving EnvFilter into its own layer)
 - rust-lang/rust#147615 (reduce calls to attr.span() in old doc attr parsing)
 - rust-lang/rust#147636 (miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
@dingxiangfei2009 dingxiangfei2009 deleted the investigate-log branch October 16, 2025 19:18
@Stypox
Copy link
Contributor

Stypox commented Oct 17, 2025

@RalfJung I just tested the tracing logic and this PR indeed seems to break it:

  • commit 806da59 (i.e. this PR) produces an empty tracing file (probably because the tracing-chrome layer is somehow not attaching properly now?)
  • commit 7d0a0a3 (i.e. the parent commit of 806da59) does produce a tracing file (although at some point rustc crashes, because of a tracing call happening while formatting a parameter passed to another tracing call, which causes a RefCell to be borrowed twice; but this is a separate issue, I'll post a comment in Remove our RDTSC code? miri#4563)
  • The problem we faced in Allow initializing logger with additional tracing Layer #140969 was with some debug/info logs being printed even if they were disabled, which caused the CI to fail due to unexpected logs being printed out. This is not happening in this PR, but still leaving this here as a pointer.

@dingxiangfei2009
Copy link
Contributor Author

dingxiangfei2009 commented Oct 17, 2025

Hey @Stypox. Thanks for looking into this. How shall I reproduce the profiling problem in MIRI? I would like to try on my end, too.

.without_time()
.event_format(BacktraceFormatter { backtrace_target });
let subscriber = subscriber.with(fmt_layer);
let subscriber = subscriber.with(layer).with(fmt_layer).with(filter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This applies the filter to all layers. I think that's what breaks Miri, which is adding its own layer that needs to have a different filter.

@RalfJung
Copy link
Member

@Stypox thanks for taking a look!

@dingxiangfei2009

Combining a Filter with another layer through the with_filter combinator produces a filtered layer that enables an event unless it is statically determined that the event is uninteresting. However, if the filter is dynamic, because of filtering on span names or field values as an example, events are always enabled by design. There is an event_enabled predicate on EnvFilter implementation but it falls back to default and, thus, the dynamic filters are unused.

So are you saying that it is impossible to have two layers such that the first layer is dynamically filtered, but the 2nd layer always receives all events? That would be pretty bad...

@Stypox
Copy link
Contributor

Stypox commented Oct 17, 2025

How shall I reproduce the profiling problem in MIRI? I would like to try on my end, too.

See "From the rustc codebase" here: https://github.com/rust-lang/miri/blob/master/doc/tracing.md#from-the-rustc-codebase

After editing bootstrap and running the command you should get a .json file with some data in it (at least a few MB). If it's an empty JSON array, then something is off.

@dingxiangfei2009
Copy link
Contributor Author

but the 2nd layer always receives all events

Sadly that is the case.

Now I know better! It appears that a proper fix should happen in tracing. I am going to post a patch there to implement the missing event_enabled filter. I will post a patch here to revert the universal filter.

@RalfJung
Copy link
Member

I will post a patch here to revert the universal filter.

RUSTC_LOG worked fine until we shuffled around the layers for Miri tracing... we should fix that regression. rustc is bigger than Miri.

I am going to post a patch there to implement the missing event_enabled filter.

That's awesome, thanks :)

dingxiangfei2009 added a commit to dingxiangfei2009/tracing that referenced this pull request Oct 17, 2025
It turns out that the `event_enabled` is not yet implemented on
`EnvFilter`.

It has created issues that dynamic filters are effectively ignored,
when this filter is composed with another layer through `with_filter`
combinator.

Related to rust-lang/rust#147613

Signed-off-by: Xiangfei Ding <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants