How can I view firebase cloud function logs older than 1 month - firebase

I have found that an error occurred in my app over a month ago. It is most likely due to an issue with a firebase cloud function which I have added logging to.
Unfortunately via the firebase control panel or GCP I can't view logs older than one month.
Is there any way to view these?
If there is not is there any way to export and save these to file?

If you can't see it in the console, then it's not available. You can use the Firebase CLI to view/print logs, but only recent entries.

I did it as follows. Thanks to #Neelavar for pointing me in the right direction.
More information here:
Log retention in Stackdriver GCP
-- Run as admin
VScode on windows
Right click the shortcut or app/exe
Go to properties
Check "Run this program as an administrator"
-- Install gcloud Alpha (as admin)
gcloud components install alpha
-- List all projects (optional)
gcloud projects list
-- Set current project
gcloud config set project my-project
-- Check correct project selected (optional)
gcloud config get-value project
-- Update retention period
gcloud alpha logging buckets update _Default --location=global --retention-days=365

Related

Firebase trouble when initializing CLI to deploy a react app

I keep getting the error below:
? Are you ready to proceed? Yes
? Which Firebase features do you want to set up for this directory? Press Space to select features, then Enter to confirm your choices. Hosting: Configure files for Firebase Hosting and (optionally) set up GitHub Action deploys
=== Project Setup
First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add,
but for now we'll just set up a default project.
? Please select an option: Use an existing project
Error: Failed to list Firebase projects. See firebase-debug.log for more info.
PS C:\Users\xxxxxlinked-in>
I have tried everything I can find on StackOverflow:
firebase login will log me in.
I have also done the firebase login --reauth one and also just reinstalling it npm install -g firebase-tools.
Its just when I go to use an existing project.
If it helps to know, I keep gettin another error when uing this command firebase projects:list.

ERROR: Failed to create project. See firebase-debug.log for more info

i Found 0 Firebase projects.
✔ Enter a project id for your new Firebase project (e.g. my-cool-project) · onoja
i New Firebase project onoja created succesfully.
FirebaseCommandException: An error occured on the Firebase CLI when attempting to run a command.
COMMAND: firebase projects:create onoja --json
ERROR: Failed to create project. See firebase-debug.log for more info.
This might be caused because you're using a new firebase account on Google or because you haven't set up the proper analytics on your Google firebase account.
I got rid of this by going into Google and setting up the project manually with all their various dialogues and then from thereon all other projects did not have this error in the CLI
if you just start using flutterfire configure for the first time. It means you haven't agreed any terms of use. You should go to firebase console on website first. Then start to build any project you want. You would asked to sign some papers during this process. Once it's done, you could use the terminal without the same error.
try
$ firebase login --reauth
if it does not work try
Open terminal.
vim .zshrc
Press "i" key to activate insert mode.
add export PATH="$PATH":"$HOME/.pub-cache/bin"
Press "Esc" then write :wq in terminal and press enter to exit vim.
Reopen the terminal and check "flutterfire --version"
firebase login
flutterfire configure
if the solution above does not work try to create a project on firebase console manually, and in visual studio command flutterfire configure
I solved the problem of creating a Flutter project in the command line.
Simply, the Project name should be less than 30 characters.
Please I hope you get the correct answer.
^^

new project not showing up Firebase CLI

