如何在Chrome火焰图中查看Jaeger轨迹



我们的应用程序中有Jaeger仪器。我们通常对Jaeger UI很满意,但由于跟踪非常大,web视图变得非常不可用。在Node.js中,我们还使用了Chrome Flame Graphs,具有良好的触觉效果。

Jaeger可以导出如下所示的JSON文件:

{"data":[{"traceID":"16c0500882122d8a16c05008820aeb3a","spans":[{"traceID":"16c0500882122d8a16c05008820aeb3a","spanID":"16c05008820aeb3a","flags":1,"operationName":"TaskProcessor","references":[],"startTime":1639398261835322,"duration":216903298,"tags":[{"key":"host","type":"string","value":""},{"key":"requestUri","type":"bool","value":false},{"key":"queryString","type":"string","value":""},{"key":"internal.span.format","type":"string","value":"proto"}],"logs":[],"processID":"p1","warnings":null},{"traceID":"16c0500882122d8a16c05008820aeb3a","spanID":"16c0500888b52131","flags":1,"operationName":"__construct","references":[{"refType":"CHILD_OF","traceID":"16c0500882122d8a16c05008820aeb3a","spanID":"16c05008820aeb3a"}],"startTime":1639398261946284,"duration":51,"tags":[{"key":"magentoType","type":"string","value":"model"},{"key":"className","type":"string","value":"Peak_Touristcard_Model_TaskProcessor"},{"key":"internal.span.format","type":"string","value":"proto"}],"logs":[],"processID":"p2","warnings":null},{"traceID":"16c0500882122d8a16c05008820aeb3a","spanID":"16c0500888b4c024","flags":1,"operationName":"_initOldFieldsMap","references":[{"refType":"CHILD_OF","traceID":"16c0500882122d8a16c05008820aeb3a","spanID":"16c0500888b52131"}],"startTime":1639398261946305,"duration":6,"tags":[{"key":"magentoType","type":"string","value":"model"},{"key":"className","type":"string","value":"Peak_Touristcard_Model_TaskProcessor"},{"key":"internal.span.format","type":"string","value":"proto"}],"logs":[],"processID":"p2","warnings":null},{"traceID":"16c0500882122d8a16c05008820aeb3a","spanID":"16c0500888b4982a","flags":1,"operationName":"_addFullNames","references":[{"refType":"CHILD_OF","traceID":"16c0500882122d8a16c05008820aeb3a","spanID":"16c0500888b52131"}],"startTime":1639398261946321,"duration":5,"tags":[{"key":"magentoType","type":"string","value":"model"},{"key":"className","type":"string","value":"Peak_Touristcard_Model_TaskProcessor"},{"key":"internal.span.format","type":"string","value":"proto"}],"logs":[],"processID":"p2","warnings":null},{"traceID":"16c0500882122d8a16c05008820aeb3a","spanID":"16c0500888b500f1","flags":1,"operationName":"_construct","references":[{"refType":"CHILD_OF","traceID":"16c0500882122d8a16c05008820aeb3a","spanID":"16c0500888b52131"}],"startTime":1639398261946332,"duration":2,"tags":[{"key":"magentoType","type":"string","value":"model"},{"key":"className","type":"string","value":"Peak_Touristcard_Model_TaskProcessor"},{"key":"internal.span.format","type":"string","value":"proto"}],"logs":[],"processID":"p2","warnings":null},
...

Chrome Flame Graphs可以打开如下JSON格式:

[{"args":{"name":"swapper"},"cat":"__metadata","name":"thread_name","ph":"M","pid":514,"tid":0,"ts":0},
{"args":{"name":"CrBrowserMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":514,"tid":259,"ts":0},
{"args":{"name":"Compositor"},"cat":"__metadata","name":"thread_name","ph":"M","pid":46733,"tid":42243,"ts":0},
{"args":{"name":"ThreadPoolServiceThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":514,"tid":25607,"ts":0},
{"args":{"name":"ThreadPoolServiceThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":46733,"tid":20739,"ts":0},
...

有没有人有在Jaeger UI之外的任何其他地方查看Jaeger痕迹的经验,甚至可能在谷歌火焰图中查看?

要转换简单用例的跟踪,请考虑这个nodejs脚本,它从标准输入中获取Jaeger JSON跟踪:

#!/usr/bin/env node
const trace = JSON.parse(require("fs").readFileSync(0).toString());
console.log(JSON.stringify(
{
traceEvents: [
{"pid":1,"tid":1,"ts":0,"ph":"M","cat":"__metadata","name":"process_name","args":{"name":"Service calls"}},
...trace.data.flat().map( d=> (
Object.keys(d.processes).map(key=>
({"pid": 1,"tid": Number(key.slice(1)),"ts": 0,"ph": "M","cat": "__metadata","name": "thread_name",
"args": {"name": d.processes[key].serviceName}}))
)).flat(),
...trace.data[0].spans.map( s=> (
{
"name": s.operationName, "ph": "X", "pid": 1, "tid": Number(s.processID.slice(1)), "ts": s.startTime, "dur": s.duration,
"args":
Object.fromEntries(
[...(s.tags||[]).map(t=>(
[t.key, t.value]
)),
[' 🚛 logs',s.logs]]
)
}
))
]
}
));

这将生成一个与谷歌跟踪事件格式匹配的JSON文件,可以在chrome://tracing(或https://ui.perfetto.dev)任何其他Catapult跟踪查看器,如Lighthouse/tracehouse,Speedscope等。

除了将痕迹可视化的问题之外,还要考虑这两种工具之间的区别。

Jaeger植根于服务器监控环境,而谷歌的Chrome跟踪器(和Perfetto(则更专注于工作站/设备的较低级别CPU/线程。为Jaeger寻找非常大的示踪剂可能不是它的主要用例。

出于这个原因,在撰写本文时,两者可能没有太大关系。Jaeger也是事务跟踪的后端,随着Open Telemetry最终从Cloud Native Computing Foundation毕业,您最好的选择是在这条路上寻找选项。例如,Grafana与Jaeger数据源进行了集成。

相关内容

  • 没有找到相关文章

最新更新