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



我正在开发一个由多个微服务组成的后端,我希望能够在Jaeger UI中查看跨度。我使用docker-compose来运行我的容器,包括jaeger,并使用opentelemetry来生成和发送跨度。我一直遵循故障排除指南直到日志记录记者。

这是我第一次与耶格尔和这种建筑合作,所以在这一点上我感到有点失落。

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

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

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

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代理容器日志

{"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'
});

相关内容

  • 没有找到相关文章

最新更新