本文中以java语言开发一个简单demo来演示zipkin的使用,Brave 是用来装备 Java 程序的类库,提供了面向 Standard Servlet、Spring MVC、Http Client、JAX RS、Jersey、Resteasy 和 MySQL 等接口的装备能力,可以通过编写简单的配置和代码,让基于这些框架构建的应用可以向 Zipkin 报告数据.同时 Brave 也提供了非常简单且标准化的接口,在以上封装无法满足要求的时候可以方便扩展与定制.
新建名为service1、service2、service3、service4四个spring boot类型的项目,下面以service1项目来描述项目详细配置,其他项目的配置类似,在此不一一详述.
配置文件中指定了本服务的服务名以及服务端口,zipkin服务的地址.
当请求该服务(请求/start时),服务会请求下级的localhost:9090/foo服务-对应service2服务.
启动服务service1、service2、service3、service4,并通过浏览器请求服务service1.
[
{
“traceId”: “122ecddc1769c0da”,
“id”: “122ecddc1769c0da”,
“name”: “get”,
“timestamp”: 1494383123630139,
“duration”: 2832405,
“annotations”: [
{
“timestamp”: 1494383123630139,
“value”: “sr”,
“endpoint”: {
“serviceName”: “service1”,
“ipv4”: “192.168.1.10”
}
},
{
“timestamp”: 1494383126462544,
“value”: “ss”,
“ipv4”: “192.168.1.10”
}
}
],
“binaryAnnotations”: [
{
“key”: “http.status_code”,
“value”: “200”,
{
“key”: “http.url”,
“value”: “/start”,
“ipv4”: “192.168.1.10”
}
}
]
},
{
“traceId”: “122ecddc1769c0da”,
“id”: “d92eb6cbae9b4787”,
“parentId”: “122ecddc1769c0da”,
“timestamp”: 1494383123974246,
“duration”: 2475470,
“annotations”: [
{
“timestamp”: 1494383123974246,
“value”: “cs”,
{
“timestamp”: 1494383124351184,
“endpoint”: {
“serviceName”: “service2”,
{
“timestamp”: 1494383126443649,
{
“timestamp”: 1494383126449716,
“value”: “cr”,
“value”: “/foo”,
“value”: “http://localhost:9090/foo”,
“id”: “eba2687430a3f56c”,
“parentId”: “d92eb6cbae9b4787”,
“timestamp”: 1494383124477917,
“duration”: 558367,
“annotations”: [
{
“timestamp”: 1494383124477917,
{
“timestamp”: 1494383124881960,
“endpoint”: {
“serviceName”: “service3”,
{
“timestamp”: 1494383125033410,
{
“timestamp”: 1494383125036284,
“value”: “http://localhost:9091/bar”,
“value”: “/bar”,
“id”: “3b0df0a2f1ea18b2”,
“timestamp”: 1494383125298903,
“duration”: 1117321,
“annotations”: [
{
“timestamp”: 1494383125298903,
{
“timestamp”: 1494383125529695,
“endpoint”: {
“serviceName”: “service4”,
{
“timestamp”: 1494383126416224,
{
“timestamp”: 1494383126424903,
“value”: “http://localhost:9092/tar”,
“value”: “/tar”,
“ipv4”: “192.168.1.10”
}
}
]
}
]