Get rid of annoying logs by Firebase function "this may be a production service" & "External network resource requested" - firebase

When running a Firebase function, my logs are very noisy mostly because of those 2 messages
Be careful, this may be a production service.
⚠ External network resource requested!
I know I am running a production service, and yes I am requesting an external ressource 😅 can I disable them?
Thanks

Normally using --quiet would silence this message, however because there are so many emulators, the Firebase team couldn't reach a consensus on whether to allow this to be silenced when used with firebase emulators:start (see firebase-tools Issue #2859).
The official stance on this is to set the logs filter to only show "user" logs using the Emulator Suite UI's Logs Viewer and let the regular log feed log everything.

Related

Firebase functions emulator requesting external network resource: computeMetadata

I have the firebase emulator running in a docker container locally for testing. The emulator includes everything I'm using for my app (firestore, auth, functions, storage) so that I can develop and test independently of the production environment.
However, I'm getting these warnings which are making me nervous:
functions: Beginning execution of "myFunction"
⚠ External network resource requested!
- URL: "http://---.---.---.---/computeMetadata/v1/instance"
- Be careful, this may be a production service.
I don't know what that URL is? Does it mean I've misconfigured something somewhere?
I'm also getting these warnings:
⚠ emulators: You are not currently authenticated so some features may not work correctly. Please run firebase login to authenticate the CLI.
⚠ functions: You are not signed in to the Firebase CLI. If you have authorized this machine using gcloud application-default credentials those may be discovered and used to access production services.
⚠ functions: Unable to fetch project Admin SDK configuration, Admin SDK behavior in Cloud Functions emulator may be incorrect.
But I don't think I want to authenticate, right? I don't want to touch anything to do with the live project on production while testing locally. Can I safely ignore these, or is there a good reason to authenticate?
The warnings are indicative that there had some issues while initialization during the setup for emulators .
Make sure that the emulator is installed by the following command: firebase setup:emulators:firestore, for this you can refer Documentation.
Deploy your function in the firebase in order to get recognized. you can refer to the Documentation using firebase deploy --only functions
Also to be sure please check your Firebase json and see if the local host is configured and not the production host,just to be sure.
For further reference you can follow up the stackoverflow thread Docker authentication issueand Firestore emulatorwhere a similar issue has been raised by other users which might be helpful.

How to investigate errors in Firebase Remote Config API?

I see errors for the Firebase Remote Config API in the Google Cloud Console > API/Service Details metrics.
Looking at "Traffic by response code" I see that a specific API key is causing HTTP code 400 responses from the API for the method:
google.firebase.remoteconfig.v1.RemoteConfigService.FetchRemoteConfig
I'm not able to reproduce this issue locally so how can I find out more about these errors in the Google Cloud Console?
What I've checked so far:
The credential that is causing the errors is restricted to the correct package name and SHA-1 hash (hash taken from Google Play Console > App Integrity)
It's apparently not hitting a quota limit from looking at the quote graph
From the client side logs I only see the exception:
com.google.firebase.remoteconfig.g: The client had an error while calling the backend!
This is a standard error message used in the Remote Config SDK for a client error (ex: a connection timeout, SSL issue, etc.). I suggest that you double check your implementation. You could also use the Android network debugger to simulate the network calls, so it could create a handling mechanism to ensure that the actual device has a proper connectivity on doing the fetch.
You may also refer to the Stackoverflow post and the GitHub Link.
Google Developer Support pointed me to a known bug in the Firebase Remote Config library which has been fixed recently. Upgrading the library indeed fixed the issue.

Call Google Cloud API from local Firebase Emulator

I've got a function which uses #google-cloud/language.
The function works when deployed live but when running in the local function emulator it complains
I've done firebase login with my Google account but get the following when running the function:
Error: 7 PERMISSION_DENIED: Cloud Natural Language API has not been used in project XXXXX before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/language.googleapis.com/overview?project=XXXXX then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
XXXXX is a project Id I don't recognise - where has this come from and how can I check if I'm mistaken?
The account I'm authed with firebase locally is already in the Owner role for the project, so either the project ID is wrong, or I need to grant permissions to the user?
What do I need to do?
The solution is to set the environment variable GOOGLE_APPLICATION_CREDENTIALS for authentication:
https://cloud.google.com/docs/authentication/getting-started#windows
And restart all the things due to my ENV variable not being updated.

Streaming Firebase Function logs to a local terminal

Streaming Firebase Function logs to a local terminal would be very helpful since the Firebase Console web interface for logs is pretty sluggish to work with.
Does any one know a way to achieve this?
Using the Firebase CLI, according to the documentation, run the command:
firebase functions:log
This gives you a dump of recent logs, but it doesn't "stream" them to your terminal. Unfortunately, this is the best you can do.
If you're a gcloud user, there are equivalent commands, as described in its documentation. There is also no option to stream the logs live with gcloud.
If you want a "live" view of logs of your deployed functions, you're going to have to use the Firebase or Google Cloud console.
If you're doing active development and need the logs for code you've just written, it might be easier to use the Firebase emulator suite to run functions locally, so you can see logs appear live in the terminal where the emulator is running.

Stackdriver logs not available for Cloud ML jobs since migration to V2

Since migration to V2 logs from Cloud ML jobs are not accessible on the Stackdriver logging console anymore. The last log displayed is
Waiting for Tensorflow to start.
The job is executed and completed successfully, I just can't access outputs in the logs
All Stackdriver APIs are enabled for the project.
There are no known issues with Cloud ML's Stackdriver logging. The fact that you see "Waiting for Tensorflow to start." indicates you are seeing log messages from Cloud ML.
If logs from your Python/TensorFlow program are missing that usually indicates Cloud ML hasn't been authorized to send logs to Stackdriver logging for your project. To check permissions do the following
Identify the Cloud ML service account by following these instructions
In the Cloud Console select the IAM Tab
Verify that the Cloud ML service account is listed and has Logs Writer permissions
This problem also took me two weeks to search answers online with frustration, until I came across this post. I did not see "migration to V2" as OP mentions but I simply could not get any application logs in StackDriver, only system logs of job started/completed. Following what Jeremy replies solves the problem.
To make Jeremy's reply simpler to follow, essentially you add the ML service account
cloud-ml-service#<project-id>.iam.gserviceaccount.com
to your project's IAM members, with at least "Logs Writer" role.
You can get "project-id" by:
gcloud config list project --format "value(core.project)"
I also assigned Project->Editor role to allow Bucket access.

Resources