Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Add trace url on bootup (vercel#26594)
Browse files Browse the repository at this point in the history
* Add trace url on bootup

* Update whitelist -> accesslist

* Add name to webpack-invalidated
  • Loading branch information
timneutkens authored Jun 25, 2021
1 parent 48c1222 commit 85cac9d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
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

0 comments on commit 85cac9d

Please sign in to comment.