Jaeger Distributed Tracing

使用 Jaeger 官方的 docker 镜像—— jaegertracing/all-in-one:latest
查看日志发现错误:
ERROR: failed to flush Jaeger spans to server: write udp 127.0.0.1:35793->127.0.0.1:6831: write: connection refused

简单的docker-compose.yml

services:
  jaeger:
    image: jaegertracing/all-in-one:1.14
    environment:
      - COLLECTOR_ZIPKIN_HTTP_PORT=9411
    container_name: jaeger
    ports:
      - "5775:5775/udp"
      - "6831:6831/udp"
      - "6832:6832/udp"
      - "5778:5778"
      - "16686:16686"
      - "14268:14268"
      - "9411:9411"

在相对应的服务也加入了环境变量:
JAEGER_AGENT_HOST=jaeger
JAEGER_AGENT_PORT=6831

细看错误的话,为啥是 127.0.0.1 而不是 docker 网络
代码问题:

cfg := &config.Configuration{
        Sampler: &config.SamplerConfig{
            Type:  jaeger.SamplerTypeConst,
            Param: 1,
        },
        Reporter: &config.ReporterConfig{
            LogSpans:           true,
        },
        ServiceName: service,
    }
    tracer, closer, err := cfg.NewTracer(config.Logger(jaeger.StdLogger))

初始化函数一顿复制粘贴根本没细看,只需要改为

agentHost := os.Getenv("JAEGER_AGENT_HOST")
agentPort := os.Getenv("JAEGER_AGENT_PORT")
Reporter: &config.ReporterConfig{
            LogSpans:           true,
            LocalAgentHostPort: agentHost + ":" + agentPort,
        }

你可能感兴趣的:(Jaeger Distributed Tracing)