logger.error doesn't show in the "Health" tab anymore
[REQUIRED] Environment info
Not sure if this is the right place to post this in the myriad of issue trackers. Sorry in advance.
firebase-tools: 9.16.3
Platform: Node 14
[REQUIRED] Test case
Doing a logger.error('Something') no longer shows up in the health tab in the firebase console under Functions->Health.
[REQUIRED] Steps to reproduce
import { logger } from 'firebase-functions';
logger.error('Something')
Notice that it doesn't show up in the health tab anymore
[REQUIRED] Expected behavior
That it shows up there - we need to log handled errors to the health tab.
[REQUIRED] Actual behavior
It never shows up
This issue does not have all the information required by the template. Looks like you forgot to fill out some sections. Please update the issue with more information.
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Thanks for reporting the issue @larssn.
I'm not familiar with how error reporting in the health tabs worked before, but you will need to explicitly include an Error object if you want these error logs to show up in the Health tab or in the GCP Error Reporting. e.g.
functions.logger.error("this is functions logger error", new Error("From the functions logger"));
Since Node.js 10, Google Cloud Functions does not work very well with console.* family of functions, and I recommend that you stick with functions logger.
Check out https://cloud.google.com/functions/docs/monitoring/error-reporting on examples of what log statement works/does not work with GCP error reporting tool (just replace console. with functions.logger.).
Let us know if this helps.
As I wrote, it used to log errors in Health tab when you did a logger.error. You could log anything.
The health tab now seemingly only reports unhandled errors. It can be problematic that your handled errors no longer shows up in the health tab. Imagine having to dig through a huge log file every day to find problems, instead of it being in the health tab.
@larssn Any recent changes to your function that you are aware of? Any recent version bump to Firebase Functions SDK or update to the nodejs runtime version?
I can check to see if there were any deliberate changes that were made in the Health tab, but AFAIK, health tab just fetches data from GCP Error Reporting (https://cloud.google.com/error-reporting), which only reports log.error that actually includes an error object. I think this behavior might be new in the Nodejs10 runtime.
Our NPM versions are updated regularly.
However we did switch to the Node 14 runtime, 3-4 months ago I'd say.
Thanks for the help! 😊
Just to get the timeline correct - when you say "it used to log errors in Health tab... You could log anything" - is this 3-4 months ago or like last week?
I haven't kept track of when it is used to work like that, but I know it didn't work last week, probably the entire month of August. For all I know it could be the swap to Node 14.
@larssn That sounds possible. Given the state of things now, I think we can shape our conversation here as a feature request to automatically wrap strings passed into functions.logger.error as an error object. This is arguably backward incompatible change (maybe people don't want errors to show up on Error Reporting? 🤷), so we could sneak it in on the next major release.
Sounds good to me 🙂
I'm having the same issue, the documentation states that using:
console.error(new Error('I failed you'));
console.error('I failed you', new Error('I failed you too'));
throw new Error('I failed you'); // Will cause a cold start if not caught
Will get reported to Error reporting and should be logged as an Error in the "cloud functions" panel. But it doesn't when using the second method:
console.error('I failed you', new Error('I failed you too'));
Only the other two will report the error.
It's not complete, but I've tried some way.
updated
// Reported correctly with error message (Errors of the same class are grouped together)
functions.logger.error(new Error('error on logger error'))
console.error(new Error('error on console error'))
throw new Error("handled error");
functions.logger.error(
new MyError(
'error with custom property on logger error',
// my error class just saving it as a property
// and error reporting stringified it and stored in text payload
{ hello: 'world' }
)
)
// Reported correctly. however, the argument is combined with the error message and output as an error message.
functions.logger.error(
'string and error on logger error',
new Error('Bar')
)
functions.logger.error(
{ 'structured data and error on logger error': 123 },
new Error('Bar')
)
// Reported correctly with additional structured data
// https://cloud.google.com/error-reporting/docs/formatting-error-messages
const manualErrorPayload = {
// required for (simplified?) reported
'@type':
'type.googleapis.com/google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent',
severity: 'ERROR',
message: 'manual error',
// can additional structured data (Although it may be illegal data that is not officially permitted)
foo: 'bar',
hey: { yo: 'yeah' },
}
console.error(JSON.stringify(manualErrorPayload))
// Not reported
functions.logger.error('string on logger error')
console.error('string on console error')
console.error('string and error on console error', new Error('Foo'))
throw new functions.https.HttpsError('internal', 'functions https error')
@ishowta Thanks for a thorough experiment. I'll see if I can grab the attention of our tech writer next week to update our content.
In the meantime, I'm curious what version of Nodejs runtime you used to check the output - there seems to be a difference in how error shows up in the Error Dashboard depending on the Nodejs version (12 vs 14 vs 16).
@taeold Hi!, I know you tagged @ishowta but im experiencing the same error and I'm using node 14. But I could experience the same error in 12 too. Don't know if it is the case of @ishowta
Thanks for your time in any case. :)
@taeold I tried it with the Node12 runtime.
@taeold @Flucadetena Sorry, my test code was wrong, so I fixed it and cleaned it up.
Basically, if there is an error instance, it seems to be reported, but in the form console.error("something", new Error("error")) was not reported.
@ishowta so what is the best way to log a object with an error stack?
Hi @SrBrahma Any of the options but, console.error("something", new Error("error")) that it is not working at the time.
I use: console.error(`your text here ${error}, ${otherData}, ...`)
And this is working great for me now.
Functions Health tab no longer exists :(. Marking the issue as obsolete.