Selecting source code automatically

Stackdriver Debugger uses source context information to display the correct version of your source code on the Debug page. The source context information is captured in a source-context.json file, which is generated from a Git repository and deployed with your application.

Before you begin

Setup on Google Cloud

Follow the steps below to select your source code automatically:

Java

App Engine standard environment

No additional setup. When you deploy your app, a WEB-INF/classes/source-context.json file is automatically generated and uploaded with your application.

App Engine flexible environment, Compute Engine, GKE, and Cloud Run

  1. Commit your latest changes.
  2. Run the following in the root directory of your local Git repository:
  3. gcloud debug source gen-repo-info-file --output-directory="WEB-INF/classes/"
  4. Deploy (or redeploy) your app from the Git repository, including the source-context.json file.

The correct version of your source code now appears automatically on the Debugger page.

Python

App Engine standard environment

No additional setup. Verify that Deployed files is selected in the Debugger panel.

App Engine flexible environment, Compute Engine, GKE, and Cloud Run

  1. Commit your latest changes.
  2. Run the following in the root directory of your local Git repository:
  3. gcloud debug source gen-repo-info-file --output-directory=[MODULE_PACKAGE_DIR]

    [MODULE_PACKAGE_DIR] is the top level of your app directory.

  4. Deploy (or redeploy) your app from the Git repository, including the source-context.json file.

The correct version of your source code now appears automatically on the Debugger page.

Node.js

App Engine standard environment

No additional setup. Verify that Deployed files is selected in the Debugger panel.

App Engine flexible environment, Compute Engine, GKE, and Cloud Run

  1. Commit your latest changes.
  2. Run the following in the root directory of your local Git repository:
  3. gcloud debug source gen-repo-info-file --output-directory=[MODULE_PACKAGE_DIR]

    [MODULE_PACKAGE_DIR] is the top level of your app directory.

  4. Deploy (or redeploy) your app from the Git repository, including the source-context.json file.

The correct version of your source code now appears automatically on the Debugger page.

.Net Core

  1. Commit your latest changes.
  2. Run the following in the root directory of your local Git repository:
  3. gcloud debug source gen-repo-info-file --output-directory=[MODULE_PACKAGE_DIR]

    [MODULE_PACKAGE_DIR] is the top level of your app directory.

  4. Deploy (or redeploy) your app from the Git repository, including the source-context.json file.

The correct version of your source code now appears automatically on the Debugger page.

Example workflow and folder structure

To generate the source-context.json file, perform the following steps:

  1. Commit your latest changes:

    git commit -m "Commit message"
    
  2. Generate the source-context.json file by running the following command from the app's root directory:

    gcloud debug source gen-repo-info-file --output-directory=path/to/app/source-code
    
  3. Verify that the source-context.json file is colocated with the app's source code. Your folder structure should be similar to the following:

    App-directory/
      main.py
      app.yaml
      source-context.json
    
Bu sayfayı yararlı buldunuz mu? Lütfen görüşünüzü bildirin:

Şunun hakkında geri bildirim gönderin...

Stackdriver Debugger