fix: add special logging fields section in the doc#728
Conversation
|
Warning: This pull request is touching the following templated files:
|
|
|
||
| ### 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.
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.
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.
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.