I'm using simply console.log('some flag', someObject) on Google Cloud and functions.logger.log('some flag', someObject) on firebase functions.
The problem is that both Firebase's admin panel logs page and Google Cloud's logs page makes this hard to read. Logs are getting split into lines. If my log had line breaks, then each line will be displayed as a separate log. Moreover, Google Clodu clearly has some kind of racing conditions when it comes to recording logs, as my logs are often displayed in the wrong order.
An obvious solution would be console.log('some flag', JSON.stringify(someObject)), but this makes logs hard to read in a different way. Now I have to copy the stringified object and JSON.parse it somewhere in browser console to make it readable.
What is the right way of writing logs in Firebase and Google Cloud?
The Cloud Functions logger SDK provides a standard interface that has a similar api to console.log statements and supports other log levels. You can use this SDK to log events with structured data, enabling easier analysis and monitoring.
The logger SDK supports log entries as part of a wildcard import. For example:
const functions = require("firebase-functions");
functions.logger.log("Hello from info. Here's an object:", someObj);
For Firebase Cloud Functions is better to use functions:logger to write logs and for reading logs use the command
firebase functions:log from CLI
Related
For some reason, I don't see the ability for me to create FCMs from the Firebase console. It's not a browser issue as I tried on multiple browsers. It's not a permissions issue either since I am the owner of the project.
I tried implementing cloud functions to send FCMs and ever since when I go into the Cloud Messaging panel of the Firebase console I can no longer see the option to create messages.
Any insight would help!
Update--This is the error I'm getting from the JavaScript console:
Last couple of weeks, I have been Observing difference between number of writes in Firebase console Firestore Usage tab and Google cloud console Quota page.
Before that, The count fairly used to sync.
Number of writes in Firebase Firestore console usage tab: 9.2K
Number of writes in Google Cloud Console page, Quotas Page: 19307
Which is approximately double the number of writes in Firebase Firestore Usage Tab. Are there any Internal writes happening which google doesn't report?
Firebase Console Firestore Usage Tab Page
Google cloud Console Quotas page
I have attached the screenshots for the same.
Can anyone clear My Query. Is this a valid Scenario?
Note: I Don't have any other project linked to the platform.
From your first screenshot you can see at the top left written on the graph “Does not include Imports/exports and may not match billing and quota usage”. Moreover, Google public documentation states that the Firebase console includes a usage dashboard that shows Cloud Firestore reads, writes, deletes and other metrics over time.
As a result of how the dashboard computes usage, the numbers reported can differ from billing reports. The billing reports are the final usage numbers.
The usage dashboard does not include reads and writes from managed import and export operations.
So,I have to answer my question.
I've found out the root cause. Firestore FieldValue atomic operations causing the double writes.
This double writes happening with any SDK version even in Cloud functions Admin SDK.
I've skipped the use of atomic operations using FieldValue. All Fine now.
Firebase Support Investigating the Issue. Will update When I Got more Info from them.
Edit:2
Response from Firebase support:
"The two writes come from: 1) the initial write and 2) the transformation. This is not a bug, and what is shown in the Cloud console is correct. We do have an internal ticket now to make sure the Firebase console syncs up this information better, as well, so hopefully that'll help."
That means Fieldvalue functions to increment and array Union, servertimestamp will cause two writes and I also found that they are causing extra reads as well. I feel Firebase should reconsider their decision of not considering it as bug or atleast restructure this Atomic Operation. Let's Wait and See.
I've got 2 different firestore interfaces: both using the same firestore project.
I'm finding this abit confusing - which one am I meant to operate in?
How come the 2nd doesn't have access to other settings such as Rules?
They are both meant for you to operate in. Which one you use depends on whatever your preference is. If you prefer to stay in the Firebase ecosystem, then use the Firebase console. If you prefer to stay in the Google Cloud ecosystem, then use the Cloud console.
Read more about the differences with Cloud Firestore between Firebase and Google Cloud.
Cloud Firestore is available with, or without Firebase SDKs.
For Firebase users, the Firebase interface allows you to configure Firebase specific functionality (Rules).
For GCP users, the Google Cloud interface keeps you closer to other services and admin settings you'll likely be using, such as IAM, BigQuery, etc. It also gives you quick access to a shell (Just click the Cloud Shell icon) so you can quickly run commands like gcloud firestore export.
Both interfaces will show you the same data.
Work in the first one. The second one is a simplified screen I think, because it is also for other services
I am just start learning how to write fulfillment to read a data stored in the firebase as a first step.
Actually, I stored the same data in the firebase realtime database
and the firebase cloud database just to try from which one i must read my data, so I am just stuck how to retrieve it by the inline editor
My data is just a JSON object String names.
Note : form where i should start to learn Node.js for dialogflow fulfillment to do basic operation as storing and retrieving ?
You can use the firebase-admin library for node.js.
The inline editor is just Firebase Cloud Functions under the covers.
Your fulfillment code needs to run "somewhere" in the cloud - you'll need an HTTPS URL that you will provide, so this is called a "webhook". Firebase Cloud Functions are a convenient place to do this - they provide a HTTPS endpoint and good scalability, but you can run your fulfillment webhook anywhere on the public Internet.
Dialogflow provides an easy way to use Firebase Cloud Functions, by providing the inline code editor. This uses Firebase Cloud Functions to do the work, but hides the URL from you, so it is one fewer thing you need to deal with.
There are a number of good places to get started, but one is using Google's Codelabs for the Assistant make sure you also have looked at Google Docs for Actions on Google, which links to other resources as well.
I have some pub / sub setup on Google Cloud and I have some Cloud Functions running on Firebase.
I'd like to set a trigger on Firebase, so when a user account is created, I publish a message to a topic on Google Cloud.
Is this possible? Am I missing something obvious?
I can trigger a cloud function on account creation and I'm happy at this point showing a console log.
I was considering in my Firebase trigger add something like #google-cloud/pubsub so I can literally setup the message in the body of my firebase trigger, but that feels a little wrong.
Quite clunky and not the way it should be done?
In short, I guess what I'm trying to do is firebase publish to topic on trigger?
I don't think there's anything wrong with what you're suggesting as a solution. You can use an authentication trigger to find out when a new user account is created, then use the node Cloud Pubsub SDK to turn around and publish a message to your topic. There's really no more straightforward way to accomplish this that I can think of.
It's pretty common to mix Cloud APIs into your Cloud Functions, regardless if they're based on Cloud or Firebase events.