Skip to content

Commit

Permalink
Add toString to reporters (open-telemetry#403)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Di Giorgi <[email protected]>
  • Loading branch information
Ithildir authored and yurishkuro committed Sep 29, 2019
1 parent f7e3b3a commit 865ac99
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/reporters/composite_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/reporters/in_memory_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions src/reporters/logging_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export default class LoggingReporter implements Reporter {
return 'LoggingReporter';
}

toString(): string {
return this.name();
}

close(callback?: () => void): void {
if (callback) {
callback();
Expand Down
4 changes: 4 additions & 0 deletions src/reporters/noop_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/reporters/remote_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions test/all_reporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 865ac99

Please sign in to comment.