Uber工程团队的开源分布式追踪系统Jaeger(java实现)

jaeger介绍

一、spring boot客户端

1、在spring boot的项目pom.xml添加依赖

1<dependency> 2 <groupId>io.opentracing.contrib</groupId> 3 <artifactId>opentracing-spring-web-autoconfigure</artifactId> 4 <version>0.0.4</version> 5</dependency> 6 7<!--添加jaeger--> 8<dependency> 9 <groupId>com.uber.jaeger</groupId> 10 <artifactId>jaeger-core</artifactId> 11 <version>0.21.0</version> 12</dependency>

注入jaeger bean

1@Bean 2public io.opentracing.Tracer jaegerTracer() { 3 return new Configuration("spring-boot", new Configuration.SamplerConfiguration(ProbabilisticSampler.TYPE, 1), 4 new Configuration.ReporterConfiguration()) 5 .getTracer();

其中需要指定jaeger IP地址,默认是localhost

如果要修改地址

1Configuration.SamplerConfiguration(ProbabilisticSampler.TYPE, 1, "jaeger IP地址:端口") 2 3Configuration.ReporterConfiguration( 4 false, 5 "jaeger agent host", 6 "jaeger agent port(int)", 7 1000, 8 100)

编写测试 HelloController.java

1@RestController 2public class HelloController { 3 4 @Autowired 5 private RestTemplate restTemplate; 6 7 @RequestMapping("/hello") 8 public String hello() { 9 return "Hello from Spring Boot!"; 10 } 11 12 @RequestMapping("/chaining") 13 public String chaining() { 14 ResponseEntity<String> response = restTemplate.getForEntity("http://localhost:8080/hello", String.class); 15 return "Chaining + " + response.getBody(); 16 } 17}

运行jaeger,以docker形式运行

docker run --rm -it --network=host jaegertracing/all-in-one

访问:http://localhost:16686查看ui页面

运行spring boot程序

访问:http://localhost:8080/hello 和 http://localhost:8080/chaining

查看UI页面,可以看到

二、如果是spring cloud程序

则替换maven

1<dependency> 2 <groupId>io.opentracing.contrib</groupId> 3 <artifactId>opentracing-spring-cloud-starter</artifactId> 4 <version>0.0.4</version> 5</dependency> 6 7 8<!--添加jaeger--> 9<dependency> 10 <groupId>com.uber.jaeger</groupId> 11 <artifactId>jaeger-core</artifactId> 12 <version>0.21.0</version> 13</dependency>

同样方式运行

  • Spring Web (RestControllers, RestTemplates)
  • Async annotation, AsyncWebTask, Executors
  • WebSocket STOMP
  • Feign, HystrixFeign
  • Hystrix
  • JMS
  • JDBC
  • Zuul

参考资料:

http://planet.jboss.org/post/opentracing_spring_boot_instrumentation

https://github.com/opentracing-contrib/java-spring-cloud

https://github.com/pavolloffay/opentracing-java-examples

 https://github.com/opentracing-contrib/java-spring-web

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

swap空间的增减方法

(1)增大swap空间去激活swap交换区:swapoff v /dev/vg00/lvswap扩展交换lv:lvextend L 10G /dev/vg00/lvswap重新生成swap交换区:mkswap /dev/vg00/lvswap激活新生成的交换区:swapon v /dev/vg00/lvswap