使用Zipkin和NodeJS链接服务跃点

问题描述 投票:0回答:2

我正在尝试将NodeJS中的三个HTTP服务跃点链接到一个Zipkin跟踪中。我有三项服务

service-main
service-hello
service-goodbye

[服务service-main调用service-hello,并且service-hello需要调用service-goodbye以完成。 Zipkin可以看到这些调用,但是将它们链接为两条单独的轨迹。 ([service-main调用service-helloservice-hello调用service-goodbye

这些服务在express中实现,并且通过node-fetch进行获取。

我使用如下代码创建检测的服务提取程序

const createFetcher = (remoteServiceName, tracer) => {
  const wrapFetch = require('zipkin-instrumentation-fetch');
  return wrapFetch(fetch,
    {
      tracer:tracer,
      remoteServiceName:remoteServiceName
    }
  );
}

并且我用看起来像这样的代码来表达

app.use(zipkinMiddleware({tracer}));       

最后,我使用如下代码创建跟踪器

const createTracer = (localServiceName) => {
  const tracer = new Tracer({
    ctxImpl: new CLSContext('zipkin'),
    recorder: new BatchRecorder({
      logger: new HttpLogger({
        endpoint: 'http://localhost:9411/api/v2/spans',
        jsonEncoder: JSON_V2
      })
    }),
    localServiceName: localServiceName // name of this application
  });
  return tracer;
}

您可以在the following github repository的上下文中看到以上代码。

我已经通过大量培养zipkin github存储库中的代码样本来完成所有这些工作,而且我对zipkin的实现还不了解,无法进一步诊断。

如何获得zipkin来将service-main-> service-hello-> service-goodbye调用链视为单个跟踪?

node.js trace distributed-system zipkin
2个回答
1
投票

[它似乎与https://github.com/openzipkin/zipkin-js/pull/498相关,您可以尝试使用[email protected]并将ctxImpl更改为ctxImpl = new CLSContext('zipkin', true);吗?


0
投票

问题最终不是在Zipkin的尽头,而是在我如何配置Express服务器方面。

app.get('/main', async function (req, res) {
    //...
})

app.use(zipkinMiddleware({tracer}));

我已经添加了zipkin中间件之后我对app.get的调用。 Express按顺序执行中间件软件,并且在命名路由的中间件与通过app.use添加的东西之间没有区别。

做这样的事情

app.use(zipkinMiddleware({tracer}));

app.get('/main', async function (req, res) {
    //...
})

给了我我想要的结果。

© www.soinside.com 2019 - 2024. All rights reserved.