nodejs-error-reporting
nodejs-error-reporting copied to clipboard
Add a way to suppress WARN for stackdriver NODE_ENV setup
When I run my unit tests, the stdout contains lots of the following 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".
This happens because my unit tests invoke my entire app (a koa2 app) which includes the error reporting setup.
I'd like a way to suppress this warning for testing - maybe by handling NODE_ENV=test
or a configuration option.
Actually I'd like to amend the request. Upon setting the reportMode
to never
by checking the environment variable myself, I still get the following output:
ERROR:@google-cloud/error-reporting: Unable to find credential information on instance. This library will be unable to communicate with the Stackdriver API to save errors. Message: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
My expectation was that when I disable reporting, the library does not attempt to lookup any credentials or perform any other actions. Basically becomes a no-op.
@defunctzombie this seems like a reasonable expectation 👌
@defunctzombie reportMode
can have one of three values:
production (default)
Only report errors if NODE_ENV is set to production
.
always Always report errors regardless of the value of NODE_ENV.
never Never report errors regardless of the value of NODE_ENV.
So in case of never
and always
it never gives any warning.
In case of production
it checks the NODE_ENV
variable and if it's not set to production
it will gives you warning.
The above functionality is working as expected 1.1.3
version and above.
@bcoe I think this is fair behavior WDYT?
@laljikanjareeya sorry for jumping in, but why throw a warning if I specifically have changed the NODE_ENV variable? For example when running unit tests this adds too much noise to the output. It would be nice to be able to "silence" those warnings.
@bachlis It throws a warning when both NODE_ENV
and reportMode
are not the same, I will take a look into unit test output.
Yes, it would be a nice warning to silence. It's very common setup to have these logs only produced in production.
Its very annoying to still have this unnecessary message filling up my log files. Please remove!