Make it possible to create error logs that are picked up by GCP Error Reporting

Open Beginner friendly
#8,169 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
google-cloud, nodejs, typescript

Research direction

Start by locating the special message-key handling in @google-cloud/logging-winston and its tests. Verify how stack_trace and @type are currently placed, then add coverage showing that the supported Error Reporting fields remain in the expected top-level log entry and are recognized by the relevant formatting behavior.

Written by the indexing model from the issue text.

Description

api: logging size: s type: feature request
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, 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

Dominant language
TypeScript
Stars
3.2k
Forks
714
Avg merge
2d 13h
Merged PRs (30d)
106

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from googleapis/google-cloud-node

All issues in googleapis/google-cloud-node

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.