Unverified Commit 634de3c4 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add trace url on bootup (#26594)

* Add trace url on bootup

* Update whitelist -> accesslist

* Add name to webpack-invalidated
parent 4da94a3f
...@@ -76,7 +76,8 @@ export class ProfilingPlugin { ...@@ -76,7 +76,8 @@ export class ProfilingPlugin {
this.traceHookPair( this.traceHookPair(
'webpack-invalidated', 'webpack-invalidated',
compiler.hooks.invalid, compiler.hooks.invalid,
compiler.hooks.done compiler.hooks.done,
() => ({ name: compiler.name })
) )
} }
} }
...@@ -86,7 +87,8 @@ export class ProfilingPlugin { ...@@ -86,7 +87,8 @@ export class ProfilingPlugin {
this.traceHookPair( this.traceHookPair(
'webpack-compilation', 'webpack-compilation',
compiler.hooks.beforeCompile, compiler.hooks.beforeCompile,
compiler.hooks.afterCompile compiler.hooks.afterCompile,
() => ({ name: compiler.name })
) )
} }
......
import { traceGlobals } from '../shared' import { traceGlobals } from '../shared'
const TRACE_EVENT_WHITELIST = new Map( const TRACE_EVENT_ACCESSLIST = new Map(
Object.entries({ Object.entries({
'webpack-invalidated': 'WEBPACK_INVALIDATED', 'webpack-invalidated': 'WEBPACK_INVALIDATED',
}) })
) )
const reportToTelemetry = (spanName: string, duration: number) => { const reportToTelemetry = (spanName: string, duration: number) => {
const eventName = TRACE_EVENT_WHITELIST.get(spanName) const eventName = TRACE_EVENT_ACCESSLIST.get(spanName)
if (!eventName) { if (!eventName) {
return return
} }
......
import { randomBytes } from 'crypto' import { randomBytes } from 'crypto'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import * as Log from '../../../build/output/log'
let traceId = process.env.TRACE_ID let traceId = process.env.TRACE_ID
if (!traceId) {
traceId = process.env.TRACE_ID = randomBytes(8).toString('hex')
}
const localEndpoint = { const localEndpoint = {
serviceName: 'zipkin-query', serviceName: 'nextjs',
ipv4: '127.0.0.1', ipv4: '127.0.0.1',
port: 9411, 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 = ( const reportToLocalHost = (
name: string, name: string,
...@@ -21,6 +20,12 @@ const reportToLocalHost = ( ...@@ -21,6 +20,12 @@ const reportToLocalHost = (
parentId?: string, parentId?: string,
attrs?: Object 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 = [ const body = [
{ {
traceId, traceId,
...@@ -35,11 +40,11 @@ const reportToLocalHost = ( ...@@ -35,11 +40,11 @@ const reportToLocalHost = (
] ]
// We intentionally do not block on I/O here. // We intentionally do not block on I/O here.
fetch(zipkinUrl, { fetch(zipkinAPI, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body), body: JSON.stringify(body),
}).catch(() => {}) }).catch(console.log)
} }
export default reportToLocalHost export default reportToLocalHost
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