This tutorial shows how to report and track uncaught exceptions in the Getting started with Python tutorial by using the Google Cloud console.
Error Reporting provides a centralized dashboard that shows counts of each unique error, stack traces, and a history of occurrences. You can also set up an alert for when errors occur.
This page is part of a multi-step tutorial. To start from the beginning and read the setup instructions, see Get started with Python.
Configuring settings
This section uses code in the 5-logging directory. Edit the files
and run commands in this directory.
-
Open the
config.pyfile for editing and replace the following values: -
Set the value of
[PROJECT_ID]to your project ID, which is visible in the Google Cloud console. -
Set the value of
[DATA_BACKEND]to the same value you used during the Using structured data tutorial. -
If you are using Cloud SQL or MongoDB, set the values under
the
Cloud SQLorMongosection to the same values you used during the Using structured data step. -
Set the value of
[CLOUD_STORAGE_BUCKET]to your Cloud Storage bucket name. -
Under the
OAuth2 configurationsection, set the values of[GOOGLE_OAUTH2_CLIENT_ID]and[GOOGLE_OAUTH2_CLIENT_SECRET]to the application client ID and secret that you created previously. -
Save and close the
config.pyfile.
If you are using Cloud SQL:
-
Open the
app.yamlfile for editing. -
Set the value of
cloudsql-instanceto the same value used for[CLOUDSQL_CONNECTION_NAME]in theconfig.pyfile. Use the formatproject:region:cloudsql-instance. Uncomment this entire line. -
Save and close the
app.yamlfile.
Installing dependencies
To create a virtual environment and install dependencies, use the following commands:
Linux/macOS
virtualenv -p python3 env
source env/bin/activate
pip install -r requirements.txt
Windows
virtualenv -p python3 env
env\scripts\activate
pip install -r requirements.txt
Running the app on your local machine
Start a local web server:
python main.pyIn your browser, enter the following address:
http://localhost:8080
Press Control+C to exit the worker and then the local web server.
Deploying the app to the App Engine flexible environment
Deploy the sample app:
gcloud app deployIn your browser, enter the following URL:
https://PROJECT_ID.REGION_ID.r.appspot.comReplace the following:
PROJECT_ID: Your Google Cloud project ID