12

If a cloud function times out, I would like to have that as an error in the logs, so I can track the health of the functions, and if necessary take steps to improve speeds.

Is it possible to make that log to show as an error?

Also, is there a way to catch such timeout? I have a function that if an exception is thrown, saves something to the realtime-database. Is it possible to catch this error as well?

Firebase Response:

Thank you for reaching out, and for providing your feedback to us. I'm Kyle from Firebase Support and I'll be happy to handle this case regarding Cloud Functions with Firebase.

I understood that Cloud Function timeouts should be regarded as "errors" instead of "info" logs. I also agree that having another trigger that responds to timeout events like functions.onTimeout() would be very cool to be included in the future version of Cloud Functions.

For this, please note that I've cascaded your feedback (and use-case) about treating function timeouts as an error log, and not as an info log. I've also filed an internal feature request ticket for your suggestion of having functions.onTimeout() trigger. This will be processed to be discussed internally within the team, but I can't provide any ETAs or specific timeline as to when this requested feature will be implemented. In the meantime, you may keep an eye on our release notes and Firebase blog for upcoming features and bug fixes that Firebase offers to our valued developers.

Amit
  • 5,924
  • 7
  • 46
  • 94
  • Do you know what function is timing out? There should be an error with your code (IE not handling promises/async correctly). You can also [adjust the default timeout](https://stackoverflow.com/a/46013547/1968911) which might help with debugging. I'm guessing an operation hasn't finished so the function can't throw an error is it hasn't generated one yet. – sketchthat Dec 13 '18 at 23:47
  • I'm using max timeout, but this function is a background data request to third party service, and is out of my control. – Amit Dec 13 '18 at 23:49

2 Answers2

3

I figured out a workaround to accomplish this.

I used Google Cloud Functions tools to monitor timeouts of my Firebase Cloud Functions.

I set up a custom alert whenever "finished with status: 'timeout'" is logged by any of my functions:

I went over to https://console.cloud.google.com/logs/viewer and created a custom advanced search:

resource.type="cloud_function"
"finished with status: 'timeout'"

Then, I used the "Create Metric" feature to track instances of that log.

Then under https://console.cloud.google.com/logs/metrics, I found my user-defined metric and created a custom alert for it.

Charlie
  • 31
  • 4
  • It doesn't reflect the Firebase logs, isn't it? I mean, if you add a new customized error in GCP, to a Firebase project, now you can see it also in Firebase logs? – genericUser Jan 04 '22 at 17:10
  • I'm not sure but my guess is no. I've found Firebase logs to be fairly limiting. For this reason, whenever I need to do more advanced logging I end up using Google Cloud Functions tools instead of Firebase. – Charlie Feb 23 '22 at 18:20
1

When a function times out, you will see a line in the logs for that. Are you suggesting that you don't see it?

You can't catch timeouts. This is a hard restriction of Cloud Functions that prevents your code from running away outside of its control.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • 3
    I see the line in the log. It shows as info, not as error, so it doesn't show in Health or when I look for errors, I have to manually type in the search "timeout" which isn't good enough. (I accept timeouts as part of this function. They can happen, I would like to minimize them, but it is fine if it happens) – Amit Dec 13 '18 at 23:50
  • 1
    I don't think there's anything you can do to change the severity of the log message, but you can certainly file a feature request. http://firebase.google.com/support/contact/bugs-features – Doug Stevenson Dec 13 '18 at 23:55
  • @DougStevenson thanks for the clarification. I recently faced the same issue. My function was behaving unexpectedly and Firebase Logs, Firebase Health Dashboard, Google Cloud Functions logs showed no issues. Finally came to this answer and 'searched for `timeout` in logs', revealing that a critical function was getting timed-out after 60 secs for the past 5 days. – Mayur Dhurpate Jul 15 '19 at 13:23
  • I don't understand why the Firebase team decided that timeout is in Debug priority... timeout means that part of your code doesn't work as expected. Whether it's stuck on an infinity loop or just takes too much time and fails. **If your function FAILS, no matter what the reason is, It's a bug. So it should be an Error.** – genericUser Jan 04 '22 at 17:04