Only some Winston logger.error calls appear in the GCP error reporting

615 views Asked by At

I'm using Winston in my Node.js application on GCP as described here: https://cloud.google.com/logging/docs/samples/logging-winston-quickstart That works in a sense that I see the logs I expect in the log explorer.

I now want to that all errors appear in the "Error Reporting" dashboard (https://console.cloud.google.com/errors?project=...). However, only some errors are listed there. I am not 100% sure which errors make it to the error reporting dashboard, but my suspicion is that logger.error calls only appear in the error dashboard if there's a proper error stack trace.

But that's not what I want. I want that whenever logger.error in my application is triggered, an error group on the error reporting dashboard should be created - regardless of the string I pass to logger.error. How do I do that?

2

There are 2 answers

0
cis On BEST ANSWER

It seems, setting @type is not quite easy in Winston, but it's possible to add a (kind of artificial) stacktrace to the message like:

format: winston.format.combine(
    winston.format((info) => {
        if (info.level === 'error') {
            Object.assign(info, { message: `${info.message}${(new Error()).stack}` });
        }
        return info;
    })
...
)

That did the trick for me at least.

0
sshevlyagin On

I was just dealing with this in java, the key documentation is in formatting requirements.

Quoting:

Log entries in Logging that contain stack traces or exceptions, or that are formatted like ReportedErrorEvent, generate errors in Error Reporting.

Here's a related bugfix in a java library where they add a @type field with the value of type.googleapis.com/google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent to the json log message object when severity is error.

I'm not sure the right way to do this in winston, but that's what you need to do.