Quickstart using App Engine

This quickstart introduces you to Stackdriver Error Reporting and shows you how to do the following:

  • Deploy a Python App Engine application by using Cloud Shell.
  • View an error in your application using Error Reporting.
  • Configure Error Reporting to send notifications.

Try the 3-minute interactive tutorial in the Google Cloud Console.
(Click Start in the Stackdriver Error Reporting Introduction column.)

Before you begin

  1. 登入您的 Google 帳戶。


  2. 在 GCP Console 的專案選擇器頁面中,選取或建立 GCP 專案。


  3. 請確認您已啟用 Google Cloud Platform 專案的計費功能。瞭解如何確認您已啟用專案的計費功能

  4. Open a Cloud Shell for your project. While it starts, the message Connecting is displayed.

    Open Cloud Shell.

Getting started

In this section, you download and deploy an application to App Engine:

  1. Download and configure the application from the GitHub project python-docs-samples:

    1. Clone the project to your Cloud Shell:

      git clone https://github.com/GoogleCloudPlatform/python-docs-samples

      Git returns a message similar to this:

      git clone https://github.com/GoogleCloudPlatform/python-docs-samples
      Cloning into 'python-docs-samples'...
    2. Create an isolated Python environment and activate it:

      cd python-docs-samples/appengine/standard_python37/hello_world
      virtualenv env -p python3
      source env/bin/activate
    3. Install dependencies:

      pip install -r requirements.txt
  2. Verify that the application installation and configuration are successful:

    1. Run the application:

      python main.py
    2. To view the application on a local web page, click the link displayed in Cloud Shell. The web page displays Hello World!.

    3. To stop your running application, in Cloud Shell enter Ctrl-C.

  3. Upload your application to App Engine:

    gcloud app deploy

    If prompted for a deployment region, select one near you. Enter Y when asked if you want to continue. After a few moments, the upload is complete.

  4. View your application in a browser by running the following command in Cloud Shell:

    gcloud app browse

    If the Cloud SDK can't find your browser, the previous command displays an error message and a link. Click the displayed link. The message Hello, World! is displayed in the browser.

Introduce an error

In the next steps, you create an error that Error Reporting catches and displays:

  1. Edit main.py and change

    return 'Hello World!


    return 'Hello World!' + 1000

    When executed, this change causes a Python TypeError exception because it is illegal to concatenate a string and an integer.

  2. Upload the modified application to App Engine:

    gcloud app deploy
  3. Return to the browser tab containing the running application, and reload the page. Because of your change, instead of the page displaying Hello, World!, it displays an error message:

    Internal Server Error
    The server encountered an internal error and was unable to complete your
    request. Either the server is overloaded or there is an error in the

    If you don't see this message, wait a minute and reload it again. It might take a few moments before the new version is activated.

View the error in Error Reporting

The error message displayed in the web page isn't that useful because it doesn't provide enough details to resolve the issue. However, if you use Error Reporting, you can get detailed information about the error and the number of times it has occurred:

  1. Go to Error Reporting:

    Go to Error Reporting

    The Error Reporting dashboard displays a summary of each error found and the number of occurrences of each error. By default, Error Reporting automatically reloads the error list every 5 seconds, but to force an immediate reload click Auto reload.

    For this quickstart, the dashboard displays one error with the description "TypeError: can only concatenate str (not "int") to str". You may have to wait a minute and refresh the page to see the error:

    The user interface showing the test error.

  2. Generate the same error again by reloading the application in your browser.

    Because the stack trace of the new error is similar to the first error, Error Reporting batches them together by updating the number of Occurrences and the time graph:

    The user interface showing batched occurences of
   the test error.

  3. To view the error details page, which contains all of the available information about an error, including links to the source code, click the error name:

    The user interface showing the
     test error details page.

Configure notifications

You can configure Error Reporting to notify you when a new type of error arrives. Notifications aren't sent when there are new occurrences of existing errors:

  1. Go to Error Reporting:

    Go to Error Reporting

  2. To enable email notifications, click More and select Turn on new error notifications for project from the drop-down list.

  3. In main.py, change

    return 'Hello World!` + 1000


    return 'Hello World!'.punctuate()

    When executed, this change causes a Python AttributeError exception because the attribute punctuate() doesn't exist.

  4. Upload the modified file to App Engine:

    gcloud app deploy
  5. Generate the new error by reloading the application in your browser.

    • The browser displays the message Internal Server Error.

    • The Error Reporting dashboard displays an error with the description "AttributeError: 'str' object has no attribute 'punctuate'.

    • Your email includes a new Stackdriver notification that contains details about the error, including the:

      • Project ID
      • An error description, in this case, it includes "AttributeError: 'str' object has no attribute 'punctuate'
      • Service
      • Application version

Clean up

To avoid incurring charges to your Google Cloud account for the resources used in this quickstart, follow these steps.

  1. 前往 GCP Console 中的「Manage resources」(管理資源) 頁面。

    前往「Manage resources」(管理資源) 頁面

  2. 在專案清單中選取您要刪除的專案,然後按一下「Delete」(刪除) 圖示
  3. 在對話方塊中輸入專案 ID,然後按一下 [Shut down] (關閉) 以刪除專案。

What's next



Stackdriver Error Reporting