Error Reporting lets you aggregate crashes and diagnose runtime exceptions from your Compute Engine applications. You can send error data by streaming logs to Cloud Logging or by calling the Error Reporting API directly. If you use Logging, then your log entries must follow the formatting requirements.
Using Logging to report errors
To connect your Compute Engine applications to Error Reporting, send your exceptions or other errors to Logging using one of the following agents:
Ops Agent
To set up Error Reporting to use the Ops Agent, complete the following steps:
Install the Ops Agent as is appropriate for your environment. For instructions, see Installing the Ops Agent.
Configure the Ops Agent to collect your application logs and format them properly.
For supported third-party application: The Ops Agent provides pre-configured logging receivers that automatically capture and parse log entries into structured formats Error Reporting recognizes. For information about the supported third-party applications, see Monitoring third-party applications.
For custom applications: Configure a logging receiver to specify your log file locations, and pair it with one of the following processors:
- Use a
parse_multilineprocessor if your app writes plain text stack traces across multiple lines. - Use a
parse_jsonprocessor if your app writes logs as JSON strings.
For detailed instructions, see Configure the Ops Agent.
- Use a
If your application does not generate standard stack traces, modify your application so that it logs exceptions and their stack traces to Cloud Logging.
You must include all the information for a single error or exception in the same log entry, including all the frames of any stack trace. If all the information isn't together, then Error Reporting might not detect the error. You can use the structured JSON format for your log entry payloads to include different kinds of information for each error.
Legacy Logging agent
To set up Error Reporting to use the legacy Logging agent, complete the following steps:
- Install the Logging
google-fluentdagent as is appropriate for your environment. For instructions, see Installing the Logging agent. Modify your application so that it logs exceptions and their stack traces to Logging.
You must include all the information for a single error or exception in the same log entry, including all the frames of any stack trace. If all the information isn't together, then Error Reporting might not detect the error. You can use the structured JSON format for your log entry payloads to include different kinds of information for each error.
Java
Add the following to your pom.xml file:
Then use code like the following to send the exception data:
Python
First, install the
fluent-logger-python library:
sudo pip install fluent-logger
Then use code like the following to send the exception data:
Node.js
First, install the
fluent-logger-node library:
npm install fluent-logger
Then use code like the following to send the exception data:
Go
First, install the
fluent-logger-golang package:
go get github.com/fluent/fluent-logger-golang/
Then use code like the following to send error data:
Using the Error Reporting API to write errors
The Error Reporting API provides a report endpoint for writing
error information to the service.
Enable the Error Reporting API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.Report errors to the API using either the REST API or a client library.
Samples
ASP.NET
The ASP.NET NuGet package reports uncaught exceptions from ASP.NET web applications to Error Reporting.
Install the NuGet package
To install the Stackdriver ASP.NET NuGet package in Visual Studio:
- Right-click your solution and select Manage NuGet packages for solution.
- Select the Include prerelease checkbox.
- Search for and install the package named
Google.Cloud.Diagnostics.AspNet.
Usage
Once you've installed the Stackdriver ASP.NET NuGet package, add the following statement to your application code to start sending errors to Stackdriver:
using Google.Cloud.Diagnostics.AspNet;
Add the following HttpConfiguration code to the Register method of your
.NET web app after replacing your-project-id with your actual
project ID
to enable the reporting of exceptions:
Once you've added this method to your ASP.NET application, you can view any uncaught exceptions that occur as they get reported to Google Cloud in the Error Reporting section of the Google Cloud console.
C#
The following example can be found in the GoogleCloudPlatform/dotnet-docs-samples repository. To use it, after building the project, specify your project ID:
C:\...\bin\Debug> set GOOGLE_PROJECT_ID=[YOUR_PROJECT_ID]
Make sure to replace [YOUR_PROJECT_ID] with the correct value from the
Google Cloud console.
Then, send exception data with code similar to the following:
Go
Java
Node.js
Ruby
Python
PHP
View error groups
In the Google Cloud console, go to the Error Reporting page:
You can also find this page by using the search bar.