Skip to content

Commit 865ac99

Browse files
Ithildiryurishkuro
authored andcommitted
Add toString to reporters (open-telemetry#403)
Signed-off-by: Andrea Di Giorgi <[email protected]>
1 parent f7e3b3a commit 865ac99

6 files changed

+35
-0
lines changed

src/reporters/composite_reporter.js

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export default class CompositeReporter implements Reporter {
2525
return 'CompositeReporter';
2626
}
2727

28+
toString(): string {
29+
return `${this.name()}(${this._reporters.map(reporter => reporter.toString()).join(',')})`;
30+
}
31+
2832
report(span: Span): void {
2933
this._reporters.forEach(r => {
3034
r.report(span);

src/reporters/in_memory_reporter.js

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export default class InMemoryReporter implements Reporter {
2626
return 'InMemoryReporter';
2727
}
2828

29+
toString(): string {
30+
return this.name();
31+
}
32+
2933
report(span: Span): void {
3034
this._spans.push(span);
3135
}

src/reporters/logging_reporter.js

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export default class LoggingReporter implements Reporter {
2929
return 'LoggingReporter';
3030
}
3131

32+
toString(): string {
33+
return this.name();
34+
}
35+
3236
close(callback?: () => void): void {
3337
if (callback) {
3438
callback();

src/reporters/noop_reporter.js

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export default class NoopReporter implements Reporter {
1818
return 'NoopReporter';
1919
}
2020

21+
toString(): string {
22+
return this.name();
23+
}
24+
2125
report(span: Span): void {}
2226

2327
close(callback?: () => void): void {

src/reporters/remote_reporter.js

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export default class RemoteReporter implements Reporter {
4444
return 'RemoteReporter';
4545
}
4646

47+
toString(): string {
48+
return this.name();
49+
}
50+
4751
report(span: Span): void {
4852
const thriftSpan = ThriftUtils.spanToThrift(span);
4953
this._sender.append(thriftSpan, this._appendCallback);

test/all_reporters.js

+15
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ describe('All Reporters should', () => {
4848
assert.equal(compositeReporter.name(), 'CompositeReporter');
4949
});
5050

51+
it('have proper toString', () => {
52+
let loggingReporter = new LoggingReporter();
53+
let inMemoryReporter = new InMemoryReporter();
54+
inMemoryReporter.setProcess('service-name', []);
55+
let noopReporter = new NoopReporter();
56+
let remoteReporter = new RemoteReporter(new UDPSender());
57+
let compositeReporter = new CompositeReporter([loggingReporter, inMemoryReporter]);
58+
59+
assert.equal(loggingReporter.toString(), 'LoggingReporter');
60+
assert.equal(inMemoryReporter.toString(), 'InMemoryReporter');
61+
assert.equal(noopReporter.toString(), 'NoopReporter');
62+
assert.equal(remoteReporter.toString(), 'RemoteReporter');
63+
assert.equal(compositeReporter.toString(), 'CompositeReporter(LoggingReporter,InMemoryReporter)');
64+
});
65+
5166
let closeOptions = [
5267
{
5368
callback: sinon.spy(),

0 commit comments

Comments
 (0)