Setting Up Stackdriver Debugger for Go

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.

GKE

  1. Make sure your cluster is created with one of the following access scopes:

    • https://www.googleapis.com/auth/cloud-platform
    • https://www.googleapis.com/auth/cloud_debugger

    Example:

    gcloud container clusters create EXAMPLE-CLUSTER-NAME \
        --scopes https://www.googleapis.com/auth/cloud-platform
    
  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:

    • https://www.googleapis.com/auth/cloud-platform
    • https://www.googleapis.com/auth/cloud_debugger
  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 the pre-built agent and make it executable:

    wget -O go-cloud-debug https://storage.googleapis.com/cloud-debugger/compute-go/go-cloud-debug
    chmod 0755 go-cloud-debug
    

  5. Start the agent and your program:

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

    Where:

    • 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 -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 only in the Kubernetes Engine and Compute Engine environments. It is not supported for local or other environments.

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

Send feedback about...

Stackdriver Debugger Documentation