rust/src/tools
Matthias Krüger 4bf5787e2b
Rollup merge of #143955 - Stypox:tracing-frame-filter, r=RalfJung
Make frame spans appear on a separate trace line

This PR changes tracing_chrome's `tracing::Layer` so that if a span has the "tracing_separate_line" field as one of the span arguments, that span is put on a separate trace line. See https://github.com/rust-lang/miri/pull/4451 for an earlier attempt and for screenshots explaining better what I mean by "separate trace line".

This PR also makes the "frame" span use this feature (so it appears on a separate trace line, see https://github.com/rust-lang/miri/pull/4451 for motivation), but passes `tracing::field::Empty` as the span parameter value so it is ignored by other tracing layers (e.g. the logger):

```rust
info_span!("frame", tracing_separate_line = Empty, "{}", instance);
```

<details><summary>Also see the following discussion I had with ``@RalfJung</summary>``

> Is there no way to attach metadata we could use instead?

[These](https://docs.rs/tracing-core/0.1.34/src/tracing_core/metadata.rs.html#57) are the **static** metadata items we can control about a span. We can't add more metadata outside of them. The most relevant are:
- `name` (for the frame span it's currently "frame")
- `target` which acts as the category (for the frame span it's currently "rustc_const_eval::interpret::stack" by default)
- `fields` which contains a list of the *names* of each of the arguments passed to the `span!` macro (for the frame span it's currently ["message"], where "message" is the default identifier for data passed in the `format!` syntax)

When the tracing code is called at runtime, the **dynamic** values of the arguments are collected into a [`ValueSet`](https://docs.rs/tracing-core/0.1.34/src/tracing_core/field.rs.html#166). Each argument value stored there corresponds with one of the static names stored in `fields` (see above).

---

We have already determined that filtering out spans by `name` is not a good idea, and I would say the same goes for `target`. Both the `name` and the `target` fields are printed to stderr when `MIRI_LOG=` is enabled, so changing them to contain an identifier (e.g. "frame:tracing_separate_root" instead of "frame" as the name) would uselessly clutter the text logs (unless we add one more filter [there](https://github.com/rust-lang/rust/blob/master/compiler/rustc_log/src/lib.rs#L137), but then it gets even more complicated).

```rust
// examples of how the above (problematic) solutions would look like
info_span!("frame:tracing_separate_root", "{}", instance);
info_span!(target: "tracing_separate_root", "frame", "{}", instance);
```

---

So that leaves us with `fields` and their runtime values. Now, my initial thought (inspired by [this comment](https://github.com/rust-lang/miri/pull/4451#issuecomment-3068072303)) was to use a field with the static name "tracing_separate_root" and with a dynamic boolean value of "true". In `tracing_chrome.rs` we can easily check if this field is true and act accordingly. This would work but then again this field would also be picked up by the logger when `MIRI_LOG=` is enabled, and would uselessly clutter the text logs.

```rust
// example of how the above (problematic) solution would look like
info_span!("frame", tracing_separate_root = true, "{}", instance);
```

---

To avoid cluttering the text logs, we can instead set "tracing_separate_root" to the dynamic value of `tracing::field::Empty`. Citing from [here](https://docs.rs/tracing/0.1.41/tracing/field/struct.Empty.html), "when a field’s value is `Empty`, it will not be recorded".  "not being recorded" means that the field and its value won't be printed to stderr text logs, nor will it be printed by any other tracing layers that might be attached in the future. In `tracing_chrome.rs` we would still be able to check if "tracing_separate_root" is in the list of static `fields`, and act accordingly. So I believe this solution would effectively allow us to attach metadata to a span in a way that does not clutter logs and still allows being read in `tracing_chrome.rs`.

If we ever wanted to pass arbitrary metadata (i.e. not just a present/not present flag), it would be possible with a custom `Empty` that also holds data and implement `Value` without doing anything ([like `Empty` does](https://docs.rs/tracing-core/0.1.34/src/tracing_core/field.rs.html#775)).

```rust
// example of how the above solution would look like
info_span!("frame", tracing_separate_root = tracing::field::Empty, "{}", instance);
```
</details>
2025-07-17 10:41:48 +02:00
..
build-manifest Add windows-gnullvm hosts to the manifest 2025-06-26 01:42:44 +02:00
bump-stage0 Remove git_repository field from GitConfig 2025-04-23 10:41:20 +02:00
cargo@6833aa715d Update cargo 2025-07-15 18:32:00 -07:00
cargotest
clippy Rollup merge of #143914 - shepmaster:mismatched-lifetime-syntaxes-rewording, r=traviscross,jieyouxu 2025-07-17 10:41:47 +02:00
collect-license-metadata
compiletest Rollup merge of #142301 - Gelbpunkt:duplicated-path-in-error-musl, r=workingjubilee,fmease,jieyouxu 2025-07-15 12:52:36 +02:00
coverage-dump Update miniz_oxide dependency of coverage_dump 2025-05-10 18:35:20 +02:00
enzyme@b5098d515d submodule update 2025-06-25 02:11:29 +00:00
error_index_generator Move error_index_generator to the rustbook workspace 2025-02-17 10:58:15 -08:00
features-status-dump Remove backtrace dep from anyhow in features status dump tool 2025-05-01 07:45:47 -04:00
generate-copyright Rollup merge of #141789 - ferrocene:hoverbear/exclude-cargo-home-from-in-tree-consideration, r=clubby789 2025-06-01 19:35:44 +02:00
generate-windows-sys Update windows-bindgen to 0.61.0 2025-04-04 16:41:40 +00:00
html-checker
jsondocck Compiletest: Simplify {Html,Json}DocCk directive handling 2025-07-13 16:00:23 +02:00
jsondoclint rustdoc_json: represent generic args consistently. 2025-06-21 13:52:46 +10:00
libcxx-version
linkchecker fix(linkcheck): Build using the lockfile 2025-06-20 09:12:30 -05:00
lint-docs Rollup merge of #143631 - hkBst:update-escaper-2, r=compiler-errors 2025-07-17 10:41:45 +02:00
lld-wrapper
llvm-bitcode-linker Pass through of target features to llvm-bitcode-linker and handling them 2025-02-16 21:57:03 +01:00
miri Rollup merge of #143955 - Stypox:tracing-frame-filter, r=RalfJung 2025-07-17 10:41:48 +02:00
miropt-test-tools
nix-dev-shell Deduplicate nix code 2025-04-17 00:01:04 -04:00
opt-dist Update sysinfo version to 0.36.0 2025-07-11 15:51:42 +02:00
remote-test-client remote-test-client: Exit code 128 + <signal-number> instead of 3 2025-07-04 20:44:26 +02:00
remote-test-server
replace-version-placeholder
run-make-support Rollup merge of #143837 - jieyouxu:symbol-apis, r=ChrisDenton 2025-07-15 12:52:39 +02:00
rust-analyzer update issue number for const_trait_impl 2025-07-13 23:55:06 +08:00
rust-installer Update README.md 2025-06-29 12:29:28 +03:00
rustbook Update mdbook to 0.4.52 2025-07-14 16:28:32 -07:00
rustc-perf@6a70166b92 Bump rustc-perf and update PGO crates 2025-05-29 09:00:36 +00:00
rustdoc librustdoc: 2024 edition! 🎊 2025-03-04 12:35:18 +02:00
rustdoc-gui Update browser-ui-test version to 0.21.1 2025-07-03 18:08:23 +02:00
rustdoc-gui-test Rollup merge of #143851 - lolbinarycat:bootstrap-node_modules, r=Kobzol 2025-07-17 03:58:32 +02:00
rustdoc-js tester.js: ignore displayTypeSignature if it is null 2025-03-27 16:00:44 -05:00
rustdoc-themes
rustfmt rustfmt: migrate BareFn -> FnPtr 2025-07-06 15:03:14 -07:00
test-float-parse Remove uncessary parens in closure body with unused lint 2025-07-10 09:25:56 +08:00
tidy Rollup merge of #143957 - samueltardieu:tidy-filenames, r=Kobzol 2025-07-16 17:06:43 +02:00
tier-check tiercheck: edition 2024 2025-07-14 08:30:27 +00:00
unicode-table-generator Remove uncessary parens in closure body with unused lint 2025-07-10 09:25:56 +08:00
unstable-book-gen Rollup merge of #141526 - jyn514:env-vars, r=petrochenkov 2025-05-27 01:29:21 +08:00
wasm-component-ld Update wasm-component-ld to 0.5.14 2025-06-24 15:59:35 -07:00
x x: use let-else 2025-07-11 05:38:05 +00:00
cherry-pick.sh
publish_toolstate.py