Skip to content

Setup tracing-tree for hierarchical debug traces - #7188

Merged
jieyouxu merged 2 commits into
rust-lang:mainfrom
jieyouxu:jieyouxu/tracing-tree
Oct 16, 2026
Merged

jieyouxu merged 2 commits into
rust-lang:mainfrom
jieyouxu:jieyouxu/tracing-tree

Conversation

@jieyouxu

@jieyouxu jieyouxu commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Motivation

We already use tracing in rustfmt for various debug tracing. Right now, the traces are flat, and sometimes I find it hard to follow where debug traces are emitted, and what the call stack/tree is.

Tracking issue: #7189

Implementation

Inspired by rustc's hierarchical traces, this PR introduces tracing-tree (which is used by rustc) so we can introduce more structured debug tracing.

Note that the hierarchy is only well-established by systematically introducing #[instrument] (or equivalent) to key functions so that we can emit tracing spans, and establish relationships between such tracing spans. Without systematic #[instrument] tracing spans, this PR is essentially a no-op.

I will provide some example outputs as comments.

Follow-up work

This PR only sets up the initial infra. In follow-up PRs, I intend to:

  • Clean up some of our debug tracing logs
  • Introduce more structured #[instrument] to key functions
  • Write up some docs on how to use the debug tracing infra, including guidance on different tracing log levels and other tips (such as filtering).

Notes for the reviewer

  • I intentionally included a DO NOT MERGE commit demonstrating the #[instrument] usages. EDIT: now dropped.

Discussed previously in #t-rustfmt > tracing-tree?.


  • I did not use an LLM to create a change in this PR.
  • I used an LLM to create a change in this PR, and I have explained below how it was used.

@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Oct 16, 2026
@jieyouxu

Copy link
Copy Markdown
Member Author

Example for full lib crate, after inserting some #[instrument]s at key functions:

Screenshot 2026-10-16 at 17 02 56

Filtered:

Screenshot 2026-10-16 at 17 03 20

@jieyouxu

Copy link
Copy Markdown
Member Author

r? @ytmimi

Comment thread src/formatting.rs
Comment thread src/bin/main.rs
Comment on lines +59 to +63
let layer = HierarchicalLayer::default()
.with_writer(std::io::stderr)
.with_targets(true)
.with_bracketed_fields(true)
.with_indent_amount(2);

@jieyouxu jieyouxu Oct 16, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

(These are stylistic options that can be tuned.)

View changes since the review

@ytmimi ytmimi left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Definitely in favor of making this change. I've often struggled to keep track of things in the logs, so having a nested structure would help out a lot!

@jieyouxu I'll let you add this to the merge queue when you think it's ready since I see the DO NOT MERGE comment.

View changes since this review

@ytmimi ytmimi added pr-ready-to-merge Status: PR is largely ready for merge, waiting for secondary review / last nits and removed S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels Oct 16, 2026
@jieyouxu
jieyouxu force-pushed the jieyouxu/tracing-tree branch from 23b5b28 to a1b3036 Compare October 16, 2026 14:02
@jieyouxu

Copy link
Copy Markdown
Member Author

Dropped the DO NOT MERGE commit, no other changes.

@jieyouxu
jieyouxu enabled auto-merge October 16, 2026 14:03
@jieyouxu
jieyouxu added this pull request to the merge queue Oct 16, 2026
Merged via the queue into rust-lang:main with commit 58e7ab3 Oct 16, 2026
33 checks passed
@rustbot rustbot added the release-notes Needs an associated changelog entry label Oct 16, 2026
@jieyouxu
jieyouxu deleted the jieyouxu/tracing-tree branch October 16, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ready-to-merge Status: PR is largely ready for merge, waiting for secondary review / last nits release-notes Needs an associated changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants