You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法让Jaeger演示应用HotRod向Jaeger上报追踪数据

问题:HotRod无法向Jaeger上报追踪数据,连接localhost:4318失败

刚接触Jaeger/HotRod,通过Docker Compose部署后,HotRod UI可正常运行并发起操作,但Jaeger实例接收不到任何追踪数据。HotRod服务报错如下:

2024/02/18 14:08:22 traces export: Post "http://localhost:4318/v1/traces": dial tcp 127.0.0.1:4318: connect: connection refused

尝试过配置中注释的各类环境变量,但HotRod始终向localhost:4318发送追踪数据,无法改变行为。

当前Docker Compose配置:

hotrod:
    image: jaegertracing/example-hotrod:latest
    ports:
      - "8090:8080"
      - "8083:8083"
    command: [ "all" ]
    environment:
      #- JAEGER_AGENT_HOST=jaeger
      #- JAEGER_AGENT_PORT=6831
      # - OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318
      # - OTEL_EXPORTER_JAEGER_ENDPOINT=http://jaeger:14268/api/traces
    depends_on:
      - jaeger

  jaeger:
    image: jaegertracing/all-in-one:latest
    volumes:
      - "./jaeger-ui.json:/etc/jaeger/jaeger-ui.json"
    command: --query.ui-config /etc/jaeger/jaeger-ui.json --reporter.grpc.host-port=jaeger-collector.jaeger-infra.svc:14250
    environment:
      - METRICS_STORAGE_TYPE=prometheus
      - PROMETHEUS_SERVER_URL=http://prometheus:9090
      - COLLECTOR_OTLP_ENABLED=true
    ports:
      - "14250:14250"
      - "14268:14268"
      - "6831:6831/udp"
      - "16686:16686"
      - "16685:16685"
      - "4317:4317"
      - "4318:4318"

修复方案

1. 核心问题:Docker容器内的localhost指向自身

Docker Compose中每个容器是独立的网络节点,HotRod容器内的localhost指向容器自身,而非运行Jaeger的容器。必须指定Jaeger容器的服务名(jaeger)作为目标地址。

2. 启用正确的环境变量

新版HotRod默认使用OpenTelemetry(OTEL)协议上报追踪数据,取消注释OTLP相关配置即可:

environment:
  - OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318

若偏好Jaeger原生UDP协议(性能更优),可启用以下配置:

environment:
  - JAEGER_AGENT_HOST=jaeger
  - JAEGER_AGENT_PORT=6831

3. 修正Jaeger的command参数

你设置的--reporter.grpc.host-port=jaeger-collector.jaeger-infra.svc:14250是Kubernetes集群内的地址,在Docker Compose环境下无效,会导致Jaeger自身无法处理上报数据。修改为Docker Compose网络内的地址,或直接删除该参数(all-in-one默认使用本地collector):

command: --query.ui-config /etc/jaeger/jaeger-ui.json

4. 可选:添加健康检查确保服务就绪

为Jaeger添加健康检查,避免HotRod在Jaeger未完全启动时发起连接:

jaeger:
  # ... 其他配置
  healthcheck:
    test: [ "CMD", "wget", "-q", "-O", "-", "http://localhost:14268/health" ]
    interval: 5s
    timeout: 5s
    retries: 5

修改后的完整配置示例

hotrod:
    image: jaegertracing/example-hotrod:latest
    ports:
      - "8090:8080"
      - "8083:8083"
    command: [ "all" ]
    environment:
      - OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318
    depends_on:
      jaeger:
        condition: service_healthy
    networks:
      - jaeger-net

  jaeger:
    image: jaegertracing/all-in-one:latest
    volumes:
      - "./jaeger-ui.json:/etc/jaeger/jaeger-ui.json"
    command: --query.ui-config /etc/jaeger/jaeger-ui.json
    environment:
      - METRICS_STORAGE_TYPE=prometheus
      - PROMETHEUS_SERVER_URL=http://prometheus:9090
      - COLLECTOR_OTLP_ENABLED=true
    ports:
      - "14250:14250"
      - "14268:14268"
      - "6831:6831/udp"
      - "16686:16686"
      - "16685:16685"
      - "4317:4317"
      - "4318:4318"
    healthcheck:
      test: [ "CMD", "wget", "-q", "-O", "-", "http://localhost:14268/health" ]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - jaeger-net

networks:
  jaeger-net:
    driver: bridge

内容的提问来源于stack exchange,提问作者Rmz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 22:30:57