I have followed the Node.js instructions here
I have an express server deployed to Cloud Run. If I use the express middleware and send an error to next()
, as in the documentation, it shows up in Error Reporting.
However, if I use the report
method in various forms like below, nothing is reported.
// Report an Error object
errors.report(new Error('My error message'), () => {
console.log('Done reporting Error object!');
});
// Report an error by provided just a string
errors.report('My error message', () => {
console.log('Done reporting error string!');
});
// Use the error message builder to customize all fields ...
const errorEvent = errors.event();
// Add error information
errorEvent.setMessage('My error message');
errorEvent.setUser('root@nexus');
// Report the error event
errors.report(errorEvent, () => {
console.log('Done reporting error event!');
});
I have tried adding the IAM role "Error Reporter Writer" to my (AppEngine default) service account that I used to deploy to Cloud Run, but it still doesn't work.
The TS compiler also doesn't accept the callback function as is used in the examples, so either the examples are outdated or the TS type definitions are wrong.
Any ideas?
I attempted to reproduce your error and found out some few things such as this warning:
WARN:@google-cloud/error-reporting: The stackdriver error reporting client is configured to report errors if and only if the NODE_ENV environment variable is set to "production". Errors will not be reported. To have errors always reported, regardless of the value of NODE_ENV, set the reportMode configuration option to "always".
For Error Reporting Client Library to work with Cloud Run, make sure that:
NODE_ENV
which contains value production
. Or add reportMode
when instantiating the client:const errors = new ErrorReporting({
projectId: 'my-project-id',
reportMode: 'always',
}
Here's a sample where I was able to submit to Error Reporting using report()
method: