enter image description hereI saw the following error in Cloud Function logs:
Error: function terminated. Recommended action: inspect logs for
termination reason. Function invocation was interrupted.
But I'm not getting any logs in Stackdriver or in Cloud Functions for Firebase logs.
When looking at stackdriver make sure to enable all logs at the filter or use this advanced filter:
resource.type="cloud_function"
resource.labels.function_name="<function_name>"
resource.labels.region="<function_region>"
Uncaught exceptions produced by your function will appear in Stackdriver Error Reporting, but if they don't try adding a catch clause and manually write it to stdout
If for some reason you find an error that is not being logged to stackdriver you can reach out to GCP support so they can check if additional logging is available at the particular function termination occurrence.
Related
Having a Firebase Callable Function, for "handled" errors (not exceptions) occurring during execution, I throw new HttpsError(...)'s to notify the client that an error occurred and handle them appropriately.
For monitoring the healthiness of the Cloud Functions, I'm using Google Cloud Monitoring. Therefore I wanted to set up an alert that alerts based on the following query if something really goes wrong (unhandled exception, whatever other errors could occur during function execution):
What I want to have is exception alerting - so if a Cloud Function fails because during an execution an uncaught exception gets thrown, I want to be alerted.
But I do not want this alert to fire if I intentionally "return" (throw) this special HttpsError which is thrown in cases of misuse or "handled" errors (like authentication failure):
throw new HttpsError('permission-denied', 'Access denied')
My question is now whether Cloud Functions that throw HttpsError(...) count as status = "error" or if they count as status = ok in Cloud Monitoring.
My feeling is they count as error (as the alert fires sometimes) but if I then look in the Firebase Console's Function log, they do not show up as error there. So they do not have the red exclamation mark:
Instead there, the log just says something like ...finished with status code: 204
That's what makes me wonder if an error in Cloud Monitoring is just every function that ended with "Http Status code != 200"
If throwing an HttpsError does count as error, how could I query only functions that crashed/did not execute as intended for my alert?
I am new to google-cloud and to stack driver logging. deployed a python script as cloud function also enabled in-built logging for python. I had set multiples logs based on the execution.
logging.info("Cloud fucntion was Triggerred on time {}".format(datetime.utcnow()))
While viewing in cloud function logs, i see many, like even the statement above, for which I have set INFO as the log level is displayed with !! icon which according to the legends should be displayed for only error types.
As I am new to this stack-driver logging, I am not sure of the reason, can anyone please explain? Thanks.
I'm throwing an error from my callable Firebase function:
throw new functions.https.HttpsError(
'invalid-argument',
`Invalid token ${token} for file ${fileName}.`
);
I the logs I see only the following:
12:29:22.500 PM SQR-cancelAllotment Function execution took 1779 ms, finished with status code: 400
12:29:20.722 PM SQR-cancelAllotment Function execution started
So, code 400 is indicated without any error message. Why?
I wouldn’t like to duplicate the error message in a separate console.error.
Throwing an HttpsError is a signal to the client that the function didn't work as expected. It's not an indication that the function terminated with a crash (which would be logged). When you throw an HttpsError, if you want to see a message in the log, you should also make a call to console.error() (or whatever log level you want) in order for that to show up.
For throwing errors in Cloud Functions you could use the Stackdriver Error Reporting client libraries
Here you can find the documentation for setting up the error reporting ( you have some examples there,also)
console.log("Log") shows up as an Info level log in the firebase functions log.
console.debug("Debug") does not show up at all.
I have the log viewer set to display all log levels.
Is there something I need to do to support different log levels?
This is for the fulfillment for a dialogflow application, if this matters. I would guess it doesn't but it's my only experience with firebase.
console.debug is for internal messages.
You need to use:
console.log() commands have the INFO log level.
console.info() commands have the INFO log level.
console.warn() commands have the ERROR log level.
console.error() commands have the ERROR log level.
Check the documentation.
I'd like to create a cloud function which sends an e-mail based on a change in my database. I use postmark, but that's not relevant for this function. I looked at the firebase-examples.
My question is: What if the mail service returns an error or if the mail service is temporary down? I don't see any form of error handling in the examples.
My 'solution' would be to try again in 5 minutes for example. Is that possible and advisable in cloud functions?
If you throw an exception when sending the email fails, it should retry the function up to 7 days.
Open detailed usage states for your function in the firebase console
Edit the function
Click the link to configure retry
Enable "Retry on failure"
I haven't tried it myself yet for your use case, but it works for my storage triggered function when it fails.