Jaeger 代理未从 Node.JS 客户端接收跨度

Jaeger agent not receiving spans from Node.JS client

我正在处理由多个微服务组成的后端,我希望能够在 Jaeger UI 中查看跨度。我使用 docker-compose 到 运行 我的容器,包括 jaeger 和 opentelemetry 来生成和发送跨度。我一直关注 troubleshooting guide 直到并包括日志报告者。

这是我第一次使用 jaeger 和这种架构,所以我在这一点上感到有些迷茫。

以下是我的代码的一些相关部分、一些日志和屏幕截图:

Docker-compose.yaml

x-aliases :
  - &jaeger_envs
    JAEGER_SAMPLER_TYPE: const
    JAEGER_SAMPLER_PARAM: 1
    JAEGER_ENDPOINT: http://127.0.0.1:14268/api/traces

api-gateway:
    build: ./src/api-gateway/
    container_name: api-gateway
    restart: always
    environment:
      MONGO_DB_URL: user-db:27017
      QUEUE_SERVICE_URL: queue-service:5001
      STATUS_SERVICE_URL: status-service:5002
      TICKET_SERVICE_URL: ticket-service:5003
      JAEGER_REPORTER_LOG_SPANS: 'true'
      <<: *api_gateway_envs
      <<: *jaeger_envs
    ports:
      - "127.0.0.1:5000:5000"
    depends_on:
      - user-db
      - queue-service
      - status-service
      - ticket-service

jaeger:
    image: jaegertracing/all-in-one:latest
    container_name: jaeger
    restart: always
    environment:
      COLLECTOR_ZIPKIN_HOST_PORT: 9411
    ports:
      - "127.0.0.1:5775:5775/udp"
      - "127.0.0.1:6831:6831/udp"
      - "127.0.0.1:6832:6832/udp"
      - "127.0.0.1:5778:5778"
      - "127.0.0.1:16686:16686"
      - "127.0.0.1:14268:14268"
      - "127.0.0.1:14269:14269"
      - "127.0.0.1:14250:14250"
      - "127.0.0.1:9411:9411"

/src/ticket_service/tracing.ts

import { NodeSDK } from "@opentelemetry/sdk-node";
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
import { JaegerExporter } from '@opentelemetry/exporter-jaeger';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Resource } from '@opentelemetry/resources';

const jaegerExporter = new JaegerExporter({
  endpoint: 'http://127.0.0.1:14268/api/traces', //hardcoded to make sure this is not an env var issue
});

const resource = new Resource({
  [SemanticResourceAttributes.SERVICE_NAME]: 'api-gateway',
});

const sdk = new NodeSDK({
  traceExporter: jaegerExporter,
  instrumentations: [getNodeAutoInstrumentations()],
  resource: resource
});

sdk.start();
console.log("tracer initialized");

我 运行 api-网关微服务 cross-env NODE_ENV=production NODE_PATH=dist/ node -r ./dist/src/tracing.js ./dist/src

Api-网关日志:

{"body":{"email":"test@test.com","password":"***"},"duration":30.636999999999997,"level":"debug","message":"POST /api/auth/sign-in - 401 - 30.64 ms","method":"POST","originalUrl":"/api/auth/sign-in","params":{},"path":"/api/auth/sign-in","remoteIp":"::ffff:172.18.0.1","remotePort":59534,"span_id":"596fa50386bd55a1","state":"outgoing","status":401,"timestamp":"2022-03-23T10:34:22.102Z","trace_flags":"01","trace_id":"8278acbbfb7c59ffb2296d96660f005e"}

{"body":{"email":"test@test.com","password":"***"},"duration":5.9342999999999995,"level":"debug","message":"POST /api/auth/sign-in - 401 - 5.93 ms","method":"POST","originalUrl":"/api/auth/sign-in","params":{},"path":"/api/auth/sign-in","remoteIp":"::ffff:172.18.0.1","remotePort":59534,"span_id":"704d7a23ae3cb1e1","state":"outgoing","status":401,"timestamp":"2022-03-23T10:34:23.562Z","trace_flags":"01","trace_id":"7dd1c34706602bab47e5ca78a78dd7cc"}

{"body":{"email":"test@test.com","password":"***"},"duration":3.6582999999999997,"level":"debug","message":"POST /api/auth/sign-in - 401 - 3.66 ms","method":"POST","originalUrl":"/api/auth/sign-in","params":{},"path":"/api/auth/sign-in","remoteIp":"::ffff:172.18.0.1","remotePort":59534,"span_id":"eace80cc6146a8fb","state":"outgoing","status":401,"timestamp":"2022-03-23T10:34:24.750Z","trace_flags":"01","trace_id":"15d1e13cd8e17558bd6624e069336219"}

与 HTTP 端点相关的 Jaeger Agent 容器日志

{"level":"info","ts":1648028283.2791674,"caller":"flags/admin.go:115","msg":"Starting admin HTTP server","http-addr":":14269"}
{"level":"info","ts":1648028283.2952828,"caller":"server/http.go:48","msg":"Starting jaeger-collector HTTP server","http host-port":":14268"}

Jaeger 的屏幕截图UI

Jaeger UI

任何帮助或想法将不胜感激! 祝你有美好的一天!

您必须将容器视为独立的最小主机。在这种情况下,当您对 ticket_service 应用程序说要调用 localhost 时,它会调用自己,这不是我们想要的。

每当使用 docker-compose 时,都会创建一个 docker 网络并将容器配置为使用它。
您可以使用该网络让您的容器通过它们的名称相互通信。

在您的情况下,由于 Jaeger 容器称为 jaeger,您必须按如下方式配置 JaegerExporter 的端点:

const jaegerExporter = new JaegerExporter({
  endpoint: 'http://jaeger:14268/api/traces'
});