Setting up Stackdriver Debugger for Go

This page describes how to configure your environment and your Go application to use Stackdriver Debugger. For some environments, you must explicitly specify the access scope to let the Stackdriver Debugger agent send data. We recommend setting the broadest possible access scope and then using Cloud Identity and Access Management to restrict access. In keeping with this best practice, set the access scope to be all Cloud APIs with the option cloud-platform.

App Engine standard environment

The Stackdriver Debugger agent for Go is not supported in App Engine standard environment yet.

App Engine flexible environment

The Stackdriver Debugger agent for Go is not supported in App Engine flexible environment yet.

Google Kubernetes Engine

  1. Create your cluster, with one of the following access scopes:

    To create a cluster using gcloud, do the following:

    1. (Optional) Update gcloud to the latest version:
      gcloud components update
    2. Set your default project ID:
      gcloud config set project [PROJECT_ID]
    3. If you're working with zonal clusters, set your default compute zone:
      gcloud config set compute/zone [COMPUTE_ZONE]
    4. If you're working with regional clusters, set your default compute region:
      gcloud config set compute/region [COMPUTE_REGION]
    5. Issue the create command:
      gcloud container clusters create example-cluster-name --scopes

    For more detailed information on creating a cluster, see Creating a cluster.

  2. Follow the instructions for Compute Engine.

Compute Engine

  1. Make sure your Compute Engine VM instances are running a 64-bit Debian Linux image.

  2. Make sure your Compute Engine VM instances are created with the access scope option Allow full access to all Cloud APIs, or have one of the following access scopes:

  3. The current Go compiler's optimizations interfere with accurate debugging. As a result, Stackdriver Debugger shows incorrect information about your application when your application is built with the default Go compiler optimizations.

    To get the correct debugging information, build your application without the default optimizations. The following sample commands demonstrate how to disable optimizations when using go1.10 or a later version:

    go build -gcflags=all='-N -l'

    The preceding gcflags value includes -N to disable optimizations and -l to disable inlining.

  4. Download the debugger agent.

    The Stackdriver Debugger agent is a light-weight binary that you enable for your application at startup. The agent starts with your application and communicates with the Stackdriver Debugger backend while the application is running.

    Once you've built and deployed your Compute Engine application, download and install the debug agent:

    go get -u
  5. Start the agent and your program:

    go-cloud-debug-agent -sourcecontext=[PATH_TO_FILE] -appmodule=[APP_NAME] \
                     -appversion=[APP_VERSION] -- [PATH_TO_BINARY] [ARG1] [ARG2]


    • PATH_TO_FILE specifies the relative path to the JSON-formatted file containing your source context configuration. See Selecting Source Code Automatically for information on generating this file.

    • APP_NAME is the name of your application or service. This, along with the version, is used to identify your application in the GCP Console.

    • APP_VERSION is an application-supplied version marker. For example, you could use a build number. The GCP Console displays the running version as module - version. For example, main - 1.0.

    • PATH_TO_BINARY specifies the relative path to your application binary.

    • ARG1 and ARG2 are placeholders for any additional arguments that your application requires.

    For example:

    go-cloud-debug-agent -appmodule=main -appversion=1.0 -- bin/my-app my-arg

The debugger is now ready for use with your app.

To have the Debug page in the GCP Console automatically display source code matching the deployed app, see Selecting Source Code Automatically.

Local and elsewhere

The Stackdriver Debugger agent for Go is supported for local or other environments that use Go 1.9 and earlier.

Was this page helpful? Let us know how we did:

Send feedback about...

Stackdriver Debugger Documentation