Skip to content
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

Merged
merged 10 commits into from
Mar 20, 2017

Conversation

ofrobots
Copy link
Contributor

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

The commit also fixes some non-determinism in the winston test caused by the sending logs through async.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Feb 14, 2017
@ofrobots
Copy link
Contributor Author

@cristiancavalli @kjin PTAL.

kjin
kjin previously requested changes Feb 16, 2017
//
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.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

//
if (is.error(metadata)) {
if (msg.length === 0) {
msg = metadata.stack;

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

];

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.

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.

@ofrobots
Copy link
Contributor Author

ofrobots commented Feb 22, 2017

This is currently blocked on #2014.

@ofrobots ofrobots changed the title logging-{winston,bunyan}: format logs to work better with Log Viewer and Error Reporting. logging-{winston,bunyan}: format logs to work better with Log Viewer Mar 14, 2017
@ofrobots ofrobots dismissed kjin’s stale review March 14, 2017 16:46

Reduced scope to formatting only. PTAL.

//
if (!record.message) {
if (record.err && record.err.stack) {
record.message = record.err.stack;

This comment was marked as spam.

@cristiancavalli
Copy link
Contributor

LGTM once CI's pass

@ofrobots ofrobots changed the title logging-{winston,bunyan}: format logs to work better with Log Viewer logging-{winston,bunyan}: format logs to work better with Log Viewer and Error Reporting Mar 14, 2017
Copy link
Contributor

@kjin kjin left a comment

Choose a reason for hiding this comment

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

LGTM.

@ofrobots
Copy link
Contributor Author

@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.

record.message = record.msg;
}
}

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

// 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.

// 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.

// 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.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

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.

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.

// 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.

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.

@googlebot
Copy link

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.

@googlebot googlebot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Mar 17, 2017
@stephenplusplus
Copy link
Contributor

npm test:

  1) logging-bunyan write should rename the msg property to message:
     TypeError: this.log_[level] is not a function
      at LoggingBunyan.write (C:\Users\sawch\dev\google-cloud-node\packages\logging-bunyan\src\index.js:170:19)
      at Context.<anonymous> (C:\Users\sawch\dev\google-cloud-node\packages\logging-bunyan\test\index.js:166:21)
      at callFnAsync (C:\Users\sawch\dev\google-cloud-node\node_modules\mocha\lib\runnable.js:349:8)
      at Test.Runnable.run (C:\Users\sawch\dev\google-cloud-node\node_modules\mocha\lib\runnable.js:301:7)
      at Runner.runTest (C:\Users\sawch\dev\google-cloud-node\node_modules\mocha\lib\runner.js:422:10)
      at C:\Users\sawch\dev\google-cloud-node\node_modules\mocha\lib\runner.js:528:12
      at next (C:\Users\sawch\dev\google-cloud-node\node_modules\mocha\lib\runner.js:342:14)
      at C:\Users\sawch\dev\google-cloud-node\node_modules\mocha\lib\runner.js:352:7
      at next (C:\Users\sawch\dev\google-cloud-node\node_modules\mocha\lib\runner.js:284:14)
      at C:\Users\sawch\dev\google-cloud-node\node_modules\mocha\lib\runner.js:315:7
      at done (C:\Users\sawch\dev\google-cloud-node\node_modules\mocha\lib\runnable.js:287:5)
      at callFn (C:\Users\sawch\dev\google-cloud-node\node_modules\mocha\lib\runnable.js:344:7)
      at Hook.Runnable.run (C:\Users\sawch\dev\google-cloud-node\node_modules\mocha\lib\runnable.js:319:7)
      at next (C:\Users\sawch\dev\google-cloud-node\node_modules\mocha\lib\runner.js:298:10)
      at Immediate.<anonymous> (C:\Users\sawch\dev\google-cloud-node\node_modules\mocha\lib\runner.js:320:5)

…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
@ofrobots
Copy link
Contributor Author

@stephenplusplus I am unable to reproduce that locally. Is that windows only failure? Are the appveyor results to be trusted?

@stephenplusplus
Copy link
Contributor

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.

@ofrobots
Copy link
Contributor Author

ofrobots commented Mar 17, 2017

Actually, I see it to be failing on CircleCI as well.
EDIT: rebuilding Circle build with SSH enabled as I cannot reproduce this.

@ofrobots
Copy link
Contributor Author

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.

@ofrobots
Copy link
Contributor Author

Let's see if ce8caf7 fixes things.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0001%) to 99.924% when pulling ce8caf7 on ofrobots:better-log-viewer into d153530 on GoogleCloudPlatform:master.

@ofrobots
Copy link
Contributor Author

@stephenplusplus Fixed the problem. Does this LGTY?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging-bunyan api: logging-winston cla: no This human has *not* signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants