Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Log only span context #153

Merged
merged 2 commits into from Sep 27, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/reporters/logging_reporter.js
Expand Up @@ -30,7 +30,7 @@ export default class LoggingReporter {
}

report(span: Span): void {
this._logger.info(`Reporting span ${JSON.stringify(span)}`);
this._logger.info(`Reporting span ${span.context().toString()}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interpolated values are automatically converted to strings:

`${{toString: () => 'abc'}}`
// -> "abc"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow. IIRC Javascript does not have Java's convention of automatically calling toString() method when converting to strings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JS does call toString() when converting to string.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString

Every object has a toString() method that is automatically called when the object is to be represented as a text value or when an object is referred to in a manner in which a string is expected.

}

name(): string {
Expand Down
14 changes: 11 additions & 3 deletions test/all_reporters.js
Expand Up @@ -78,14 +78,22 @@ describe('All Reporters should', () => {
});

describe('Logging reporter', () => {
it('report span logs span as a stringified object', () => {
it('logs span as context().toString()', () => {
let logger = new MockLogger();
let reporter = new LoggingReporter(logger);
let spanMock = { key: 'some-span' };
let spanMock = {
context: function context() {
return {
toString: function toString() {
return "span-as-string";
}
};
}
};

reporter.report(spanMock);

assert.equal(logger._infoMsgs[0], 'Reporting span {"key":"some-span"}');
assert.equal(logger._infoMsgs[0], 'Reporting span span-as-string');
});
});

Expand Down