Setting Up Stackdriver Debugger for .NET Core

This page describes how to configure your environment and your .NET Core 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.

Before You Begin

  • To use Stackdriver Debugger while running your application locally:

    • Set the GOOGLE_APPLICATION_CREDENTIALS environment variable to point to service account json full file path.
    • Set the STACKDRIVER_DEBUGGER_MODULE the environment variable to the name of component being debugged. This module name will appear in the GCP Console list of modules allowed to be debugged.
    • Set STACKDRIVER_DEBUGGER_VERSION environment variable to the logical version of the module being debugged. This allows debugging multiple logical versions of the module in GCP Console.
    • Set STACKDRIVER_DEBUGGER_DEBUGGER environment variable to point to a location of the Stackdriver Debugger binary.
    • If running on Linux, set LD_LIBRARY_PATH environment variable to include Stackdriver Debugger directory.
  • When building the .NET Core application, include and deploy PDB files with your code. Include the following lines in each PDB file:

    <PropertyGroup>
      <TargetFramework>netcoreapp2.1</TargetFramework>
      <DebugType>portable</DebugType>
    </PropertyGroup>
    
  • Note that when debugging a Release build, variables might be misnamed or missing.

  • To begin using Debugger, ensure the Debugger API is enabled.
    Enable Debugger API

App Engine standard environment

The Stackdriver Debugger agent for .NET Core isn't supported in App Engine standard environment.

App Engine flexible environment

  1. Change the runtime in your app.yaml to custom:

    runtime: custom
    env: flex
    
  2. Use a custom Dockerfile:

    FROM gcr.io/dotnet-debugger/aspnetcore:2.0
    COPY . /app
    WORKDIR /app
    
    # If you don't have source context delete the below line.
    # See 'Selecting source code automatically' below for more information.
    COPY ./source-context.json /usr/share/dotnet-debugger/agent/
    ENTRYPOINT ["/usr/share/dotnet-debugger/start-debugger.sh", "dotnet", "APPLICATION.dll"]
    

    Where:

    • APPLICATION is the binary you wish to run and debug.

The Stackdriver Debugger is now ready for use with your application.

To have the Debug page in the GCP Console automatically display source code matching the deployed application, see Selecting source code automatically.

Google Kubernetes Engine

GCLOUD

To enable Debugger using gcloud, complete the following steps:

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

    • https://www.googleapis.com/auth/cloud-platform grants your cluster access to all Google Cloud Platform APIs.

    • https://www.googleapis.com/auth/cloud_debugger grants your cluster access to only the Debugger API. Use this access scope to harden your cluster's security.

    gcloud container clusters create example-cluster-name \
           --scopes=https://www.googleapis.com/auth/cloud_debugger
    
  2. Add the following lines to your Dockerfile to add the Debugger agent to your containerized app:

    FROM gcr.io/dotnet-debugger/aspnetcore:2.0
    COPY . /app
    WORKDIR /app
    # If you don't have the source-context.json file, delete the `COPY` line below.
    # See running locally below for more information.
    COPY ./source-context.json /usr/share/dotnet-debugger/agent/
    
    ENV STACKDRIVER_DEBUGGER_MODULE=MODULE
    ENV STACKDRIVER_DEBUGGER_VERSION=VERSION
    
    # If not running on Google Cloud Platform, uncomment and set the following:
    # ENV GOOGLE_APPLICATION_CREDENTIALS=CREDENTIALS_FILE
    ENTRYPOINT ["/usr/share/dotnet-debugger/start-debugger.sh", "dotnet", "APPLICATION.dll"]
    

    Where:

    • source-context.json is the JSON-formatted file containing your source context configuration. See Selecting source code automatically for information on generating this file.

    • MODULE is the name of the application. Together with version, it identifies the application in the GCP Console. Examples: MyApp,Backend, or Frontend.

    • VERSION is the application version (e.g., the build ID). The GCP Console displays the running application as MODULE - VERSION. Examples: v1.0, build_147, or v20160520.

    • CREDENTIALS_FILE is the path to the service account credentials JSON file.

    • APPLICATION is the entry point to the .NET Core application being run with Debugger attached.

The debugger is now ready for use when you deploy your containerized app.

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

CONSOLE

To enable Debugger using the console, complete the following steps:

  1. After selecting your cluster type, click More options from the Node pools pane:

    Node pools options

  2. Select one of the following from the Security pane:

    • Allow full access to all Cloud APIs.

    • Allow access for each API and then select Enabled for Cloud Debugger.

The debugger is now ready for use with your application.

To have the Debug page in the GCP Console automatically display source code matching the deployed application, see Selecting source code automatically.

Compute Engine

The Stackdriver Debugger agent for .NET Core isn't supported in Compute Engine environment.

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

Send feedback about...

Stackdriver Debugger Documentation