nodejs-error-reporting icon indicating copy to clipboard operation
nodejs-error-reporting copied to clipboard

Add a way to suppress WARN for stackdriver NODE_ENV setup

Open defunctzombie opened this issue 4 years ago • 7 comments

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.

defunctzombie avatar Mar 29 '20 02:03 defunctzombie

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 avatar Mar 30 '20 00:03 defunctzombie

@defunctzombie this seems like a reasonable expectation 👌

bcoe avatar Mar 30 '20 17:03 bcoe

@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 avatar Nov 13 '20 10:11 laljikanjareeya

@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 avatar Nov 19 '20 10:11 bachlis

@bachlis It throws a warning when both NODE_ENV and reportMode are not the same, I will take a look into unit test output.

laljikanjareeya avatar Nov 25 '20 05:11 laljikanjareeya

Yes, it would be a nice warning to silence. It's very common setup to have these logs only produced in production.

wtesler avatar Dec 13 '20 20:12 wtesler

Its very annoying to still have this unnecessary message filling up my log files. Please remove!

tohagan avatar Apr 12 '24 03:04 tohagan