#15897·rspack

[Bug]: logger traces add JavaScript nanoseconds to a microsecond timestamp

Author: matthewdavis-oaiCreated Sep 26, 2026Updated Sep 26, 2026

With @rspack/[email protected] and its stock 2.2.7 Linux x64 GNU binding, JavaScript records from experiments.globalTrace.register('OVERVIEW', 'logger', file) have timestamps far outside the actual capture window. This prevents aligning JS hooks with native spans. The JS duration conversion is already correct; the absolute timestamp conversion is wrong.

Reproduction

The source package contains the runnable fixture, raw results, and proposed patch. repro.mjs performs one tiny compile with a beforeCompile promise hook, closes the compiler, cleans up tracing, and removes its temporary input/output directory. Run with the attached package.json:

bash
git clone https://gist.github.com/f56c8d4455fc10c059fedc211d2fc817.git rspack-logger-timestamp
cd rspack-logger-timestamp
npm install
node repro.mjs --output run-1

Use a new output directory and unset NODE_OPTIONS, RSPACK_BINDING, NAPI_RS_NATIVE_LIBRARY_PATH, NAPI_RS_FORCE_WASI, and RSPACK_PROFILE. No dev server or watcher is involved.

Observed with Node 24.19.0 on Linux x64, using unmodified published core JS and native packages:

Observation Value
Actual hook start 2026-09-26 19:13:54.138 UTC (rounded)
JS record timestamp 2026-09-26T19:14:59.803005Z
Trace cleanup completed 2026-09-26 19:13:54.188 UTC (rounded)
JS timestamp minus observed hook start 65,665.080 ms
Logged hook duration 20.25 ms
Measured hook body duration 20.079209 ms

The run has 145 native CLOSE and 9 JS records, no compiler errors, and successful compiler/trace/temp cleanup. Raw evidence is in stock-result.json and stock-rspack.log. These are correctness observations, not performance measurements.

Cause and proposed fix

JavaScriptTracer.getTs() returns the elapsed process.hrtime.bigint() value in nanoseconds. StdoutTracer stores its epoch baseline in microseconds, then adds the unconverted JS offset.

Proposed one-line change:

diff
- let absolute_ts_micros = self.begin_ts + begin_event.ts;
+ let absolute_ts_micros = self.begin_ts + begin_event.ts / 1_000;

This preserves the current begin-event timestamp semantics, even though the record says message: "close". Keep the duration division by 1_000_000.0: its input is a nanosecond difference. Small JS/native baseline initialization skew is separate from this unit error.

The same expression remains at upstream commit 03a480bef530efe1b8908008eea1ab1289e8748e, checked September 26, 2026. Related implementation: #12687; its review discussed unit ambiguity, but the actual producer returns nanoseconds. The attached patch is source-only and has not been built or runtime-validated.