Skip to content

feat(log): emit build-started JSON message with run_id - #16632

Merged
epage merged 2 commits into
rust-lang:masterfrom
weihanglo:session-id
Aug 6, 2026
Merged

feat(log): emit build-started JSON message with run_id #16632
epage merged 2 commits into
rust-lang:masterfrom
weihanglo:session-id

Conversation

@weihanglo

Copy link
Copy Markdown
Member

What does this PR try to resolve?

When both -Zbuild-analysis and --message-format=json are enabled,
emit a build-started JSON message to stdout containing the run_id.

This allows external tools to associate the JSON output stream
with the corresponding log file in ~/.cargo/log/{run_id}.jsonl.

While a better design of JSON message and structured logging is needed,
this provides a temporary workaround for those needing the old --timings=json flag.

Closes #16576

How to test and review this PR?

Commit by commit.

@weihanglo weihanglo added the Z-build-analysis Nightly: build-analysis label Feb 12, 2026
@rustbot rustbot added A-json-output Area: JSON message output S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 12, 2026
@rustbot

rustbot commented Feb 12, 2026

Copy link
Copy Markdown
Collaborator

r? @epage

rustbot has assigned @epage.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, epage

@weihanglo

Copy link
Copy Markdown
Member Author

cc @Kobzol @soqb

Until a better solution is out, I think this is sufficient for your use case (with some extra probe to ~/.cargo/log/ directory). Let me know if this is suffcient, or you have some other wild idea. I should create a separate issue discussing the interaction between logging and JSON message.

@Kobzol

Kobzol commented Feb 12, 2026

Copy link
Copy Markdown
Member

So, for my use-case with rustwide, it doesn't help :( Because rustwide (used e.g. by crater) runs Rust crates in a Docker container where CARGO_HOME is mounted as read-only:

Error: Experiment run failed

Caused by:
    command failed: exit status: 101
    
    error: failed to create directory `/opt/rustwide/cargo-home/log`
    
    Caused by:
      Read-only file system (os error 30)

If the writing into CARGO_HOME ever became performed default, I guess this would also currently break crater 😆

@weihanglo

Copy link
Copy Markdown
Member Author

I think we have a few options here:

  • Redirect log to stdout
  • A configurable log directory path

The second one is less ambiguous and straightforward to implement, though I am not sure if that meets your use case

@Kobzol

Kobzol commented Feb 12, 2026

Copy link
Copy Markdown
Member

