next.js
286a73f8 - Add trace spans for turbopack persistence in .next/trace (#90397)

Commit
31 days ago
Add trace spans for turbopack persistence in .next/trace (#90397) ## Summary - Add a generic `TraceEvent` compilation event type that carries a name, wall-clock timing, and arbitrary attributes - Emit `TraceEvent` from Turbopack's Rust backend for cache persistence and compaction operations - Expose `eventJson` on compilation events through the NAPI bridge - Record `turbopack-persistence` and `turbopack-compaction` trace spans in `.next/trace` with memory usage snapshots, in both dev and build workflows ## Details Turbopack persistence and compaction operations were invisible in `.next/trace`. The only signal was a console log for operations exceeding 10s. A new generic `TraceEvent` type replaces the need for per-operation event structs. It carries a name, start/end wall-clock timestamps, and a `Vec` of key-value attributes. On the JS side, `backgroundLogCompilationEvents` handles all `TraceEvent`s with a single code path — creating trace spans via `manualTraceChild` and recording memory usage snapshots. Adding new traced operations requires only a few lines of Rust and zero JS changes. At @bgw's suggestion, I considered integrating as a `tracing_subscriber::Layer` to automatically forward spans to the compilation event system, but this ended up requiring quite a bit of code (a new subscriber, 'target' impl, span lifecycle management, new crate dependencies) for what is currently just 2 events, and we don't really anticipate adding more. ## Test plan - [x] Integration test in `test/e2e/filesystem-cache` verifying `turbopack-persistence` spans exist with correct attributes - [x] `pnpm test-dev-turbo test/e2e/filesystem-cache` - [x] `pnpm test-start-turbo test/e2e/filesystem-cache`
Author
Parents
Loading