Unverified Commit 1f788b54 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Development tracing improvements (#29076)

parent 85b83998
{ {
"scripts": { "scripts": {
"prepare": "rm -rf components && node ./fuzzponent.js -d 2 -s 206 -o components", "prepare": "rm -rf components && mkdir components && node ./fuzzponent.js -d 2 -s 206 -o components",
"dev": "../../node_modules/.bin/next dev", "dev": "../../node_modules/.bin/next dev",
"build": "../../node_modules/.bin/next build", "build": "../../node_modules/.bin/next build",
"start": "../../node_modules/.bin/next start", "start": "../../node_modules/.bin/next start",
......
...@@ -99,15 +99,22 @@ export class ProfilingPlugin { ...@@ -99,15 +99,22 @@ export class ProfilingPlugin {
} }
traceCompilationHooks(compiler: any) { traceCompilationHooks(compiler: any) {
this.traceHookPair( this.traceHookPair('emit', compiler.hooks.emit, compiler.hooks.afterEmit, {
'webpack-emit', parentSpan: () =>
compiler.hooks.emit, webpackInvalidSpans.get(compiler) || this.runWebpackSpan,
compiler.hooks.afterEmit, })
{
parentSpan: () => if (isWebpack5) {
webpackInvalidSpans.get(compiler) || this.runWebpackSpan, this.traceHookPair(
} 'make',
) compiler.hooks.make,
compiler.hooks.finishMake,
{
parentSpan: () =>
webpackInvalidSpans.get(compiler) || this.runWebpackSpan,
}
)
}
compiler.hooks.compilation.tap(pluginName, (compilation: any) => { compiler.hooks.compilation.tap(pluginName, (compilation: any) => {
compilation.hooks.buildModule.tap(pluginName, (module: any) => { compilation.hooks.buildModule.tap(pluginName, (module: any) => {
...@@ -152,6 +159,29 @@ export class ProfilingPlugin { ...@@ -152,6 +159,29 @@ export class ProfilingPlugin {
spans.get(module)?.stop() spans.get(module)?.stop()
}) })
if (isWebpack5) {
this.traceHookPair(
'webpack-compilation-seal',
compilation.hooks.seal,
compilation.hooks.afterSeal,
{ parentSpan: () => spans.get(compiler)! }
)
this.traceHookPair(
'add-entry',
compilation.hooks.addEntry,
compilation.hooks.afterSeal,
{
attrs: (entry: any) => {
return {
request: entry.request,
}
},
parentSpan: () => spans.get(compiler)!,
}
)
}
this.traceHookPair( this.traceHookPair(
'webpack-compilation-chunk-graph', 'webpack-compilation-chunk-graph',
compilation.hooks.beforeChunks, compilation.hooks.beforeChunks,
......
...@@ -89,7 +89,7 @@ export async function ncc_amp_optimizer(task, opts) { ...@@ -89,7 +89,7 @@ export async function ncc_amp_optimizer(task, opts) {
.target('dist/compiled/@ampproject/toolbox-optimizer') .target('dist/compiled/@ampproject/toolbox-optimizer')
} }
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
externals['arg'] = 'distcompiled/arg' externals['arg'] = 'next/dist/compiled/arg'
export async function ncc_arg(task, opts) { export async function ncc_arg(task, opts) {
await task await task
.source(opts.src || relative(__dirname, require.resolve('arg'))) .source(opts.src || relative(__dirname, require.resolve('arg')))
......
...@@ -43,7 +43,7 @@ const reportToLocalHost = ( ...@@ -43,7 +43,7 @@ const reportToLocalHost = (
// Ensure ECONNRESET error is retried 3 times before erroring out // Ensure ECONNRESET error is retried 3 times before erroring out
return retry( return retry(
() => () =>
// Send events to zipkin // Send events to jaeger's zipkin endpoint
fetch(zipkinAPI, { fetch(zipkinAPI, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
......
...@@ -23,22 +23,32 @@ export class Span { ...@@ -23,22 +23,32 @@ export class Span {
_start: bigint _start: bigint
constructor(name: string, parentId?: SpanId, attrs?: Object) { constructor({
name,
parentId,
attrs,
startTime,
}: {
name: string
parentId?: SpanId
startTime?: bigint
attrs?: Object
}) {
this.name = name this.name = name
this.parentId = parentId this.parentId = parentId
this.duration = null this.duration = null
this.attrs = attrs ? { ...attrs } : {} this.attrs = attrs ? { ...attrs } : {}
this.status = SpanStatus.Started this.status = SpanStatus.Started
this.id = getId() this.id = getId()
this._start = process.hrtime.bigint() this._start = startTime || process.hrtime.bigint()
} }
// Durations are reported as microseconds. This gives 1000x the precision // Durations are reported as microseconds. This gives 1000x the precision
// of something like Date.now(), which reports in milliseconds. // of something like Date.now(), which reports in milliseconds.
// Additionally, ~285 years can be safely represented as microseconds as // Additionally, ~285 years can be safely represented as microseconds as
// a float64 in both JSON and JavaScript. // a float64 in both JSON and JavaScript.
stop() { stop(stopTime?: bigint) {
const end: bigint = process.hrtime.bigint() const end: bigint = stopTime || process.hrtime.bigint()
const duration = (end - this._start) / NUM_OF_MICROSEC_IN_SEC const duration = (end - this._start) / NUM_OF_MICROSEC_IN_SEC
this.status = SpanStatus.Stopped this.status = SpanStatus.Stopped
if (duration > Number.MAX_SAFE_INTEGER) { if (duration > Number.MAX_SAFE_INTEGER) {
...@@ -56,7 +66,17 @@ export class Span { ...@@ -56,7 +66,17 @@ export class Span {
} }
traceChild(name: string, attrs?: Object) { traceChild(name: string, attrs?: Object) {
return new Span(name, this.id, attrs) return new Span({ name, parentId: this.id, attrs })
}
manualTraceChild(
name: string,
startTime: bigint,
stopTime: bigint,
attrs?: Object
) {
const span = new Span({ name, parentId: this.id, attrs, startTime })
span.stop(stopTime)
} }
setAttribute(key: string, value: any) { setAttribute(key: string, value: any) {
...@@ -81,7 +101,7 @@ export class Span { ...@@ -81,7 +101,7 @@ export class Span {
} }
export const trace = (name: string, parentId?: SpanId, attrs?: Object) => { export const trace = (name: string, parentId?: SpanId, attrs?: Object) => {
return new Span(name, parentId, attrs) return new Span({ name, parentId, attrs })
} }
export const flushAllTraces = () => reporter.flushAll() export const flushAllTraces = () => reporter.flushAll()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment