Skip to content

feat: introduce warnings/traces fields and optional stderr prefix of attribute path#409

Draft
ConnorBaker wants to merge 3 commits intoNixOS:mainfrom
ConnorBaker:vibe-coding/per-attr-path-logger
Draft

feat: introduce warnings/traces fields and optional stderr prefix of attribute path#409
ConnorBaker wants to merge 3 commits intoNixOS:mainfrom
ConnorBaker:vibe-coding/per-attr-path-logger

Conversation

@ConnorBaker
Copy link
Copy Markdown

Caution

This is a work in progress and entirely vibe-coded.

The goal of the PR is to make it easier to analyze nix-eval-jobs logs for both people (i.e., by providing attribution of warnings/traces to the attribute paths which created them) and scripts (i.e., adding warnings/traces fields to the JSON objects being streamed out).

Summary

  • Worker subprocesses now wrap nix::logger with a PrefixLogger decorator that can prepend attrPath: to all stderr log lines during evaluation, making interleaved multi-worker output attributable
  • The stderr prefix is opt-in via --log-attr-prefix to avoid breaking existing scripts that parse stderr
  • Evaluation log messages are buffered per-attribute and exposed as optional traces and warnings fields on the JSON output (omitted when empty), giving machine consumers access to builtins.trace and builtins.warn output that was previously only available on stderr
  • builtins.trace output goes to traces; builtins.warn and structured warnings from logEI go to warnings; errors remain in the existing error field
ConnorBaker and others added 3 commits March 26, 2026 15:39
Worker subprocesses now wrap `nix::logger` with a `PrefixLogger` that prepends `attrPath:` to all log messages while an attribute is being evaluated. Direct stderr writes in the catch blocks are similarly prefixed so that every warning, trace, and error on stderr is attributable to the attribute path that caused it. Uses std::format for prefix formatting, a Finally RAII guard for exception-safe attrPath cleanup, and removes unused getAttrPath(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
PrefixLogger now buffers log messages during evaluation. Messages starting with "trace:" (from builtins.trace) go to a traces buffer; all other messages (from builtins.warn, logWarning, etc.) go to a warnings buffer. After each attribute is evaluated, the buffers are drained into the Response and serialized as optional JSON fields (omitted when empty). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The stderr prefix (attrPath: ...) is now opt-in via --log-attr-prefix to avoid breaking scripts that parse stderr output. Without the flag, stderr output is unchanged from the previous behavior. The JSON traces/warnings fields are always populated regardless of the flag, since they are structured data for machine consumption. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ConnorBaker ConnorBaker force-pushed the vibe-coding/per-attr-path-logger branch from 5776dad to 20438ed Compare March 26, 2026 15:39
@ConnorBaker
Copy link
Copy Markdown
Author

@Mic92 how does this approach compare with the one you've got in #396? I see both introduce a new logger, but yours additionally introduces attachTracesToLastWarning. (The name of the logger in this PR has grown rotten, given that it's also saving warnings/traces in addition to optionally prefixing logs.)

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

Labels

None yet

1 participant