It would work for the Docker/container use-case, and making the log dir be configurable sounds like a good idea regardless. (streaming to stdout would also be appreciated, but I guess that can wait until there's more design work done on -Zbuild-analysis)

@soqb

soqb commented Feb 17, 2026

Copy link
Copy Markdown

i am in roughly the same boat as @Kobzol here. a configurable log dir is necessary for my use case.

@oriongonza

Copy link
Copy Markdown

Useful for rust-lang/crater#825
Zulip

@weihanglo

Copy link
Copy Markdown
Member Author

Created #16696 for specifying log file paths.

@rustbot

This comment has been minimized.

@Kobzol

Kobzol commented Jun 21, 2026

Copy link
Copy Markdown
Member

Just noting that I wanted to do a benchmark for #8545 and measure only the duration of building the build script itself, for which --timings=json, or this PR, would be quite useful. Otherwise I don't really know how to extract the durations of individual crates out of Cargo directly at the moment.

@weihanglo

Copy link
Copy Markdown
Member Author

@Kobzol you not only need this but also #16696, right?

@Kobzol

Kobzol commented Jun 29, 2026

Copy link
Copy Markdown
Member

For the large-scale rustwide experiment, yeah. But now I don't even know how to run a one-off measurement to get the build script duration, other than eyeballing the HTML timings page or patching Cargo.

@rustbot

This comment has been minimized.

@lqd

lqd commented Aug 5, 2026

Copy link
Copy Markdown
Member

Just noting that I wanted to do a benchmark for #8545 and measure only the duration of building the build script itself, for which --timings=json, or this PR, would be quite useful. Otherwise I don't really know how to extract the durations of individual crates out of Cargo directly at the moment.

Noting that this has also been happening to the handful of people doing performance evaluations to enable the new solver and polonius alpha on nightly.

This PR would still be useful for people to analyze these experiments' results and have per-dependency stats instead of the coarse grained full crate graph results. An alternative is ofc to parse the HTML from --timings... With this PR they should be able to more easily see the slowdowns/improvements from e.g. the next solver, on each crate.

For my own experiments, strictly speaking I'm in the same boat as Jakub, doing crater-like rustwide experiments, and thus would also need #16696, so it's fine.

This test documents the current behavior
when using both `-Zbuild-analysis` and `--message-format=json`.
When both `-Zbuild-analysis` and `--message-format=json` are enabled,
emit a `build-started` JSON message to stdout containing the `run_id`.

This allows external tools to associate the JSON output stream
with the corresponding log file in `~/.cargo/log/{run_id}.jsonl`.

While a better design of JSON message and structured logging is needed,
this provides a temporary workaround for those needing the old
`--timings=json` flag

Closes rust-lang#16576
@rustbot

rustbot commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@weihanglo

weihanglo commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

@epage

Would you mind taking a look at this? I think even without #16696, this is useful standalone and help do analysis locally. At least better than parsing HTML. The message is behind -Zbuild-analysis of course. And we should have a holistic design for the potential v2 JSON message.

(See #16632 (comment))

@weihanglo

Copy link
Copy Markdown
Member Author

The re-review of this will definitely be a blocker before stabilization.

@epage

epage commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Can you call out an item for this in the tracking issue?

@epage
epage added this pull request to the merge queue Aug 6, 2026
Merged via the queue into rust-lang:master with commit 04b8ad8 Aug 6, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 6, 2026
@weihanglo

Copy link
Copy Markdown
Member Author

Can you call out an item for this in the tracking issue?

Done. Thanks!

@weihanglo
weihanglo deleted the session-id branch August 6, 2026 14:16
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Aug 8, 2026
Update cargo submodule

14 commits in c79e8f89441b3e73d6d65d125c0c745792808c74..b07e5a08651da80108eb65d7dc769ee04589f9bf
2026-08-04 19:17:33 +0000 to 2026-08-07 21:51:16 +0000
- feat(profile): Add built-in profile debug  (rust-lang/cargo#17214)
- feat(toml): allow overriding inherited default-features in 2024 (rust-lang/cargo#17126)
- feat(resolver): Report the min-publish-age in the lock message (rust-lang/cargo#17328)
- refactor(resolver): resolve() does not need an optional gctx (rust-lang/cargo#17331)
- fix(resolver): Make min-publish-age relative to --publish-time  (rust-lang/cargo#17327)
- test(trim-paths): exercise unremap files with debuggers (rust-lang/cargo#17326)
- feat(log): emit build-started JSON message with run_id  (rust-lang/cargo#16632)
- docs: remove stray `directory` metavar from `cargo update --breaking` option (rust-lang/cargo#17319)
- fix(lock): Use more accurate 'highest, rather than 'latest' (rust-lang/cargo#17317)
- docs(changelog): Pull the --verbose item (rust-lang/cargo#17315)
- revert(compiler): forward verbose flag to rustc for local crates (rust-lang/cargo#17314)
- fix(diag): Gate blanket_hint_mostly_unused with -Zprofile-hint-mostly-unused (rust-lang/cargo#17313)
- fix(diag): Remove complexity, perf, and nursery lint groups (rust-lang/cargo#17307)
- fix(git): Avoid use of git's core.fsmonitor (rust-lang/cargo#17306)

r? ghost
@rustbot rustbot added this to the 1.99.0 milestone Aug 8, 2026
pull Bot pushed a commit to LeeeeeeM/miri that referenced this pull request Aug 9, 2026
Update cargo submodule

14 commits in c79e8f89441b3e73d6d65d125c0c745792808c74..b07e5a08651da80108eb65d7dc769ee04589f9bf
2026-08-04 19:17:33 +0000 to 2026-08-07 21:51:16 +0000
- feat(profile): Add built-in profile debug  (rust-lang/cargo#17214)
- feat(toml): allow overriding inherited default-features in 2024 (rust-lang/cargo#17126)
- feat(resolver): Report the min-publish-age in the lock message (rust-lang/cargo#17328)
- refactor(resolver): resolve() does not need an optional gctx (rust-lang/cargo#17331)
- fix(resolver): Make min-publish-age relative to --publish-time  (rust-lang/cargo#17327)
- test(trim-paths): exercise unremap files with debuggers (rust-lang/cargo#17326)
- feat(log): emit build-started JSON message with run_id  (rust-lang/cargo#16632)
- docs: remove stray `directory` metavar from `cargo update --breaking` option (rust-lang/cargo#17319)
- fix(lock): Use more accurate 'highest, rather than 'latest' (rust-lang/cargo#17317)
- docs(changelog): Pull the --verbose item (rust-lang/cargo#17315)
- revert(compiler): forward verbose flag to rustc for local crates (rust-lang/cargo#17314)
- fix(diag): Gate blanket_hint_mostly_unused with -Zprofile-hint-mostly-unused (rust-lang/cargo#17313)
- fix(diag): Remove complexity, perf, and nursery lint groups (rust-lang/cargo#17307)
- fix(git): Avoid use of git's core.fsmonitor (rust-lang/cargo#17306)

r? ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-json-output Area: JSON message output Z-build-analysis Nightly: build-analysis

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Associate --message-format=json with session ID from -Zbuild-analysis

7 participants