ad6b9c2d4d
Noticed the trace can't be imported because the tags are a nested as apparently the type was not restrictive of that. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `yarn lint`
68 lines
1.6 KiB
JavaScript
68 lines
1.6 KiB
JavaScript
import fs from 'fs'
|
|
import eventStream from 'event-stream'
|
|
import retry from 'async-retry'
|
|
import fetch from 'node-fetch'
|
|
|
|
const file = fs.createReadStream(process.argv[2])
|
|
|
|
const localEndpoint = {
|
|
serviceName: 'nextjs',
|
|
ipv4: '127.0.0.1',
|
|
port: 9411,
|
|
}
|
|
|
|
// Jaeger supports Zipkin's reporting API
|
|
const zipkinUrl = `http://${localEndpoint.ipv4}:${localEndpoint.port}`
|
|
const jaegerWebUiUrl = `http://${localEndpoint.ipv4}:16686`
|
|
const zipkinAPI = `${zipkinUrl}/api/v2/spans`
|
|
|
|
let loggedUrl = false
|
|
|
|
function logWebUrl(traceId) {
|
|
console.log(
|
|
`Jaeger trace will be available on ${jaegerWebUiUrl}/trace/${traceId}`
|
|
)
|
|
}
|
|
file.pipe(eventStream.split()).pipe(
|
|
eventStream.map((data, cb) => {
|
|
if (data === '') {
|
|
return cb(null, '')
|
|
}
|
|
|
|
const eventsJson = JSON.parse(data).map((item) => {
|
|
item.localEndpoint = localEndpoint
|
|
return item
|
|
})
|
|
if (!loggedUrl) {
|
|
logWebUrl(eventsJson[0].traceId)
|
|
loggedUrl = true
|
|
}
|
|
retry(
|
|
() =>
|
|
// Send events to zipkin
|
|
fetch(zipkinAPI, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(eventsJson),
|
|
}),
|
|
{ minTimeout: 500, retries: 3, factor: 1 }
|
|
)
|
|
.then(async (res) => {
|
|
if (res.status !== 202) {
|
|
console.dir(
|
|
{
|
|
status: res.status,
|
|
body: await res.text(),
|
|
events: eventsJson,
|
|
},
|
|
{ depth: null }
|
|
)
|
|
}
|
|
cb(null, '')
|
|
})
|
|
.catch((err) => {
|
|
console.log(err)
|
|
cb(null, '')
|
|
})
|
|
})
|
|
)
|