使用 Jaeger 进行跟踪不适用于 docker-compose



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

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

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

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

这是我的 docker 撰写文件:

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上找到我的项目。

我做错了什么?

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

我缺少环境变量JAEGER_SAMPLER_MANAGER_HOST_PORT,如果使用(默认(遥控采样器进行跟踪,这是必需的。

这是工作 docker 撰写文件:

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"

对于在此页面上发现自己在 .net core 中查看 jaeger opentracing 的 simialr 问题的人来说,下面是 Startup.cs 中的工作 docker 编写片段和工作代码。我缺少的部分是让 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" />

然后在启动.cs配置方法中,您需要配置jaeger和openttrace,如下所示。

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

相关内容

  • 没有找到相关文章

最新更新