Setting up on App Engine Flexible Environment

Stackdriver Error Reporting is automatically enabled for App Engine flexible environment applications. No additional setup is required. Errors written to stderr, which App Engine writes to, are analyzed and displayed by the Error Reporting service.

See Viewing Errors for instructions on viewing error and exception data for your application in the GCP Console.

Examples using the instrumentation libraries

If you'd like to customize the error information being sent to Error Reporting, you can use the instrumentation libraries available for a number of languages.

C#

Refer to the README for Stackdriver and App Engine Flexible Environment for instructions on running and deploying the Stackdriver sample application.

Google.Cloud.Diagnostics.AspNetCore is a .NET Core client library that enables error reporting for your application using the Logging API v2 and optionally the Error Reporting API v1beta1.

To use the Google.Cloud.Diagnostics.AspNetCore client library:

Right-click your solution in Visual Studio and select Manage Nuget packages for solution.

  1. Select the Include prerelease checkbox.

  2. Search for and install the package named Google.Cloud.Diagnostics.AspNetCore.

  3. Once the Google.Cloud.Diagnostics.AspNetCore client is installed, add the following using directive to your application's source code files when you want to customize the error information being sent to Error Reporting.

     using Google.Cloud.Diagnostics.AspNetCore;
    

Then complete the following 3 steps to log custom error reports from your application:

  1. Add the following code to your web application's appsettings.json file and update YOUR-GOOGLE-PROJECT-ID to be your project ID or number. Also update NAME-OF-YOUR-SERVICE and VERSION-OF-YOUR-SERVICE to appropriate values for your application:

    {
      "Stackdriver": {
        "ProjectId": "YOUR-GOOGLE-PROJECT-ID",
        "ServiceName": "NAME-OF-YOUR-SERVICE",
        "Version": "VERSION-OF-YOUR-SERVICE"
      }
    }

  2. Create or edit the ConfigureServices method in your application's Startup.cs file and call services.AddGoogleExceptionLogging():

            public void ConfigureServices(IServiceCollection services)
            {
                services.AddOptions();
                services.Configure<StackdriverOptions>(
                    Configuration.GetSection("Stackdriver"));
                services.AddGoogleExceptionLogging(options =>
                {
                    options.ProjectId = Configuration["Stackdriver:ProjectId"];
                    options.ServiceName = Configuration["Stackdriver:ServiceName"];
                    options.Version = Configuration["Stackdriver:Version"];
                });
    
                // Add trace service.
                services.AddGoogleTrace(options =>
                {
                    options.ProjectId = Configuration["Stackdriver:ProjectId"];
                    options.Options = TraceOptions.Create(
                        bufferOptions: BufferOptions.NoBuffer());
                });
    
                // Add framework services.
                services.AddMvc();
            }
    

  3. Edit the Configure method in your application's Startup.cs file and call app.UseGoogleExceptionLogging() before calling app.UseStaticFiles() and app.UseMvc().

            public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
            {
                // Configure logging service.
                loggerFactory.AddGoogle(Configuration["Stackdriver:ProjectId"]);
                var logger = loggerFactory.CreateLogger("testStackdriverLogging");
                // Write the log entry.
                logger.LogInformation("Stackdriver sample started. This is a log message.");
                // Configure error reporting service.
                app.UseGoogleExceptionLogging();
                // Configure trace service.
                app.UseGoogleTrace();
    
                app.UseStaticFiles();
    
                app.UseMvc(routes =>
                {
                    routes.MapRoute(
                        name: "default",
                        template: "{controller=Home}/{action=Index}/{id?}");
                });
            }
    

Now you can send customized error messages as shown in the following example:

throw new Exception("Generic exception for testing Stackdriver Error Reporting");

Go

See Setting Up Stackdriver Error Reporting for Go.

Java

See Setting Up Stackdriver Error Reporting for Java.

Node.js

See Setting Up Stackdriver Error Reporting for Node.js.

PHP

See Setting Up Stackdriver Error Reporting for PHP.

Python

See Setting Up Stackdriver Error Reporting for Python.

Ruby

See Setting Up Stackdriver Error Reporting for Ruby.

Send feedback about...

Stackdriver Error Reporting