体验zipkin二

77 阅读1分钟

1 单应用运行

现在来创建一个demo

          <dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-sleuth</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-sleuth-zipkin</artifactId>
		</dependency> 
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
@RestController
public class HomeController {
    @Autowired
    private RestTemplate restTemplate;
    
    @GetMapping("/")
    public String home() {
        ResponseEntity<String> response = restTemplate.getForEntity("http://xxx.com/abc", String.class);
        return response.getBody();
    }
}

访问 127.0.0.1:8080

image.png

来看每一张表的数据:

image.png

image.png

image.png

从页面上可以看到

image.png

有两个span可以点击查看, 分别对应下面两张详情图:

first:

image.png

second:

image.png

上报数据格式

[
    {
        "traceId": "ce475be7fd649601",
        "parentId": "ce475be7fd649601",
        "id": "6178f4b978a3ae34",
        "kind": "CLIENT",
        "name": "get",
        "timestamp": 1716370752446755,
        "duration": 27838,
        "localEndpoint": {
            "serviceName": "zipkintest",
            "ipv4": "192.168.31.116"
        },
        "tags": {
            "http.method": "GET",
            "http.path": "/abc"
        }
    },
    {
        "traceId": "ce475be7fd649601",
        "id": "ce475be7fd649601",
        "kind": "SERVER",
        "name": "get /",
        "timestamp": 1716370752415247,
        "duration": 73817,
        "localEndpoint": {
            "serviceName": "zipkintest",
            "ipv4": "192.168.31.116"
        },
        "remoteEndpoint": {
            "ipv4": "127.0.0.1",
            "port": 51356
        },
        "tags": {
            "http.method": "GET",
            "http.path": "/",
            "mvc.controller.class": "HomeController",
            "mvc.controller.method": "home"
        }
    }
]

2 双应用运行

此处是构建两个应用,用来模拟多链路调用的情况, zipkintest应用发起一个http请求至ziptest2.

image.png 与单应用数据对比可以发现, ziptest2也上报了数据, 在zipkintest调用ziptest2的时候, 会通过http的header传递spanid和traceid

X-B3-Parentspanid [1e22a40df49ba54a]
X-B3-Sampled [1]
User-Agent [Java/17.0.2]
Connection [keep-alive]
Accept [text/plain, application/json, application/*+json, */*]
X-B3-Traceid [1e22a40df49ba54a]
X-B3-Spanid [8c41cb93604d2cf5]

可以看一下界面上的显示

image.png

image.png

接下来看一下拓朴图,有个小圆点, 动态移动,指明流向方向。

image.png