zipkin可以将ts中的opentelemetry埋点发出的信息进行可视化(信息的转发依赖于物化视图的url外部存储功能)
数据流
流程
代码埋点
在一个作用域中声明span实体,在span的构造析构时会对时间信息进行打点。
在tsearch-client中进行表建立物化视图
参考:https://clickhouse.com/docs/en/operations/opentelemetry
不需要修改,除非zipkin的服务不在本地,端口不在9411.
CREATE MATERIALIZED VIEW default.zipkin_spans
(
`traceId` String,
`parentId` String,
`id` String,
`name` LowCardinality(String),
`timestamp` UInt64,
`duration` Int64,
`localEndpoint` Tuple(serviceName String),
`serviceName` String,
`tags` Map(LowCardinality(String), String)
)
ENGINE = URL('http://127.0.0.1:9411/api/v2/spans', 'JSONEachRow')
SETTINGS output_format_json_named_tuples_as_objects = 1, output_format_json_array_of_rows = 1 AS
SELECT
lower(hex(trace_id)) AS traceId,
multiIf(parent_span_id = 0, '0', lower(hex(parent_span_id))) AS parentId,
lower(hex(span_id)) AS id,
operation_name AS name,
start_time_us AS timestamp,
finish_time_us - start_time_us AS duration,
CAST(tuple('clickhouse'), 'Tuple(serviceName text)') AS localEndpoint,
'ser' AS serviceName,
attribute AS tags
FROM system.opentelemetry_span_log
zipkin
下载 并运行jar包
https://zipkin.io/
查看即可
查看http://127.0.0.1:9411/zipkin
其他问题
- 从远端转发到本地浏览器查看
https://www.wyr.me/post/723 - 如果用docker跑ck,物化视图可能发送不到宿主机的zipkin,应该打通网络。https://wiki.eryajf.net/pages/674f53/#%E6%96%B9%E6%A1%88%E4%BA%8C