-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[.next/trace] Serialize trace info across workers to preserve .next/t…
…race with webpackBuildWorker (#57761) This PR sets up the webpack build workers (webpackBuildWorker: true) to serialize debug trace information across the worker boundary so that it can appear in the final .next/trace file at the end of the build. Currently, when webpackBuildWorker is turned on, all traces that appear under the webpack compilation are lost. After this PR, they will appear in the trace file just like when the workers are not enabled.
- Loading branch information
Showing
12 changed files
with
392 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,25 @@ | ||
import { trace, flushAllTraces, Span, SpanStatus } from './trace' | ||
import type { SpanId } from './shared' | ||
import { | ||
trace, | ||
exportTraceState, | ||
flushAllTraces, | ||
getTraceEvents, | ||
initializeTraceState, | ||
recordTraceEvents, | ||
Span, | ||
SpanStatus, | ||
} from './trace' | ||
import { setGlobal } from './shared' | ||
import type { SpanId, TraceEvent, TraceState } from './types' | ||
|
||
export { trace, flushAllTraces, Span, setGlobal, SpanStatus } | ||
export type { SpanId } | ||
export { | ||
trace, | ||
exportTraceState, | ||
flushAllTraces, | ||
getTraceEvents, | ||
initializeTraceState, | ||
recordTraceEvents, | ||
Span, | ||
setGlobal, | ||
SpanStatus, | ||
} | ||
export type { SpanId, TraceEvent, TraceState } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { mkdtemp, readFile } from 'fs/promises' | ||
import { reporter } from '.' | ||
import { setGlobal } from '../shared' | ||
import { join } from 'path' | ||
import { tmpdir } from 'os' | ||
|
||
const TRACE_EVENT = { | ||
name: 'test-span', | ||
duration: 321, | ||
timestamp: Date.now(), | ||
id: 127, | ||
startTime: Date.now(), | ||
} | ||
const WEBPACK_INVALIDATED_EVENT = { | ||
name: 'webpack-invalidated', | ||
duration: 100, | ||
timestamp: Date.now(), | ||
id: 112, | ||
startTime: Date.now(), | ||
} | ||
|
||
describe('Trace Reporter', () => { | ||
describe('JSON reporter', () => { | ||
it('should write the trace events to JSON file', async () => { | ||
const tmpDir = await mkdtemp(join(tmpdir(), 'json-reporter')) | ||
setGlobal('distDir', tmpDir) | ||
setGlobal('phase', 'anything') | ||
reporter.report(TRACE_EVENT) | ||
await reporter.flushAll() | ||
const traceFilename = join(tmpDir, 'trace') | ||
const traces = JSON.parse(await readFile(traceFilename, 'utf-8')) | ||
expect(traces.length).toEqual(1) | ||
expect(traces[0].name).toEqual('test-span') | ||
expect(traces[0].id).toEqual(127) | ||
expect(traces[0].duration).toEqual(321) | ||
expect(traces[0].traceId).toBeDefined() | ||
}) | ||
}) | ||
|
||
describe('Telemetry reporter', () => { | ||
it('should record telemetry event', async () => { | ||
const recordMock = jest.fn() | ||
const telemetryMock = { | ||
record: recordMock, | ||
} | ||
setGlobal('telemetry', telemetryMock) | ||
// This should be ignored. | ||
reporter.report(TRACE_EVENT) | ||
expect(recordMock).toBeCalledTimes(0) | ||
reporter.report(WEBPACK_INVALIDATED_EVENT) | ||
expect(recordMock).toBeCalledTimes(1) | ||
expect(recordMock).toHaveBeenCalledWith({ | ||
eventName: 'WEBPACK_INVALIDATED', | ||
payload: { | ||
durationInMicroseconds: 100, | ||
}, | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { TraceEvent } from '../types' | ||
|
||
export type Reporter = { | ||
flushAll: () => Promise<void> | void | ||
report: (event: TraceEvent) => void | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.