Skip to content

Commit

Permalink
chore(#362): refactors flush setup based on @adriancole's feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcchavezs committed Jul 21, 2019
1 parent c8fdc59 commit fa751dc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
8 changes: 2 additions & 6 deletions packages/zipkin/src/batch-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,12 @@ class BatchRecorder {
* @property {number} batchInterval interval for reporting in miliseconds.
* The value -1 means that there won't be batch reporting on interval basis.
*/
constructor({logger, timeout = defaultTimeout, batchInterval = defaultBatchInterval}) {
constructor({logger, timeout = defaultTimeout}) {
this.logger = logger;
this.timeout = timeout;
this.partialSpans = new Map();
this[defaultTagsSymbol] = {};

if (batchInterval === -1) {
return;
}

// read through the partials spans regularly
// and collect any timed-out ones
const timer = setInterval(() => {
Expand All @@ -94,7 +90,7 @@ class BatchRecorder {
this._writeSpan(id, span);
}
});
}, batchInterval);
}, 1000);
if (timer.unref) { // unref might not be available in browsers
timer.unref(); // Allows Node to terminate instead of blocking on timer
}
Expand Down
5 changes: 1 addition & 4 deletions packages/zipkin/test/batch-recorder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,14 @@ describe('Batch Recorder', () => {
trace.recordAnnotation(new Annotation.ServerRecv());
});

clock.tick('01:00'); // 1 minute is the default timeout
clock.tick(100); // 1000 is de batching interval

expect(logSpan.calledOnce).to.equal(false);

recorder.flush();

expect(logSpan.calledOnce).to.equal(true);

const loggedSpan = logSpan.getCall(0).args[0];
expect(loggedSpan.annotations[0].value).to.equal('zipkin-js.flush');

clock.uninstall();
});

Expand Down

0 comments on commit fa751dc

Please sign in to comment.