Skip to content

Commit

Permalink
feat(#362): adds flush method to http reporter. (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcchavezs authored and adriancole committed Jul 23, 2019
1 parent 859e3cb commit 6b29aa1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/zipkin/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ declare namespace zipkin {
class BatchRecorder implements Recorder {
constructor(args: { logger: Logger, timeout?: number });
record: (rec: Record) => void;
flush: () => void;
}

class ConsoleRecorder implements Recorder {
Expand Down
11 changes: 11 additions & 0 deletions packages/zipkin/src/batch-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ class BatchRecorder {
}
}

/**
* Calling this will flush any pending spans to the transport.
*
* Note: the transport itself may be batching, in such case you may need to flush that also.
*/
flush() {
this.partialSpans.forEach((span, id) => {
this._writeSpan(id, span);
});
}

record(rec) {
const id = rec.traceId;

Expand Down
21 changes: 21 additions & 0 deletions packages/zipkin/test/batch-recorder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,29 @@ describe('Batch Recorder - integration test', () => {
'http.status_code': '200'
}
});
});

it('should only flush spans when calling flush method', () => {
recorder = new BatchRecorder({
logger: {
logSpan: (span) => {
spans.push(JSON.parse(JSON_V2.encode(span)));
}
}
});

recorder.record(record(rootId, 1, new Annotation.ServerRecv()));

expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions

recorder.flush();

expect(popSpan()).to.deep.equal({
traceId: rootId.traceId,
id: rootId.spanId,
kind: 'SERVER',
timestamp: 1
});
});

it('should handle overlapping server and client', () => {
Expand Down

0 comments on commit 6b29aa1

Please sign in to comment.