From ebf09652e0f1fd65a65dd443a10021bbb058e6be Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Fri, 25 Jun 2021 12:29:42 +0200 Subject: [PATCH 1/3] Add trace url on bootup --- .../build/webpack/plugins/profiling-plugin.ts | 3 ++- .../next/telemetry/trace/report/to-zipkin.ts | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/next/build/webpack/plugins/profiling-plugin.ts b/packages/next/build/webpack/plugins/profiling-plugin.ts index 8bab027fcec6ac..1cd2c6b3ca8ddf 100644 --- a/packages/next/build/webpack/plugins/profiling-plugin.ts +++ b/packages/next/build/webpack/plugins/profiling-plugin.ts @@ -86,7 +86,8 @@ export class ProfilingPlugin { this.traceHookPair( 'webpack-compilation', compiler.hooks.beforeCompile, - compiler.hooks.afterCompile + compiler.hooks.afterCompile, + () => ({ name: compiler.name }) ) } diff --git a/packages/next/telemetry/trace/report/to-zipkin.ts b/packages/next/telemetry/trace/report/to-zipkin.ts index c65ab8279272e0..78390b44d8c049 100644 --- a/packages/next/telemetry/trace/report/to-zipkin.ts +++ b/packages/next/telemetry/trace/report/to-zipkin.ts @@ -1,17 +1,16 @@ import { randomBytes } from 'crypto' import fetch from 'node-fetch' +import * as Log from '../../../build/output/log' let traceId = process.env.TRACE_ID -if (!traceId) { - traceId = process.env.TRACE_ID = randomBytes(8).toString('hex') -} const localEndpoint = { - serviceName: 'zipkin-query', + serviceName: 'nextjs', ipv4: '127.0.0.1', port: 9411, } -const zipkinUrl = `http://${localEndpoint.ipv4}:${localEndpoint.port}/api/v2/spans` +const zipkinUrl = `http://${localEndpoint.ipv4}:${localEndpoint.port}` +const zipkinAPI = `${zipkinUrl}/api/v2/spans` const reportToLocalHost = ( name: string, @@ -21,6 +20,12 @@ const reportToLocalHost = ( parentId?: string, attrs?: Object ) => { + if (!traceId) { + traceId = process.env.TRACE_ID = randomBytes(8).toString('hex') + Log.info( + `Zipkin trace will be available on ${zipkinUrl}/zipkin/traces/${traceId}` + ) + } const body = [ { traceId, @@ -35,11 +40,11 @@ const reportToLocalHost = ( ] // We intentionally do not block on I/O here. - fetch(zipkinUrl, { + fetch(zipkinAPI, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body), - }).catch(() => {}) + }).catch(console.log) } export default reportToLocalHost From 01115722eb63ffaf676daadfd5f75b02996a8488 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Fri, 25 Jun 2021 12:49:02 +0200 Subject: [PATCH 2/3] Update whitelist -> accesslist --- packages/next/telemetry/trace/report/to-telemetry.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/next/telemetry/trace/report/to-telemetry.ts b/packages/next/telemetry/trace/report/to-telemetry.ts index 51d46ca59637ea..8486c1354057fd 100644 --- a/packages/next/telemetry/trace/report/to-telemetry.ts +++ b/packages/next/telemetry/trace/report/to-telemetry.ts @@ -1,13 +1,13 @@ import { traceGlobals } from '../shared' -const TRACE_EVENT_WHITELIST = new Map( +const TRACE_EVENT_ACCESSLIST = new Map( Object.entries({ 'webpack-invalidated': 'WEBPACK_INVALIDATED', }) ) const reportToTelemetry = (spanName: string, duration: number) => { - const eventName = TRACE_EVENT_WHITELIST.get(spanName) + const eventName = TRACE_EVENT_ACCESSLIST.get(spanName) if (!eventName) { return } From d29aa3ffc029ac292805b900ba660cd994c060b4 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Fri, 25 Jun 2021 12:50:31 +0200 Subject: [PATCH 3/3] Add name to webpack-invalidated --- packages/next/build/webpack/plugins/profiling-plugin.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/next/build/webpack/plugins/profiling-plugin.ts b/packages/next/build/webpack/plugins/profiling-plugin.ts index 1cd2c6b3ca8ddf..a091ec83a35153 100644 --- a/packages/next/build/webpack/plugins/profiling-plugin.ts +++ b/packages/next/build/webpack/plugins/profiling-plugin.ts @@ -76,7 +76,8 @@ export class ProfilingPlugin { this.traceHookPair( 'webpack-invalidated', compiler.hooks.invalid, - compiler.hooks.done + compiler.hooks.done, + () => ({ name: compiler.name }) ) } }