Skip to content

logger.error doesn't show in the "Health" tab anymore #954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
larssn opened this issue Aug 13, 2021 · 19 comments
Closed

logger.error doesn't show in the "Health" tab anymore #954

larssn opened this issue Aug 13, 2021 · 19 comments

Comments

@larssn
Copy link

larssn commented Aug 13, 2021

[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

@google-oss-bot
Copy link
Collaborator

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.

@taeold taeold transferred this issue from firebase/firebase-tools Aug 16, 2021
@google-oss-bot
Copy link
Collaborator

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@taeold
Copy link
Contributor

taeold commented Aug 30, 2021

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.

@taeold taeold added the Needs: Author Feedback Issues awaiting author feedback label Aug 30, 2021
@larssn
Copy link
Author

larssn commented Aug 31, 2021

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.

@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Aug 31, 2021
@taeold
Copy link
Contributor

taeold commented Aug 31, 2021

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

@taeold taeold added Needs: Author Feedback Issues awaiting author feedback and removed needs-triage Needs: Attention labels Aug 31, 2021
@larssn
Copy link
Author

larssn commented Aug 31, 2021

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! 😊

@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Aug 31, 2021
@taeold
Copy link
Contributor

taeold commented Aug 31, 2021

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?

@taeold taeold added Needs: Author Feedback Issues awaiting author feedback and removed Needs: Attention labels Aug 31, 2021
@larssn
Copy link
Author

larssn commented Aug 31, 2021

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.

@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Aug 31, 2021
@taeold
Copy link
Contributor

taeold commented Aug 31, 2021

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

@larssn
Copy link
Author

larssn commented Sep 1, 2021

Sounds good to me 🙂

@Flucadetena
Copy link

Flucadetena commented Jan 14, 2022

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.

@ishowta
Copy link

ishowta commented Jan 14, 2022

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')

@taeold
Copy link
Contributor

taeold commented Jan 14, 2022

@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).

@Flucadetena
Copy link

@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. :)

@ishowta
Copy link

ishowta commented Jan 15, 2022

@taeold I tried it with the Node12 runtime.

@ishowta
Copy link

ishowta commented Jan 15, 2022

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

@ftzi
Copy link

ftzi commented Jan 29, 2022

@ishowta so what is the best way to log a object with an error stack?

@Flucadetena
Copy link

Flucadetena commented Jan 29, 2022

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.

@taeold
Copy link
Contributor

taeold commented Dec 13, 2022

Functions Health tab no longer exists :(. Marking the issue as obsolete.

@taeold taeold closed this as completed Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants