googleapis / googleapis/google-cloud-node
Make it possible to create error logs that are picked up by GCP Error Reporting
- Dominant language
- TypeScript
- Stars
- 3.2k
- Forks
- 712
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 99
Description
### Library Name
@google-cloud/logging-winston
### A screenshot that you have tested with "Try this API".
does not apply
### What would you like to see in the library?
#### Context
We're running a NodeJS application in GCP and wish to have logs with severity/level 'ERROR' show up in GCP's Error Reporting service.
We are currently using the `@google-cloud/logging-winston` library to write log messages (as recommended by GCP). However, we are finding that this library prevents us to write log messages in the format that the Error Reporting service expects.
According to the Error Reporting service's [documentation](https://docs.cloud.google.com/error-reporting/docs/formatting-error-messages), a log entry would be picked up when one these are true:
1. the log entry's message contains a stack trace
2. the log entry contains certain specific fields (`stack_trace` or `exception`, or a specific `@type` value
Although *1* is possible, it will include a stack trace inside a plain text message field, which clutters up the logging quite a bit. This makes querying and organizing logs unnecessarily harder.
Using method *2* would be a huge improvement, however the `@google-cloud/logging-winston` library prevents us from doing that. When we try to add a `stack_trace`, `exception` of `@type` field, it gets moved in a `metadata` object instead, causing the Error Reporting service to ignore the log entry.
#### Proposal
The `@google-cloud/logging-winston` already defines certain special message keys which are not put into the `metadata` object (fields like `logging.googleapis.com/trace`, `level` etc.). I propose we add `stack_trace` and `@type` to that list as well, allowing us to properly format a log entry to be picked up by the Error Reporting service.
As an alternative, we could also introduce a new option field in `@google-cloud/logging-winston` which explicitly enables formatting a log entry to be picked up by the error reporter (something like 'formatForErrorReporting:true`?).
_No response_
### Describe alternatives you've considered
_No response_
### Additional context/notes
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.