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.
This section uses code in the 5-logging directory. Edit the files
and run commands in this directory.
config.py file for editing and replace the
following values:[PROJECT_ID] to your project ID, which
is visible in the Google Cloud console.
[DATA_BACKEND] to the same value you used
during the
Using structured data
tutorial.
Cloud SQL or Mongo section to the
same values you used during the Using structured data step.
[CLOUD_STORAGE_BUCKET] to your
Cloud Storage bucket name.
Under the OAuth2 configuration section, set the values
of [GOOGLE_OAUTH2_CLIENT_ID] and
[GOOGLE_OAUTH2_CLIENT_SECRET] to the application client
ID and secret that you created previously.
config.py file.
If you are using Cloud SQL:
app.yaml file for editing.
cloudsql-instance to the same value used for
[CLOUDSQL_CONNECTION_NAME] in the config.py
file. Use the format project:region:cloudsql-instance.
Uncomment this entire line.
app.yaml file.
To create a virtual environment and install dependencies, use the following commands:
virtualenv -p python3 env
source env/bin/activate
pip install -r requirements.txt
virtualenv -p python3 env
env\scripts\activate
pip install -r requirements.txt
Start a local web server:
python main.py
In your browser, enter the following address:
http://localhost:8080
Press Control+C to exit the worker and then the local web server.
Deploy the sample app:
gcloud app deploy
In your browser, enter the following URL:
https://PROJECT_ID.REGION_ID.r.appspot.com
Replace the following:
PROJECT_ID: Your Google Cloud project IDREGION_ID: A code that App Engine assigns
to your app If you update your app, you deploy the updated version by entering the same command that you used to deploy the app. The deployment creates a new version of your app and promotes it to the default version. The earlier versions of your app remain, as do their associated virtual machine (VM) instances. All of these app versions and VM instances are billable resources. To reduce costs, delete the non-default versions of your app.
To delete an app version:
For more information about cleaning up billable resources, see the Cleaning up section in the final step of this tutorial.
To see Error Reporting in action, intentionally introduce a mistake in your code, and then look for the exception in the Google Cloud console's Error Reporting page.
In bookshelf/crud.py, add an operation that accesses an undefined variable
and generates a ReferenceError in the index view.
@crud.route("/") def list(): x[3]
Deploy the app.
gcloud app deploy
Access the index page.
gcloud app browse
You can view the message An internal error occurred.
In the Google Cloud console, go to the Error Reporting page:
You can also find this page by using the search bar.
You can see the error listed.
Click the error to see information about the error, such as when the error was last seen,the number of times the error occurred, a histogram of occurrence times, and the stack trace.
To report uncaught exceptions, the code first uses the Flask errorhandler
decorator, and then reports the exception to Error Reporting by using
the
Cloud Client Libraries for Python.
The client automatically adds the traceback info and uses a helper function to
extract the relevant request details from the Flask request, which populates
Error Reporting with the relevant stack traces and HTTP contexts for any
uncaught InternalServerError HTTP 500 exception in your app.
To avoid incurring charges to your Google Cloud account for the resources used in this tutorial, either delete the project that contains the resources, or keep the project and delete the individual resources.
The easiest way to eliminate billing is to delete the project that you created for the tutorial.
To delete the project:
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-11-10 UTC.