1

I am trying to link three HTTP service hops in NodeJS together into a single Zipkin trace. I have three services

service-main
service-hello
service-goodbye

The service service-main calls service-hello, and service-hello needs to call service-goodbye to complete. Zipkin can see these calls, but links them together as two separate traces. (service-main calling service-hello, and service-hello calling service-goodbye.

The services are implemented in express, and the fetching happens via node-fetch.

I create an instrumented service fetcher with code that looks like this

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

and I instrument express with code that looks like this

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

and finally, I create my tracer with code that looks like this

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;
}

You can see the above code in context in the following github repository.

I've done all this by cargo-culting the code samples from the zipkin github repositories, and I don't know enough about zipkin's implementation to diagnose this further.

How to I get zipkin to see the service-main -> service-hello -> service-goodbye call chain as a single trace?

Alana Storm
  • 164,128
  • 91
  • 395
  • 599

2 Answers2

1

It looks like it is related to https://github.com/openzipkin/zipkin-js/pull/498, could you try with zipkin-context-cls@0.19.2-alpha.7 and change ctxImpl into ctxImpl = new CLSContext('zipkin', true);?

José Carlos
  • 1,005
  • 16
  • 29
  • thank you for you time/attention -- +1. I made the suggested changes and zipkin still sees two traces instead of a single trace. Branch is here: https://github.com/astorm/zipkin-example/tree/stackoverflow/61800994 -- Bonuse Question if you have the time/know -- what job do these context objects do? Are they where the logic foo passing on the trace id exists? – Alana Storm May 14 '20 at 22:24
0

The problem ended up not being on Zipkin's end, but instead in how I was instrumenting the express server.

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

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

I had added the zipkin middleware after my call to app.get. Express executes middlwares in order and makes no distinction between middleware for a named route vs. something added via app.use.

Doing things like this

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

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

Gave me the result I was looking for.

Alana Storm
  • 164,128
  • 91
  • 395
  • 599