Skip to content

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

Open
weihanglo wants to merge 2 commits intorust-lang:masterfrom
weihanglo:session-id
Open

feat(log): emit build-started JSON message with run_id #16632
weihanglo wants to merge 2 commits intorust-lang:masterfrom
weihanglo:session-id

Conversation

@weihanglo
Copy link
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
Copy link
Collaborator

rustbot commented Feb 12, 2026

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
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
Copy link
Member

Kobzol commented Feb 12, 2026

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
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
Copy link
Member

Kobzol commented Feb 12, 2026

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
Copy link

soqb commented Feb 17, 2026

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

@oriongonza
Copy link

Useful for rust-lang/crater#825
Zulip

@weihanglo
Copy link
Member Author

Created #16696 for specifying log file paths.

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
Copy link
Collaborator

rustbot commented Mar 14, 2026

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.

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 S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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

6 participants