-
Notifications
You must be signed in to change notification settings - Fork 34
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
fix: add special logging fields section in the doc #728
Conversation
Warning: This pull request is touching the following templated files:
|
@@ -80,6 +80,10 @@ body: |- | |||
|
|||
You may also want to see the [@google-cloud/error-reporting][@google-cloud/error-reporting] module which provides direct access to the Error Reporting API. | |||
|
|||
### Special Payload Fields in LogEntry | |||
|
|||
There are some fields that are considered special by Google cloud logging and will be extracted into the LogEntry structure. For example, `severity`, `message` and `labels` can be extracted to LogEntry if included in the bunyan log payload. These [special JSON fields](https://cloud.google.com/logging/docs/structured-logging#special-payload-fields) will be used to set the corresponding fields in the `LogEntry`. Please be aware of these special fields to avoid unexpected logging behavior. |
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.
I believe this only applies to logs written to stdout, when parsed through the Logging Agent. You should make sure that is captured in the message here
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.
Sorry Daniel I missed this comment earlier.
Initially I thought the same, then I looked into code and it looks like we are honoring these special fields and do a special processing from bunyan entry even without redirectToStdout: true
. Here is the where the logEntry is formatted: https://github.com/googleapis/nodejs-logging-bunyan/blob/main/src/index.ts#L253.
An example code snippet I was using Bunyan logger without redirectToStdout
:
const loggingBunyan = new LoggingBunyan();
const logger = bunyan.createLogger({
name: 'my-service',
streams: [
{stream: process.stdout, level: 'info'},
loggingBunyan.stream('info'),
],
});
logger.info({ message: 'boom11', labels: {first: "label-name", count: "2"} , "logging.googleapis.com/trace_sampled": true }, 'this is the actual message');
You can see the special fields (traceSampled
and labels
here) are being processed and actually promoted to the log entry level:
Maybe we can just leave the doc as this since special fields handling looks like the default behavior?
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.
Ok interesting, I was thinking from the backend perspective, but I guess nodejs must be doing its own parsing as well. LGTM then
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #690 🦕
This is to add a small section to explain the special fields in structured logging.