Skip to content

Commit

Permalink
fix(example): add flushInterval to report spans to Jaeger exporter (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 authored Oct 2, 2019
1 parent 5f3e398 commit 42a0e26
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
6 changes: 6 additions & 0 deletions examples/grpc/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ function main() {
console.log('Greeting:', response.getMessage());
});
});

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

main();
24 changes: 11 additions & 13 deletions examples/grpc/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const EXPORTER = process.env.EXPORTER || '';

function setupTracerAndExporters(service) {
let exporter;
const options = {
serviceName: service
};
const tracer = new NodeTracer({
plugins: {
grpc: {
Expand All @@ -21,19 +17,21 @@ function setupTracerAndExporters(service) {
}
}
});

let exporter;
if (EXPORTER.toLowerCase().startsWith('z')) {
// need ignoreOutgoingUrls: [/spans/] to avoid infinity loops
// TODO: manage this situation
const zipkinExporter = new ZipkinExporter(options);
exporter = new SimpleSpanProcessor(zipkinExporter);
exporter = new ZipkinExporter({
serviceName: service,
});
} else {
// need to shutdown exporter in order to flush spans
// TODO: check once PR #301 is merged
const jaegerExporter = new JaegerExporter(options);
exporter = new SimpleSpanProcessor(jaegerExporter);
exporter = new JaegerExporter({
serviceName: service,
// The default flush interval is 5 seconds.
flushInterval: 2000
});
}

tracer.addSpanProcessor(exporter);
tracer.addSpanProcessor(new SimpleSpanProcessor(exporter));

// Initialize the OpenTelemetry APIs to use the BasicTracer bindings
opentelemetry.initGlobalTracer(tracer);
Expand Down

0 comments on commit 42a0e26

Please sign in to comment.