介绍 OpenTracing
OpenTracing通过提供平台无关、厂商无关的API,使得开发人员能够方便的添加(或更换)追踪系统的实现。 OpenTracing提供了用于运营支撑系统的和针对特定平台的辅助程序库。程序库的具体信息请参考详细的规范。
单机测试搭建 zipkin
Docker
docker run -d -p 9411:9411 openzipkin/zipkin
Java
curl -sSL https://zipkin.io/quickstart.sh | bash -s
java -jar zipkin.jar
通过访问 http://127.0.0.1:9411/zipkin/ 确定服务是否正常
ElasticSearch 作为数据存储启动方式
本地测试启动方式:
启动 ElasticSearch 到解压目录运行:
./bin/elasticsearch (window 需要运行 elasticsearch.bat)
启动 zipkin
STORAGE_TYPE=elasticsearch ES_HOSTS=http://127.0.0.1:9200 java -jar zipkin.jar
Docker 快速本地测试
项目托管地址:https://github.com/openzipkin/docker-zipkin Clone 下来后启动命令
docker-compose -f docker-compose.yml -f docker-compose-elasticsearch.yml up
Spring Boot 项目整合方法
案例使用Spring Boot 版本:2.0.3
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
需要添加依赖:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
</properties>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
注意配置文件修改:
server:
port: 8081
spring:
application:
# This ends up as the service name in zipkin
name: testsleuthzipkin
sleuth:
sampler:
probability: 1.0
zipkin:
base-url: http://127.0.0.1:9411/
配置好后启动项目,访问原来的内容。 在 zikpin 服务中就可以看到调用链信息
参考资料
opentracing 中文说明
https://github.com/opentracing-contrib/opentracing-specification-zh
zipkin opentracing 的 Java 开源实现
https://github.com/openzipkin/zipkin
Jaeger opentracing 的 Golang 开源实现
https://github.com/jaegertracing/jaeger
Brave Java distributed tracing implementation compatible with Zipkin backend services.
https://github.com/openzipkin/brave d openzipkin https://github.com/openzipkin