Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/next/build/webpack/plugins/profiling-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export class ProfilingPlugin {
this.traceHookPair(
'webpack-invalidated',
compiler.hooks.invalid,
compiler.hooks.done
compiler.hooks.done,
() => ({ name: compiler.name })
)
}
}
Expand All @@ -86,7 +87,8 @@ export class ProfilingPlugin {
this.traceHookPair(
'webpack-compilation',
compiler.hooks.beforeCompile,
compiler.hooks.afterCompile
compiler.hooks.afterCompile,
() => ({ name: compiler.name })
)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/next/telemetry/trace/report/to-telemetry.ts
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
19 changes: 12 additions & 7 deletions packages/next/telemetry/trace/report/to-zipkin.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand All @@ -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