版本
spring boot: 3.4.1
dubbo:3.3.1
java17
1,dubbo3 已经提供链路追踪的集成
请参考:官方文档
但有个问题:无论是zipkin 还是 skywalking 都需要安装服务端,将dubbo服务产生的日志上传服务器
对于小项目来说没有这个必要。
所以需要去掉这个功能只保留记录traceId的功能就可以
2,引入zipkin 并去掉发送报告功能
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-tracing-brave-zipkin-spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-brave</artifactId>
</exclusion>
</exclusions>
</dependency>
通过去掉io.zipkin.reporter2包,去掉发送报告的功能
要是留着这个,就需要配置zipkin的服务器地址等信息,否则启动会报错
3,配置文件
只需要开启tracing就可以,其他的都不需要配置
dubbo:
tracing:
enabled: true
4,logback配置打印traceId
MDC的设置dubbo已经处理好,我们只要打印出来就可以
<property name="CONSOLE_LOG_PATTERN" value="%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr([%32.32X{traceId:- }]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>
<!-- 控制台 Appender -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>
5,结果
consumer
2025-01-24 15:33:58.654 INFO 17540 --- [:10003-thread-3] [679342662e54e7e88e80c7dbc44f74aa] com.zx.frame.filter.LoginAuthFilter : 进入dubbo 权限认证过滤器 com.zx.consumer.rpc.ITestConsumerSevice.test
2025-01-24 15:33:58.770 INFO 17540 --- [:10003-thread-3] [679342662e54e7e88e80c7dbc44f74aa] c.zx.consumer.rpc.TestConsumerService : test consumer 同步处理
2025-01-24 15:34:34.168 INFO 17540 --- [:10003-thread-4] [6793428a1fbf2e017f3aae0c1902d52a] com.zx.frame.filter.LoginAuthFilter : 进入dubbo 权限认证过滤器 com.zx.consumer.rpc.ITestConsumerSevice.testa
2025-01-24 15:34:34.189 INFO 17540 --- [:10003-thread-4] [6793428a1fbf2e017f3aae0c1902d52a] c.zx.consumer.rpc.TestConsumerService : test consumer 异步处理
provider
2025-01-24 15:33:58.775 INFO 2140 --- [10002-thread-14] [679342662e54e7e88e80c7dbc44f74aa] com.zx.frame.filter.LoginAuthFilter : 进入dubbo 权限认证过滤器 com.zx.api.system.rpc.AuthRpc.getPerms
2025-01-24 15:33:58.840 INFO 2140 --- [10002-thread-14] [679342662e54e7e88e80c7dbc44f74aa] c.zx.system.controller.rpc.AuthRpcImpl : getPerms provider
2025-01-24 15:34:34.197 INFO 2140 --- [10002-thread-16] [6793428a1fbf2e017f3aae0c1902d52a] com.zx.frame.filter.LoginAuthFilter : 进入dubbo 权限认证过滤器 com.zx.api.system.rpc.AuthRpc.getPerms
2025-01-24 15:34:34.197 INFO 2140 --- [10002-thread-16] [6793428a1fbf2e017f3aae0c1902d52a] c.zx.system.controller.rpc.AuthRpcImpl : getPerms provider
网友评论