node.jsgoogle-cloud-platformwinstongoogle-cloud-error-reporting

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


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?


Solution

  • 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.