Was recently added to a new firebase project via the web interface but it isn't showing up in firebase list. I can see the project in my firebase console. I've tried restarting my terminal, logging out/in, and doing firebase use, but no avail.
Any ideas?
Thanks.
firebase-init first asks which features you wish to use, e.g. database, firestore, storage, etc.
If you choose firestore but have not yet enabled Firestore in your newly created Firebase project via firebase.google.com website, that project will not show up as a project option.
So, before running firebase-cli, enable all the features you want via the website first, ...before chosing those features in step 1 of firebase init.
Once you've enabled Firestore, for example, your project will now show up.
There is now a --project option you can use with firebase init to choose the project.
firebase init --project <projectId>
You can select your project if you know the project id:
firebase use --add
That will select the project, so when you type "firebase init" will not show the select project option but take you to the next step
After 24 hrs, the project finally showed up in my list. Turns out there's just an extremely long delay if you're not the owner of the project.
While following the firebase init steps, use the [don't setup a default project] option.
Then use firebase use --add projectId to add the project.
So recently I changed my password, and was still logged into my firebase account, I did firebase logout and then tried firebase login again, and this time the firebase use --add command worked
In case this helps anyone else: a firebase project is just a firebase-enabled Google Cloud Platform project.
You can create a GCP project but it won't appear in the firebase CLI until you visit console.firebase.google.com and enable firebase for your GCP project of choice.
Then
firebase use --add your_google_cloud_platform_project_id
Should detect your project.
When firebase init asks you to choose a project from the list just check [don't setup a default project] and after the installation you can manually add the project to the .firebaserc file as shown below.
{
"projects": {
"default": "your-project-id"
}
}
You can check the id's of your projects with the command firebase list.
It'll also show the current project.
The below solution worked for me.
Get the Project Id from firebase console. e.g. myproject-2233
On Firebase CLI run below command
$ firebase -P myproject-2233
Next Select the features you want to add e.g. Web Hosting
Next Select "Don't Setup a default project"
Give the public folder name
It worked only after choosing "Don't Setup a default project"

"Error: Permission denied" when running firebase init and choosing database

So I’m testing out the CLI today and firebase init with db/hosting selected, and choosing to create a new project, always says Error: Permission denied..
sudo firebase init didn’t help.
firebase-tools version 3.0.3 on OS X 10.11.5.
firebase init
You're about to initialize a Firebase project in this directory:
/Users/splaktar/Git/tmp
Before we get started, keep in mind:
* You are initializing in an existing Firebase project directory
? What Firebase CLI features do you want to setup for this folder? Database: Deploy Firebase Realtime Database Rules
=== Project Setup
First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add,
but for now we'll just set up a default project.
? What Firebase project do you want to associate as default? [don't setup a default project]
=== Database Setup
Firebase Realtime Database Rules allow you to define how your data should be
structured and when your data can be read from and written to.
? What file should be used for Database Rules? database.rules.json
Error: Permission denied.
I've tried the answers here but they did not help. Is this just a bug in the firebase-tools?
I have the same issue and this is how I fixed it.
run firebase init
Deselect ❯◯ Database: Deploy Firebase Realtime Database Rules
Go through other steps to setup the initial app, selecting the default for each should work just fine.
run firebase serve
Hope that helps.
Sometimes it could happen when .firebaserc file exists.
Remove .firebaserc file and reattempt firebase init.
I was with the same problem, but I was not accessing the right account.
After accessed the right account, I created a new project and run "firebase list" (before this not happened) and my new project was there.
This solved my problem.
You need to have Owner or Editor IAM permission on the GCP project to use firebase init command.
The firebase init command initializes/enables the project to use Cloud Functions/Hosting etc for Firebase. Owners/Editors have higher permissions that allow APIs to be enabled etc.
it is a first-time task when you starting the development, and then init command can be avoided if you have set up your cloud functions code in VCS for multiple developers or you.
i.e, Usually after writing code, you will replicate the project to other developers, who will then also write code and use firebase use yourprojectid further.

How to delete site via CLI

Is there a way to delete an app via Firebase CLI?
Our CI creates a temporary Firebase app for a feature branch (based on the CI build number), and then runs tests on it. At the end it needs to delete the app. I'm not entirely sure how this is done. firebase disable:hosting just disables hosting and does not delete the app. This is similar to how we would have used Heroku review apps or Heroku forked apps. A similar CI workflow can also be achieved on Google App engine via versions.
Any pointers would be much appreciated.
The correct command is firebase hosting:disable, which make your site offline. You can not remove your project, instead you can overwrite it by creating a new one with firebase init.
More info here https://firebase.google.com/docs/cli/.
There is currently no public API to delete a Firebase backend.
The recommended practice is to use the same database for testing and (if needed) put each run in its own node under the root. So instead of creating/deleting a new database, you're just create/deleting a node in a single database.
Using the command firebase use <alias> --unaliasand then delete the project from the console https://console.firebase.google.com/
Check before the list of commands with the command -h

Resources