Instrument Spring - 在 Docker 容器中执行的引导应用程序,带有 Jaeger 跟踪

Instrument Spring-Boot application that's executed in Docker container with Jaeger tracing

我正在 运行在 docker 容器中启动一个 Spring-Boot 应用程序,并希望使用 Uber 的 Jaeger 客户端通过 OpenTracing 对其进行检测。

我使用的是 OpenTracing Spring Web library in combination with the Jaeger 客户端。

以下代码片段在应用程序中配置跟踪器:

@Bean
public io.opentracing.Tracer jaegerTracer() {
    return new Configuration("hello_service", new Configuration.SamplerConfiguration(ProbabilisticSampler.TYPE, 1),
            new Configuration.ReporterConfiguration())
            .getTracer();
}

当我 运行 应用程序(不在 Docker 容器内)并使用以下命令启动 Jaeger 时,我可以看到痕迹:

docker run -d -e
COLLECTOR_ZIPKIN_HTTP_PORT=9411
-p 5775:5775/udp
-p 6831:6831/udp
-p 6832:6832/udp
-p 5778:5778
-p 16686:16686
-p 14268:14268
-p 9411:9411
jaegertracing/all-in-one:latest

但是当我使用以下 docker-compose 文件将 Spring-Boot 应用程序包装在 Docker 容器中并再次启动 Jaeger 客户端时,我看不到任何痕迹.

version: '2'

services:
        demo:
                build: opentracing_demo/.
                ports: 
                        - "8080:8080"

之后,我尝试在同一个 docker-compose 文件中声明 Jaeger docker 容器,并将 demo 服务中的 link 添加到 jaeger 服务:

version: '2'

services:
    demo:
            build: opentracing_demo/.
            ports: 
                    - "8080:8080"
            links:
                    - jaeger
    jaeger: 
            image: jaegertracing/all-in-one:latest
            ports:
                    - "5775:5775/udp"
                    - "6831:6831/udp"
                    - "6832:6832/udp"
                    - "5778:5778"
                    - "16686:16686"
                    - "14268:14268"
                    - "9411:9411"

但是我在Jaeger客户端中还是看不到任何痕迹

几个小时以来,我尝试了不同的方法,但到目前为止没有取得任何进展,如果有人能帮助我,我将不胜感激!

您可以在 GitHub 上找到我的演示项目。

But when I wrap the Spring-Boot application inside a Docker container with the following docker-compose file and start the Jaeger client again I can't see any traces

这是因为默认情况下,Jaeger 客户端将通过 UDP 将跨度发送到 localhost 的代理。当您的应用程序 运行 在 Docker 容器中时,您的 localhost 就是容器本身,因此跨度会丢失。

当您将 Jaeger 容器与您的应用程序链接时,您可能希望通过将环境变量 JAEGER_AGENT_HOST 导出到 jaeger.

来解决此问题