opentracing-tutorial icon indicating copy to clipboard operation
opentracing-tutorial copied to clipboard

Edit nodejs tutorial

Open MarckK opened this issue 7 years ago • 2 comments

The nodejs tutorial should more closely match the python tutorial, which is excellent.

See WIP.

MarckK avatar Dec 13 '17 14:12 MarckK

As discussed with @pavolloffay, it would be great to have a context manager in js. As a step in that direction, I am trying to wrap the function in lesson01 in a promise and then close the tracer when the promise settles -- instead of having a 12 sec timeout at the end, which is a bit much.

But both of the implementations I've come up with are problematic:

const makePromise = (func, ...args) => {
  return new Promise(function(resolve, reject) {
    resolve(func(...args));
  });
};
makePromise(sayHello, helloTo).then(closeTracer);

The above closes the tracer right away; the logs show, but the data is not being sent to the Jaeger backend as no traces show in the UI.

const manageTracer = (func, ...args) => {
  return new Promise(function(resolve, reject) {
    return func(...args, function(err, result) {
      return err ? reject(err) : resolve();
    });
  });
};
manageTracer(sayHello, helloTo)
  .then(closeTracer)
  .catch(console.log);

The above never closes the tracer. The logs show and the trace displays in the UI.

For both, const closeTracer = () => tracer.close();

MarckK avatar Jan 02 '18 20:01 MarckK

The issue is this one, I think - https://github.com/jaegertracing/jaeger-client-node/issues/157.

Simply calling tracer.Close() is not going to work, you need to call it in an async manner, with a callback, but because of the above issue even when reporter.close() is called with a callback it does not guarantee that the sender has flushed the spans.

yurishkuro avatar Jan 02 '18 21:01 yurishkuro