fix(jaeger): assign correct scope for flush operation (#378)

This commit is contained in:
Mayur Kale 2019-09-30 13:17:29 -07:00 committed by Brandon Gonzalez
parent f82a2d8acd
commit b0f3d3e6b4
3 changed files with 18 additions and 9 deletions

View File

@ -32,6 +32,12 @@ function makeRequest() {
});
});
})
// The process must live for at least the interval past any traces that
// must be exported, or some risk being lost if they are recorded after the
// last export.
console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.')
setTimeout(() => { console.log('Completed.'); }, 5000);
}
makeRequest();

View File

@ -8,20 +8,23 @@ const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const EXPORTER = process.env.EXPORTER || '';
function setupTracerAndExporters(service) {
let exporter;
const options = {
serviceName: service,
}
const tracer = new NodeTracer();
let exporter;
if (EXPORTER.toLowerCase().startsWith('z')) {
exporter = new ZipkinExporter(options);
exporter = new ZipkinExporter({
serviceName: service,
});
} else {
exporter = new JaegerExporter(options);
exporter = new JaegerExporter({
serviceName: service,
// The default flush interval is 5 seconds.
flushInterval: 2000
});
}
tracer.addSpanProcessor(new SimpleSpanProcessor(exporter));
// Initialize the OpenTelemetry APIs to use the BasicTracer bindings
opentelemetry.initGlobalTracer(tracer);
}

View File

@ -52,7 +52,7 @@ export class JaegerExporter implements SpanExporter {
this._sender.setProcess(this._process);
const flushInterval = config.flushInterval || 5000;
this._timer = setInterval(this._flush, flushInterval);
this._timer = setInterval(this._flush.bind(this), flushInterval);
unrefTimer(this._timer);
}