Reputation: 303
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?
Upvotes: 11
Views: 10634
Reputation: 366
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();
Upvotes: 0
Reputation: 303
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"
Upvotes: 19