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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add special logging fields section in the doc #728

Merged
merged 2 commits into from Dec 11, 2023
Merged

Conversation

cindy-peng
Copy link
Contributor

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:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #690 馃
This is to add a small section to explain the special fields in structured logging.

Copy link

Warning: This pull request is touching the following templated files:

@product-auto-label product-auto-label bot added size: xs Pull request size is extra small. api: logging Issues related to the googleapis/nodejs-logging-bunyan API. labels Nov 28, 2023
@cindy-peng cindy-peng changed the title fix: add speciel logging fields section in the doc fix: add special logging fields section in the doc Nov 28, 2023
@@ -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.
Copy link
Contributor

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

Copy link
Contributor Author

@cindy-peng cindy-peng Dec 5, 2023

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:
image

Maybe we can just leave the doc as this since special fields handling looks like the default behavior?

Copy link
Contributor

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

@cindy-peng cindy-peng self-assigned this Dec 5, 2023
@cindy-peng cindy-peng merged commit 0b9ad2b into main Dec 11, 2023
18 checks passed
@cindy-peng cindy-peng deleted the cindy/update-doc branch December 11, 2023 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the googleapis/nodejs-logging-bunyan API. size: xs Pull request size is extra small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

message field in data record overwrites actual log message
3 participants