Gitlab与Jaeger集成,实现Tracing链路追踪

一、Jaeger的安装部署

$ docker run -d --name jaeger \
  -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
  -p 5775:5775/udp \
  -p 6831:6831/udp \
  -p 6832:6832/udp \
  -p 5778:5778 \
  -p 16686:16686 \
  -p 14268:14268 \
  -p 14250:14250 \
  -p 9411:9411 \
  jaegertracing/all-in-one:1.24

端口介绍:

端口协议组件作用
5775UDPagent通过精简thrift协议接受zipkin.thrift,(废弃,仅旧客户端使用)
6831UDPagent通过精简的thrift协议接受jaeger.thrift
6832UDPagent通过二进制thrift协议接受jaeger.thrift
5778HTTPagent服务配置
16686HTTPquery服务器前端
14268HTTPcontroller从客户端接受jaeger.thrift
14250HTTPcontroller接受model.proto
9411HTTPcontrollerZipkin兼容端口(可选)

二、访问Jaeger UI

http://192.168.xx.xx:16686/

三、运行官方示例

$ docker run --rm -it \
  --link jaeger \
  -p8080-8083:8080-8083 \
  -e JAEGER_AGENT_HOST="jaeger" \
  jaegertracing/example-hotrod:1.24 \
  all

启动完成后,访问http://192.168.xx.xx:8080/,可以看到这是个打车的服务,有四个按钮,点击按钮会有相应的Tracing日志。

 四、查看Jaeger打车服务追踪信息

选择需要查看的服务,就可以得到追踪的信息了。

 五、在gitlab中启用Jaeger Tracing

输入Jaeger URL点击保存即可

 六、在gitlab中查看Tracing

 

这不是Jaeger的网页吗???哈哈哈,真会玩。 

七、在项目中使用Jaeger

新建一个springboot项目

 1.pom.xml文件中加入jaeger的依赖

<dependency>
   <groupId>io.opentracing.contrib</groupId>
   <artifactId>opentracing-spring-jaeger-web-starter</artifactId>
   <version>3.1.1</version>
</dependency>

2.application.yml文件中加入Jaeger的配置信息

service-name为显示在UI界面的名字

opentracing:
  jaeger:
    enabled: true
    udp-sender:
      host: 192.168.xx.xx
      port: 6831
    service-name: jaeger-demo

3.启动项目,发送请求,然后在Jaeger UI界面查看Tracing 结果

demo中一个是open接口,一个是tracing接口,open中又调用了tracing接口

八、官方推荐的入门案例教程地址:

https://github.com/yurishkuro/opentracing-tutorial

好了,这个就介绍到这里了,使用起来还是挺简单的,快去学学吧。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当您在Spring Boot应用程序中集成Jaeger时,您需要进行以下步骤: 1. 添加依赖:在您的Spring Boot项目的`pom.xml`文件中添加Jaeger客户端库的依赖项。例如: ```xml <dependency> <groupId>io.jaegertracing</groupId> <artifactId>jaeger-client</artifactId> <version>1.6.0</version> </dependency> ``` 2. 配置Jaeger:在您的应用程序的配置文件(如`application.properties`或`application.yml`)中添加Jaeger的配置。例如: ```yaml # Jaeger配置 jaeger: service-name: your-service-name udp-sender: host: localhost port: 6831 ``` 这里,您需要指定`service-name`作为您的应用程序的名称,并配置Jaeger的发送器(可以是UDP、HTTP等)的主机和端口。 3. 创建Jaeger Tracer Bean:在您的Spring Boot应用程序的配置类中创建一个Jaeger Tracer Bean。例如: ```java import io.jaegertracing.Configuration; import io.jaegertracing.internal.samplers.ConstSampler; import io.opentracing.Tracer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class JaegerConfig { @Bean public Tracer jaegerTracer() { Configuration.SamplerConfiguration samplerConfig = Configuration.SamplerConfiguration.fromEnv() .withType(ConstSampler.TYPE) .withParam(1); Configuration.ReporterConfiguration reporterConfig = Configuration.ReporterConfiguration.fromEnv() .withLogSpans(true); Configuration config = new Configuration("your-service-name") .withSampler(samplerConfig) .withReporter(reporterConfig); return config.getTracer(); } } ``` 在上面的代码中,我们创建了一个`jaegerTracer()`方法,该方法使用了Jaeger的配置和参数,并返回一个Jaeger Tracer实例。 4. 使用Jaeger Tracer:在您的应用程序中使用注入的Jaeger Tracer实例进行跟踪。例如,在您的控制器类中: ```java import io.opentracing.Span; import io.opentracing.Tracer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class MyController { @Autowired private Tracer tracer; @GetMapping("/hello") public String hello() { Span span = tracer.buildSpan("helloSpan").start(); // 执行您的业务逻辑 span.finish(); return "Hello, World!"; } } ``` 在上面的例子中,我们使用了注入的`tracer`实例创建了一个Span,用于跟踪`hello()`方法的执行。您可以根据需要在其他地方创建更多的Span。 5. 运行Jaeger Agent:在集成Jaeger之前,请确保Jaeger Agent正在运行并监听所配置的主机和端口。Jaeger Agent负责接收来自应用程序的跟踪数据并将其发送到Jaeger Collector。 这样,您就完成了Spring Boot应用程序与Jaeger集成。 请注意,这只是一个简单的示例,您可以根据您的需求进行更复杂的集成。更多关于Jaeger的配置和使用方法,请参考Jaeger的官方文档。 希望这个示例对您有所帮助!如有任何其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值