Tracing with Jaeger doesn't work with docker-compose
Asked Answered
J

2

11

I instrumented a simple Spring-Boot application with Jaeger, but when I run the application within a Docker container with docker-compose, I can't see any traces in the Jaeger frontend.

I'm creating the tracer configuration by reading the properties from environment variables that I set in the docker-compose file.

This is how I create the tracer:

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

And this is my docker-compose file:

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"

You can also find my project on GitHub.

What am I doing wrong?

Jiles answered 4/5, 2018 at 11:16 Comment(0)
J
19

I found the solution to my problem, in case anybody is facing similar issues.

I was missing the environment variable JAEGER_SAMPLER_MANAGER_HOST_PORT, which is necessary if the (default) remote controlled sampler is used for tracing.

This is the working docker-compose file:

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"
Jiles answered 8/5, 2018 at 9:19 Comment(1)
Pretty amazing that this rather essential info is lacking from all documentation I could find. Thanks for posting!Interrex
S
0

For anyone finding themselves on this page looking at a simialr issue for jaeger opentracing in .net core below is a working docker compose snippet and working code in Startup.cs. The piece I was missing was getting jaeger to read the environment variables from docker-compose as by default it was trying to send the traces over udp on localhost.

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:

Add following nuget packages to your api's.

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

Then inside your Startup.cs Configure method, you will need to configure jaeger and opentracing as below.

     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();
Subconscious answered 22/2, 2021 at 14:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.