Tracing with Jaeger doesn't work with docker-compose Tracing with Jaeger doesn't work with docker-compose docker docker

Tracing with Jaeger doesn't work with docker-compose


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"


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-agentnetworks:     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();