Error Reporting client libraries

Stay organized with collections Save and categorize content based on your preferences.

This page shows how to get started with the Cloud Client Libraries for the Error Reporting API. Read more about the client libraries for Cloud APIs, including the older Google API Client Libraries, in Client Libraries Explained.

Install the client library


For more information, see Setting Up a C# Development Environment.

Install-Package Google.Cloud.ErrorReporting.V1Beta1 -pre


For more information, see Setting Up a Go Development Environment.

go get


For more information, see Setting Up a Java Development Environment.

If you are using Maven, add the following to your pom.xml file. For more information about BOMs, see The Google Cloud Platform Libraries BOM.


If you are using Gradle, add the following to your dependencies:

implementation ''

If you are using sbt, add the following to your dependencies:

libraryDependencies += "" % "google-cloud-errorreporting" % "0.126.0-beta"

If you're using Visual Studio Code, IntelliJ, or Eclipse, you can add client libraries to your project using the following IDE plugins:

The plugins provide additional functionality, such as key management for service accounts. Refer to each plugin's documentation for details.


For more information, see Setting Up a Node.js Development Environment.

npm install --save @google-cloud/error-reporting


For more information, see Using PHP on Google Cloud.

composer require google/cloud-error-reporting


For more information, see Setting Up a Python Development Environment.

pip install --upgrade google-cloud-error-reporting


For more information, see Setting Up a Ruby Development Environment.

gem install google-cloud-error_reporting

Set up authentication

When you use client libraries, you use Application Default Credentials (ADC) to authenticate. For information about setting up ADC, see Provide credentials for Application Default Credentials. For information about using ADC with client libraries, see Authenticate using client libraries.

Use the client library

The following example shows how to use the client library.


using Google.Api.Gax.ResourceNames;
using Google.Cloud.ErrorReporting.V1Beta1;
using System;

public class ErrorReportingSample
    public static void Main(string[] args)
            throw new Exception("Generic exception for testing Stackdriver Error Reporting");
        catch (Exception e)
            Console.WriteLine("Stackdriver Error Report Sent");

    /// <summary>
    /// Report an exception to the Error Reporting service.
    /// </summary>
    private static void report(Exception e)
        // Create the report and execute the request.
        var reporter = ReportErrorsServiceClient.Create();

        // Get the project ID from the environement variables.
        var projectName = new ProjectName(

        // Add a service context to the report. For more details see:
        ServiceContext serviceContext = new ServiceContext()
            Service = "myapp",
            Version = "1.1",
        ReportedErrorEvent errorEvent = new ReportedErrorEvent()
            Message = e.ToString(),
            ServiceContext = serviceContext,
        reporter.ReportErrorEvent(projectName, errorEvent);


// Sample errorreporting_quickstart contains is a quickstart
// example for the Google Cloud Error Reporting API.
package main

import (


var errorClient *errorreporting.Client

func main() {
	ctx := context.Background()

	// Sets your Google Cloud Platform project ID.
	projectID := "YOUR_PROJECT_ID"

	var err error
	errorClient, err = errorreporting.NewClient(ctx, projectID, errorreporting.Config{
		ServiceName: "myservice",
		OnError: func(err error) {
			log.Printf("Could not log error: %v", err)
	if err != nil {
	defer errorClient.Close()

	resp, err := http.Get("not-a-valid-url")
	if err != nil {

func logAndPrintError(err error) {
		Error: err,



 * Snippet demonstrates using the Error Reporting API to report a custom error event.
 * <p>This library is not required on App Engine, errors written to stderr are automatically written
 * to Error Reporting. It is also not required if you are writing logs to Cloud Logging. Errors
 * written to Cloud Logging that contain an exception or stack trace are automatically written out
 * to Error Reporting.
public class QuickStart {
  public static void main(String[] args) throws Exception {

    // Google Cloud Platform Project ID
    String projectId = (args.length > 0) ? args[0] : ServiceOptions.getDefaultProjectId();
    ProjectName projectName = ProjectName.of(projectId);

    // Instantiate an Error Reporting Client
    try (ReportErrorsServiceClient reportErrorsServiceClient = ReportErrorsServiceClient.create()) {

      // Custom error events require an error reporting location as well.
      ErrorContext errorContext =

      // Report a custom error event
      ReportedErrorEvent customErrorEvent =
              .setMessage("custom error event")
      // Report an event synchronously, use .reportErrorEventCallable for asynchronous reporting.
      reportErrorsServiceClient.reportErrorEvent(projectName, customErrorEvent);


// Imports the Google Cloud client library
const {ErrorReporting} = require('@google-cloud/error-reporting');

// Instantiates a client
const errors = new ErrorReporting();

// Reports a simple error'Something broke!');


// Imports the Cloud Client Library
use Google\Cloud\ErrorReporting\Bootstrap;
use Google\Cloud\Logging\LoggingClient;
use Google\Cloud\Core\Report\SimpleMetadataProvider;

// These variables are set by the App Engine environment. To test locally,
// ensure these are set or manually change their values.
$projectId = getenv('GCLOUD_PROJECT') ?: 'YOUR_PROJECT_ID';
$service = getenv('GAE_SERVICE') ?: 'error_reporting_quickstart';
$version = getenv('GAE_VERSION') ?: 'test';

// Instantiates a client
$logging = new LoggingClient([
    'projectId' => $projectId,
// Set the projectId, service, and version via the SimpleMetadataProvider
$metadata = new SimpleMetadataProvider([], $projectId, $service, $version);
// Create a PSR-3 compliant logger
$psrLogger = $logging->psrLogger('error-log', [
    'metadataProvider' => $metadata,
// Using the Error Reporting Bootstrap class, register your PSR logger as a PHP
// exception hander. This will ensure all exceptions are logged to Stackdriver.

print('Throwing a test exception. You can view the message at' . PHP_EOL);
throw new Exception('quickstart.php test exception');


def simulate_error():
    from import error_reporting

    client = error_reporting.Client()
        # simulate calling a method that's not defined
        raise NameError
    except Exception:


require "google/cloud/error_reporting"

  raise "Raise an exception for Error Reporting."
rescue StandardError => e e

Additional resources