SpringBoot引入sleuth做链路追踪

一、sleuth介绍

sleuth 是一个分布式跟踪系统,用于跟踪应用程序中的请求和操作。引入该依赖后,日志中会自动添加(traceid,spanid),但是sleuth也可以在SpringBoot中单独使用

二、sleuth引用

#pom.xml引入spring-cloud

				org.springframework.cloud
				spring-cloud-dependencies
				2021.0.5
				pom
				import
			

#业务的pom.xml中引入sleuth包

			org.springframework.cloud
			spring-cloud-starter-sleuth
		

三、日志文件的修改








	
	
	
	
	
	
	
	
	
		
			
			
			${FILE_LOG_PATTERN}
		
	

	
		${logPath}/debug.log
		
			
				${logPath}/%d{yyyy-MM-dd}/debug.%d{yyyy-MM-dd}.%i.log.gz
			
			${maxHistory}
			
				${maxFileSize}
			
		
		
			
			
			${FILE_LOG_PATTERN}
		
	

	
	
	
	
	
	
	
	
	
	

	
	
		
		
	

四、application.yml的修改

spring:
  sleuth:
     enabled: true

五、启动Application应用查看traceId信息

2023-11-26 12:47:40.056 [TID:cac59d5c559740d8bc10443e9aafe964.129.17009740600380001] [c118555cfa8cf4f8,c118555cfa8cf4f8] [http-nio-8081-exec-1] INFO  o.a.c.c.C.[.[.[/demobigdata] -Initializing Spring DispatcherServlet 'dispatcherServlet'
2023-11-26 12:47:40.129 [TID:cac59d5c559740d8bc10443e9aafe964.129.17009740600380001] [c118555cfa8cf4f8,c118555cfa8cf4f8] [http-nio-8081-exec-1] INFO  o.d.w.c.a.c.AccountController -ent getAllAccount
2023-11-26 12:47:40.129 [TID:cac59d5c559740d8bc10443e9aafe964.129.17009740600380001] [c118555cfa8cf4f8,c118555cfa8cf4f8] [http-nio-8081-exec-1] INFO  o.d.s.a.impl.AccountServiceImpl -queryAllAccount
2023-11-26 12:47:40.199 [TID:cac59d5c559740d8bc10443e9aafe964.129.17009740600380001] [c118555cfa8cf4f8,c118555cfa8cf4f8] [http-nio-8081-exec-1] DEBUG com.clickhouse.jdbc.ClickHouseDriver -ClickHouse Driver 0.5.0.0(JDBC: 4.2.0.0) registered
2023-11-26 12:47:40.446 [TID:cac59d5c559740d8bc10443e9aafe964.129.17009740600380001] [c118555cfa8cf4f8,c118555cfa8cf4f8] [http-nio-8081-exec-1] INFO  c.alibaba.druid.pool.DruidDataSource -{dataSource-1} inited
2023-11-26 12:47:40.651 [TID:cac59d5c559740d8bc10443e9aafe964.129.17009740600380001] [c118555cfa8cf4f8,c118555cfa8cf4f8] [http-nio-8081-exec-1] DEBUG o.d.m.d.a.A.selectAllAccount -==>  Preparing: select id,username,password from account
2023-11-26 12:47:40.670 [TID:cac59d5c559740d8bc10443e9aafe964.129.17009740600380001] [c118555cfa8cf4f8,c118555cfa8cf4f8] [http-nio-8081-exec-1] DEBUG o.d.m.d.a.A.selectAllAccount -==> Parameters: 
2023-11-26 12:47:40.697 [TID:cac59d5c559740d8bc10443e9aafe964.129.17009740600380001] [c118555cfa8cf4f8,c118555cfa8cf4f8] [http-nio-8081-exec-1] DEBUG o.d.m.d.a.A.selectAllAccount -<==      Total: 91

这样springboot就成功引入sleuth入了。

你可能感兴趣的:(JAVA知识,大数据,spring,boot,java,后端,sleuth)