8

我使用 Jaeger 检测了一个简单的 Spring-Boot 应用程序,但是当我使用 docker-compose 在 Docker 容器中运行该应用程序时,我在 Jaeger 前端看不到任何痕迹。

我通过从我在 docker-compose 文件中设置的环境变量中读取属性来创建跟踪器配置。

这就是我创建跟踪器的方式:

Configuration config = Configuration.fromEnv();
return config.getTracer();

这是我的 docker-compose 文件:

version: '2'

services:
    demo:
            build: opentracing_demo/.
            ports: 
                    - "8080:8080"
            environment: 
                    - JAEGER_SERVICE_NAME=hello_service
                    - JAEGER_AGENT_HOST=jaeger
                    - JAEGER_AGENT_PORT=6831
    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"

你也可以在GitHub 上找到我的项目。

我究竟做错了什么?

4

2 回答 2

16

我找到了解决问题的方法,以防有人遇到类似问题。

我错过了环境变量JAEGER_SAMPLER_MANAGER_HOST_PORT,如果(默认)远程控制采样器用于跟踪,这是必需的。

这是工作的 docker-compose 文件:

version: '2'

services:           
    demo:
            build: opentracing_demo/.
            ports: 
                    - "8080:8080"
            environment: 
                    - JAEGER_SERVICE_NAME=hello_service
                    - JAEGER_AGENT_HOST=jaeger
                    - JAEGER_AGENT_PORT=6831     
                    - JAEGER_SAMPLER_MANAGER_HOST_PORT=jaeger:5778
    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"
于 2018-05-08T09:19:17.910 回答
0

对于在此页面上查看 .net 核心中 jaeger opentracing 的类似问题的任何人来说,这是一个工作 docker compose 片段和 Startup.cs 中的工作代码。我缺少的部分是让 jaeger 从 docker-compose 读取环境变量,因为默认情况下它试图通过本地主机上的 udp 发送跟踪。

version: '3.4'

services:
  jaeger-agent:
    container_name: 'tracing.jaeger.agent'
    image: jaegertracing/all-in-one:latest
    networks:
        - jaeger-demo
    ports:
        - "5775:5775/udp"
        - "6831:6831/udp"
        - "6832:6832/udp"
        - "5778:5778/tcp"
        - "16686:16686"
        - "14268:14268"
        - "9411:9411"
    environment:
        - LOG_LEVEL=debug
    labels:
        NAME: "jaeger-agent"

  orderService:
    container_name: 'tracing.orders.api'
    image: ${DOCKER_REGISTRY-}orderservice.api
    build:
      context: .
      dockerfile: OrdersApi/Dockerfile
    networks:
        - jaeger-demo
    ports:
        - "16252:80"
    environment:
        - ASPNETCORE_ENVIRONMENT=Development
        - JAEGER_SERVICE_NAME=OrdersApi
        - JAEGER_AGENT_HOST=jaeger-agent
        - JAEGER_AGENT_PORT=6831
        - JAEGER_SAMPLER_TYPE=const
        - JAEGER_SAMPLER_PARAM=1
    depends_on: 
      - jaeger-agent

  customerService:
    container_name: 'tracing.customers.api'
    image: ${DOCKER_REGISTRY-}customerservice.api
    build:
      context: .
      dockerfile: CustomerApi/Dockerfile
    networks:
        - jaeger-demo
    ports:
        - "17000:80"
    environment:
        - ASPNETCORE_ENVIRONMENT=Development
        - JAEGER_SERVICE_NAME=CustomersApi
        - JAEGER_AGENT_HOST=jaeger-agent
        - JAEGER_AGENT_PORT=6831
        - JAEGER_SAMPLER_TYPE=const
        - JAEGER_SAMPLER_PARAM=1
    depends_on: 
      - jaeger-agent

networks: 
    jaeger-demo:

将以下 nuget 包添加到您的 api 中。

<PackageReference Include="OpenTracing.Contrib.NetCore" Version="0.6.2" />
<PackageReference Include="Jaeger" Version="0.4.2" />

然后在您的 Startup.cs 配置方法中,您需要配置 jaeger 和 opentracing,如下所示。

     services.AddSingleton<ITracer>(serviceProvider =>
     {
        ILoggerFactory loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>();
     
        Jaeger.Configuration.SenderConfiguration.DefaultSenderResolver = new SenderResolver(loggerFactory).RegisterSenderFactory<ThriftSenderFactory>();
     
        var config = Jaeger.Configuration.FromEnv(loggerFactory);
     
        ITracer tracer = config.GetTracer();
     
        GlobalTracer.Register(tracer);
     
        return tracer;
     });
     
     services.AddOpenTracing();
于 2021-02-22T14:41:31.360 回答