-
Notifications
You must be signed in to change notification settings - Fork 598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
logging-{winston,bunyan}: format logs to work better with Log Viewer and Error Reporting #1997
logging-{winston,bunyan}: format logs to work better with Log Viewer and Error Reporting #1997
Conversation
@cristiancavalli @kjin PTAL. |
packages/logging-bunyan/src/index.js
Outdated
// | ||
if (!record.message) { | ||
if (record.err && record.err.stack) { | ||
record.message = record.err.stack; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
// | ||
if (is.error(metadata)) { | ||
if (msg.length === 0) { | ||
msg = metadata.stack; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
]; | ||
|
||
it('should properly write log entries', function(done) { | ||
async.each(testData, function(test, callback) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
args: [ 'fifth message', new Error('fifth') ], | ||
level: 'error', | ||
verify: function(entry) { | ||
assert.ok(entry.data.startsWith('fifth message: Error: fifth')); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
22af7ca
to
76fac44
Compare
|
packages/logging-bunyan/src/index.js
Outdated
// | ||
if (!record.message) { | ||
if (record.err && record.err.stack) { | ||
record.message = record.err.stack; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
LGTM once CI's pass |
da155b7
to
f610645
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@stephenplusplus this is good to go from our side. PTAL. |
(metadata && metadata.stack) ? | ||
(msg.length === 0 ? metadata.stack : msg + ': ' + metadata.stack) : | ||
msg | ||
}; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
packages/logging-bunyan/src/index.js
Outdated
record.message = record.msg; | ||
} | ||
} | ||
|
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
packages/logging-bunyan/src/index.js
Outdated
// TODO(ofrobots): when resource.type is 'global' we need to additionally | ||
// provide serviceContext.service as part of the entry for Error Reporting to | ||
// automatically pick up the error. | ||
if (!record.message) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
// TODO(ofrobots): when resource.type is 'global' we need to additionally | ||
// provide serviceContext.service as part of the entry for Error Reporting to | ||
// automatically pick up the error. | ||
var data = { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
f610645
to
ce3b162
Compare
// to automatically pick up the error. | ||
if (record.err && record.err.stack) { | ||
record.message = record.err.stack; | ||
} else if (record.msg) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
args: ['fifth message', new Error('fifth')], | ||
level: 'error', | ||
verify: function(entry) { | ||
assert.ok( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
args: [new Error('forth')], | ||
level: 'error', | ||
verify: function(entry) { | ||
assert.ok(entry.data.message.startsWith('Error: forth')); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
// provide serviceContext.service as part of the entry for Error Reporting to | ||
// automatically pick up the error. | ||
if (metadata && metadata.stack) { | ||
msg += ' ' + metadata.stack; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
loggingWinston.log(LEVEL, MESSAGE, error, assert.ifError); | ||
}); | ||
|
||
it('should append the stack when metadata is an error, empty message', |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
3d88d32
to
f6e1535
Compare
|
…and Error Reporting Stackdriver Logs Viewer picks up the summary line from the 'message' field of the jsonPayload or from the textPayload. See: https://cloud.google.com/logging/docs/view/logs_viewer_v2#expanding Furthermore, for error messages at severity 'error' and higher, Stackdriver Error Reporting will pick up error messages if the full stack trace is included in the textPayload or in the `message` property of the jsonPaylod. See: https://cloud.google.com/error-reporting/docs/formatting-error-messages Fixes: googleapis#1989
f6e1535
to
a392b84
Compare
@stephenplusplus I am unable to reproduce that locally. Is that windows only failure? Are the appveyor results to be trusted? |
That was actually on my computer. I'll have to check that I didn't have the repo in some weird state and report back. |
Actually, I see it to be failing on CircleCI as well. |
I cannot reproduce on an ssh session on CircleCI either. Also, it seems that the first run on the test on Circle (with Node.js v4) passes. The second test (Node.js v6) fails. Running the test individually with either v4 or v6 passes. Somehow this is dependent on how the test is run from the script and/or dependent on something else non-deterministic. |
Let's see if ce8caf7 fixes things. |
@stephenplusplus Fixed the problem. Does this LGTY? |
Stackdriver Logs Viewer picks up the summary line from the 'message' field
of the jsonPayload or from the textPayload. See:
https://cloud.google.com/logging/docs/view/logs_viewer_v2#expanding
Furthermore, for error messages at severity 'error' and higher, Stackdriver
Error Reporting will pick up error messages if the full stack trace is
included in the textPayload or in the
message
property of thejsonPaylod. See:
https://cloud.google.com/error-reporting/docs/formatting-error-messages
The commit also fixes some non-determinism in the winston test caused by the sending logs through
async
.