sleuth+zipkin链路追踪
build.gradle
plugins {
id 'org.springframework.boot' version '2.6.11'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'maven'
}
group = 'com.emapgo'
archivesBaseName = 'feign-test'
version = '1.0.0'
sourceCompatibility = '1.8'
repositories {
mavenLocal()
maven {
url "http://maven.aliyun.com/nexus/content/groups/public/"
}
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.cloud:spring-cloud-starter-sleuth:3.1.5')
compile('org.springframework.cloud:spring-cloud-sleuth-zipkin:3.1.5')
compile('org.springframework.cloud:spring-cloud-starter-openfeign:3.1.5')
compile('org.springframework.cloud:spring-cloud-loadbalancer:3.1.5')
compile('com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-config:2021.0.4.0')
compile('com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery:2021.0.4.0')
compile('com.alibaba.cloud:spring-cloud-starter-alibaba-sentinel:2021.0.4.0')
compile('com.alibaba.csp:sentinel-transport-simple-http:1.8.6')
compile('com.alibaba.csp:sentinel-datasource-nacos:1.8.6')
}
看了很多资料都依赖的spring-cloud-starter-zipkin,结果版本各种不兼容,其实向zipkin发送信息依赖spring-cloud-sleuth-zipkin即可。
spring-cloud-starter-sleuth: 依赖该包即可打开链路追踪
spring-cloud-sleuth-zipkin: 该包负责向zipkin发送信息
application.yaml
server:
port: 8081
spring:
application:
name: consumer
main:
allow-circular-references: true
cloud:
nacos:
config:
server-addr: 192.168.3.2:30848
namespace: dev
discovery:
register-enabled: true
server-addr: 192.168.3.2:30848
namespace: dev
group: test
service: consumer
sentinel:
eager: true
transport:
port: 8719
dashboard: 192.168.3.2:30880
datasource:
ds1:
nacos:
server-addr: 192.168.3.2:30848
namespace: dev
dataId: sentinel-rule
groupId: test
data-type: json
rule-type: flow
zipkin:
base-url: http://192.168.3.2:30411
sender:
type: web
sleuth:
sampler:
probability: 1.0
config:
import:
- optional:nacos:hdmap4?group=test
feign:
sentinel:
enabled: true
logging.level.org.springframework.cloud.sleuth: DEBUG
zipkin.base-url: zipkin服务地址端口
zipkin.sender.type: 发送类型,除了web还有一些其他类型。如kafka等。
sleuth.sampler.probability: 0-1的数字,默认0.1。1代表所有请求都被追踪。
logging.level.org.springframework.cloud.sleuth: DEBUG 打开后可看到每次请求的traceId和spanId。