Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

console.log on Firebase Cloud Functions simply not logging.

I'm tearing my hair out here:

I have a cloud function that looks like this:

exports.stripeCharge = functions.firestore.document('/payments/{paymentId}')
    .onWrite((doc, context) => {
        console.log("hello?");

        const payment = doc.after.data();

        // Snip - What happens here shouldn't affect whether the log show or not right? 
}); 

But my log statements simply don't show up on my logs - even though the execution does.

ie. sample logs:

5:04:40.084 PM
stripeCharge
Function execution took 288 ms, finished with status: 'ok'
5:04:40.077 PM
stripeCharge
Function returned undefined, expected Promise or value
5:04:39.797 PM
stripeCharge
Function execution started
5:04:13.583 PM
stripeCharge
Function execution took 10195 ms, finished with status: 'ok'
5:04:07.696 PM
stripeCharge
The behavior for Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK. To hide this warning and ensure your app does not break, you need to add the following code to your app before calling any other Cloud Firestore methods: const firestore = new Firestore(); const settings = {/* your settings... */ timestampsInSnapshots: true}; firestore.settings(settings); With this change, timestamps stored in Cloud Firestore will be read back as Firebase Timestamp objects instead of as system Date objects. So you will also need to update code expecting a Date to instead expect a Timestamp. For example: // Old: const date = snapshot.get('created_at'); // New: const timestamp = snapshot.get('created_at'); const date = timestamp.toDate(); Please audit all existing usages of Date when you enable the new behavior. In a future release, the behavior will change to the new behavior, so if you do not follow these steps, YOUR APP MAY BREAK.
5:04:03.390 PM
stripeCharge
Function execution started

What am I missing here?

like image 867
dwjohnston Avatar asked Jul 29 '18 07:07

dwjohnston


2 Answers

Ok, the problem ended up being that the function wasn't deploying properly.

What had happened was due to some typescript/firebase config issue - the new code was being compiled to a location that wasn't what firebase was looking for.

When deployed the code - some old compiled code was still there to be deployed.

The moral of the story here is: make sure you delete your dist/build/lib directory before deploying - as that will cause an error if firebase is looking in the wrong place.

like image 163
dwjohnston Avatar answered Sep 26 '22 09:09

dwjohnston


In case someone wastes as much time as I did. It turned out I was logged into the wrong firebase project 🤦🏻‍♂️.

firebase projects:list

Your current project will be highlighted in blue with "(current)" beside it.

If you need to change project:

firebase use insert-project-id-here
like image 34
paul_f Avatar answered Sep 24 '22 09:09

paul_f