使用 Spring Boot 的 Jaeger

Kav*_*vau 5 trace jaeger

在 Spring Boot 应用程序(目前只有一个)中,我通过添加依赖项opentracing-spring-jaeger-web-starter和以下 bean 来包含 jaeger

@Bean
public static JaegerTracer getTracer() {
    io.jaegertracing.Configuration.SamplerConfiguration samplerConfig =
            io.jaegertracing.Configuration.SamplerConfiguration.fromEnv().withType("const").withParam(1);
    io.jaegertracing.Configuration.ReporterConfiguration reporterConfig =
            io.jaegertracing.Configuration.ReporterConfiguration.fromEnv().withLogSpans(true);
    io.jaegertracing.Configuration config = new io.jaegertracing.Configuration("fooService").withSampler(samplerConfig).withReporter(reporterConfig);
    return config.getTracer();
}

@PostConstruct
public void setProperty() {
    System.setProperty("JAEGER_REPORTER_LOG_SPANS", "true");
}
Run Code Online (Sandbox Code Playgroud)

在 docker 中启动 Jaeger 后,docker run -d --name jaeger -p 16686:16686 -p 6831:6831/udp jaegertracing/all-in-one:1.9我得到了痕迹。

我现在发现了另一个依赖项并阅读了不同的教程,这让我不知何故不确定在 Spring Boot 中使用 Jaeger 的正确方法是什么。

我会使用哪个依赖项?

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

<dependency>
  <groupId>io.opentracing.contrib</groupId>
  <artifactId>opentracing-spring-cloud-starter</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

https://github.com/signalfx/tracing-examples/tree/master/jaeger-java-spring-boot-web

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-spring-jaeger-web-starter</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

可能遵循Jaeger 文档

<dependency>
    <groupId>io.jaegertracing</groupId>
    <artifactId>jaeger-client</artifactId>
    <version>$jaegerVersion</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

就够了!?

在尝试 Jaeger 之前,我使用了 Zipkin,它很容易集成到 Spring 中,因为它有一个用于侦探的入门工具。日志在单独的字段中包含跟踪和跨度 ID,因此可以在例如 Kibana 中搜索它们。耶格没有

可以定制吗?如果可以,如何定制?

是否可以将 Jaeger 与 Brave 一起用于检测。该项目例如spring-cloud-starter-sleuth作为依赖项包括在内。与已经存在的 bean 存在一些冲突。Jaeger 可以和勇敢一起使用吗?

小智 2

回答有关依赖项的问题,在“依赖项”部分(https://github.com/opentracing-contrib/java-spring-jaeger)中对此进行了解释:

opentracing-spring-jaeger-web-starter 启动器是一个方便的启动器,包含 opentracing-spring-jaeger-starter 和 opentracing-spring-web-starter 这意味着通过包含它,简单的 Web Spring Boot 微服务包含了所有必要的依赖项仪器 Web 请求/响应并向 Jaeger 发送跟踪。

opentracing-spring-jaeger-cloud-starter 启动器是一个方便的启动器,包含 opentracing-spring-jaeger-starter 和 opentracing-spring-cloud-starter 这意味着通过包含它,Opentracing 支持的 Spring Cloud 堆栈的所有部分都将被仪器化

顺便说一下:

  • opentracing.jaeger.log-spans 默认为 true

与...一样:

  • opentracing.jaeger.udp-sender.host=localhost
  • opentracing.jaeger.udp-sender.port=6831
  • opentracing.jaeger.const-sampler.decision=true
  • opentracing.jaeger.enabled=true