You have been tasked with deploying your team’s application to App Engine, as a proof-of-concept demo for Platform-as-a-Service technologies that you will present to the rest of your organisation. The app will work just great — most of the time. For some reason, it also seems to return an internal server error, although you can’t see any bugs in your code when you run the app locally. In this lab, we will use GCP Error Reporting to see live errors and stack traces from our deployed application, to identify where the error is occurring.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Deploy the Demo Application
Under "APIs & Services," "Library," search for "Cloud Build API." Click "ENABLE" to enable the Cloud Build API.
Inside the GCP console, click the Activate Cloud Shell icon.
Clone the Git repo from GitHub.
From the
appengine-buggy
directory inside the repo, deploy the application to App Engine.You will be asked to choose a region for deployment (select us-east1), then confirm the details to create the application. When the command completes you should be able to see the URL of your deployed app.
Visit the application in your browser. Did it work? Keep reloading the page until it breaks.
- Use Cloud Error Reporting
View your application’s errors in the GCP console. You can find application errors in the App Engine dashboard, or in the Error Reporting section (under Operations in the GCP menu).
The variable
sample_text
is sometimes not set because of theif random_value
condition. You can see the stack trace of this error, along with all of its occurrences, as a single Error in Error Reporting.- Fix the Application and Redeploy
Remove the
if
condition on line 21 ofmain.py
so thatsample_text
is always set. Make sure you correct the indentation on the following line. You should probably change the text as well, so that it no longer claims to fail some of the time!Redeploy the application to App Engine, and test that your change has solved the problem by reloading the app several times.
You can now mark the Error as resolved in Error Reporting.