console.debug not showing in firebase functions log - firebase

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.

Related

Google Cloud Function logs showing error icon for Info log types

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.

Cloud Logging API not showing JSON Payload

I am are using cloud logging APIs to publish stackdriver logs. I'm using an enhancer to convert a textpayload to jsonPayload. I don't see any errors while I convert the payload. However, I do not see any data in jsonPayload on the console.
I tested with textPayload and it works perfectly fine, Is there something clearly obvious that I might be missing.
UPDATE: I got the jsonpayload to log but now, I see that only the values which are null are being logged. Non null values are not logged
Documentation on how to log structured logs to cloud logging can be found here: https://cloud.google.com/logging/docs/structured-logging
It sounds like your JSON is likely to be invalid if values are ignored and nulls are accepted. Perhaps quotes around text are missing?
I'd suggest you output your logs to console or a file and manually inspect the format.

Permission errors unit-testing Google Cloud Functions calling firestore db

I'm following the guide at https://firebase.google.com/docs/functions/unit-testing, but I always get " FirebaseError: Missing or insufficient permissions" when I run my test. I have the correct service-account.json file and I'm setting up firebase-functions-test with it (that part goes without error).
I've tried it with the emulator running (setting the FIRESTORE_EMULATOR_HOST var), and without it (which I assume uses live data) but I always get this error, as soon as my code under test does a db request such as:
data = await db().collection('/machines').get()
So my function under test is getting called, but it just can't do anything.
I also tried calling firebase.initializeApp() the same way I do in my front-end app, but that doesn't help, although without it I get the error telling me to call Firebase App.initializeApp().
firebase use is set to my current project.
I also tried running my test as firebase emulators:exec jest, no difference.
Any ideas?

Cloud Function automatically terminated

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.

Retry Cloud Functions for Firebase until it succeeds

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.

Resources