diff --git a/src/reporters/composite_reporter.js b/src/reporters/composite_reporter.js index 968f5f16120..4c990638cc3 100644 --- a/src/reporters/composite_reporter.js +++ b/src/reporters/composite_reporter.js @@ -25,6 +25,10 @@ export default class CompositeReporter implements Reporter { return 'CompositeReporter'; } + toString(): string { + return `${this.name()}(${this._reporters.map(reporter => reporter.toString()).join(',')})`; + } + report(span: Span): void { this._reporters.forEach(r => { r.report(span); diff --git a/src/reporters/in_memory_reporter.js b/src/reporters/in_memory_reporter.js index e833c1bc8ac..c2a80570bf1 100644 --- a/src/reporters/in_memory_reporter.js +++ b/src/reporters/in_memory_reporter.js @@ -26,6 +26,10 @@ export default class InMemoryReporter implements Reporter { return 'InMemoryReporter'; } + toString(): string { + return this.name(); + } + report(span: Span): void { this._spans.push(span); } diff --git a/src/reporters/logging_reporter.js b/src/reporters/logging_reporter.js index 3610ecdd561..85d27ee5d28 100644 --- a/src/reporters/logging_reporter.js +++ b/src/reporters/logging_reporter.js @@ -29,6 +29,10 @@ export default class LoggingReporter implements Reporter { return 'LoggingReporter'; } + toString(): string { + return this.name(); + } + close(callback?: () => void): void { if (callback) { callback(); diff --git a/src/reporters/noop_reporter.js b/src/reporters/noop_reporter.js index a6e6ef103d0..96a70bf8b6c 100644 --- a/src/reporters/noop_reporter.js +++ b/src/reporters/noop_reporter.js @@ -18,6 +18,10 @@ export default class NoopReporter implements Reporter { return 'NoopReporter'; } + toString(): string { + return this.name(); + } + report(span: Span): void {} close(callback?: () => void): void { diff --git a/src/reporters/remote_reporter.js b/src/reporters/remote_reporter.js index 578be300aa1..14d81eb47be 100644 --- a/src/reporters/remote_reporter.js +++ b/src/reporters/remote_reporter.js @@ -44,6 +44,10 @@ export default class RemoteReporter implements Reporter { return 'RemoteReporter'; } + toString(): string { + return this.name(); + } + report(span: Span): void { const thriftSpan = ThriftUtils.spanToThrift(span); this._sender.append(thriftSpan, this._appendCallback); diff --git a/test/all_reporters.js b/test/all_reporters.js index 730704063fa..3c5e57dc828 100644 --- a/test/all_reporters.js +++ b/test/all_reporters.js @@ -48,6 +48,21 @@ describe('All Reporters should', () => { assert.equal(compositeReporter.name(), 'CompositeReporter'); }); + it('have proper toString', () => { + let loggingReporter = new LoggingReporter(); + let inMemoryReporter = new InMemoryReporter(); + inMemoryReporter.setProcess('service-name', []); + let noopReporter = new NoopReporter(); + let remoteReporter = new RemoteReporter(new UDPSender()); + let compositeReporter = new CompositeReporter([loggingReporter, inMemoryReporter]); + + assert.equal(loggingReporter.toString(), 'LoggingReporter'); + assert.equal(inMemoryReporter.toString(), 'InMemoryReporter'); + assert.equal(noopReporter.toString(), 'NoopReporter'); + assert.equal(remoteReporter.toString(), 'RemoteReporter'); + assert.equal(compositeReporter.toString(), 'CompositeReporter(LoggingReporter,InMemoryReporter)'); + }); + let closeOptions = [ { callback: sinon.spy(),