Setting up Cloud Trace for C# ASP.NET

You can enable Cloud Trace for ASP.NET Framework applications by using the Google.Cloud.Diagnostics.AspNet client library for C#.

In this page you will find general information on how to enable and configure Trace in Google Cloud. For examples on how to configure and use the Google.Cloud.Diagnostics.AspNet client library, see Google.Cloud.Diagnostics.AspNet reference docs.

Configure your platform

You can use Cloud Trace on Google Cloud and other platforms.

Running on Google Cloud

When your application is running on Google Cloud, you don't need to provide authentication credentials in the form of a service account to the client library. However, you do need to ensure that your Google Cloud platform has the Cloud Trace API access scope enabled.

For the following configurations, the default access-scope settings enable the Cloud Trace API:

  • App Engine flexible environment
  • Google Kubernetes Engine (GKE)

  • Compute Engine

If you use custom access scopes, then you must ensure that Cloud Trace API access scope is enabled. For gcloud users, specify access scopes using the --scopes flag and include the trace.append Cloud Trace API access scope. For example, to create a GKE cluster with only the Cloud Trace API enabled, do the following:

gcloud container clusters create example-cluster-name --scopes=

Running locally and elsewhere

If your application is running outside of Google Cloud, then you must provide authentication credentials in the form of a service account to the client library. The service account must contain the Cloud Trace agent role. For instructions, see Creating a service account.

Google Cloud client libraries use Application Default Credentials (ADC) to find your application's credentials. You provide these credentials by setting the GOOGLE_APPLICATION_CREDENTIALS environment variable:


    export GOOGLE_APPLICATION_CREDENTIALS=path-to-your-service-accounts-private-key


    set GOOGLE_APPLICATION_CREDENTIALS=path-to-your-service-accounts-private-key



Viewing the traces

After deployment, you can view the traces in the Cloud Console Trace Viewer.

Go to the Trace Viewer page


For information on troubleshooting issues with Cloud Trace, go to the Troubleshooting page.