我使用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上找到我的项目。
我做错了什么?
答案 0 :(得分:4)
我找到了问题的解决方案,以防任何人遇到类似的问题。
我错过了环境变量 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"
答案 1 :(得分:0)
对于在此页面上查看 .net core 中 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();