Error Reporting API - Module Google::Cloud::ErrorReporting (v0.42.3)

Reference documentation and code samples for the Error Reporting API module Google::Cloud::ErrorReporting.

Error Reporting

Error Reporting counts, analyzes and aggregates the crashes in your running cloud services.

See Error Reporting Overview.

Methods

.configure

def self.configure() -> Google::Cloud::Config

Configure the default Project client, allows the ErrorReporting.report public method to reuse these configured parameters.

The following ErrorReporting configuration parameters are supported:

  • project_id - (String) Google Cloud Platform project identifier for the Error Reporting service you are connecting to. (The parameter project is considered deprecated, but may also be used.)
  • credentials - (String, Hash, Google::Auth::Credentials) The path to the keyfile as a String, the contents of the keyfile as a Hash, or a Google::Auth::Credentials object. (See Credentials) (The parameter keyfile is considered deprecated, but may also be used.)
  • scope - (String, Array
  • quota_project - (String) The project ID for a project that can be used by client libraries for quota and billing purposes.
  • timeout - (Integer) Default timeout to use in requests.
  • endpoint - (String) Override of the endpoint host name, or nil to use the default endpoint.
  • service_name - (String) Name for the application.
  • service_version - (String) Version identifier for the application.
  • ignore_classes - (Array
  • on_error - (Proc) A Proc to be run when an error is encountered on a background thread, such as ErrorReporting.report or Middleware. The Proc must take the error object as the single argument. If ErrorReporting is being used to report errors using Google::Cloud::cofigure.on_error, then this on_error should be configured to report errors raised when reporting through ErrorReporting.

See the Configuration Guide for full configuration parameters.

Yields
  • (Google::Cloud.configure.error_reporting)
Returns
  • (Google::Cloud::Config) — The configuration object the Google::Cloud::ErrorReporting module uses.
Example
# in app.rb
require "google/cloud/error_reporting"

Google::Cloud::ErrorReporting.configure do |config|
  config.project_id = "my-project"
  config.credentials = "/path/to/keyfile.json"
  config.service_name = "my-service"
  config.service_version = "v8"
end

begin
  fail "boom"
rescue => exception
  # Report exception using configuration parameters provided above
  Google::Cloud::ErrorReporting.report exception
end

.default_reporter

def self.default_reporter(&block) -> #report

Returns the global default reporter used by middleware and the ErrorReporting.report convenience method.

If the default reporter is already defined, returns it. Otherwise, if a block is given, it is called and the result is set as the default reporter. Otherwise, if no block is given, a reporter is constructed from the default project and credentials.

Returns
  • (#report)

.new

def self.new(project_id: nil, credentials: nil, scope: nil, timeout: nil, endpoint: nil, project: nil, keyfile: nil) -> Google::Cloud::ErrorReporting::Project

Creates a new object for connecting to the Error Reporting service. Each call creates a new connection.

For more information on connecting to Google Cloud see the Authentication Guide.

Parameters
  • project_id (String) (defaults to: nil) — Google Cloud Platform project identifier for the Error Reporting service you are connecting to. If not present, the default project for the credentials is used.
  • credentials (String, Hash, Google::Auth::Credentials) (defaults to: nil) — The path to the keyfile as a String, the contents of the keyfile as a Hash, or a Google::Auth::Credentials object. (See Credentials)
  • scope (String, Array<String>) (defaults to: nil)

    The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs.

    The default scope is:

    • https://www.googleapis.com/auth/cloud-platform
  • timeout (Integer) (defaults to: nil) — Default timeout to use in requests. Optional.
  • endpoint (String) (defaults to: nil) — Override of the endpoint host name. Optional. If the param is nil, uses the default endpoint.
  • project (String) (defaults to: nil) — Alias for the project_id argument. Deprecated.
  • keyfile (String) (defaults to: nil) — Alias for the credentials argument. Deprecated.
Example
require "google/cloud/error_reporting"

error_reporting = Google::Cloud::ErrorReporting.new
# ...

.report

def self.report(exception, service_name: nil, service_version: nil)

Provides an easy-to-use interface to Report a Ruby exception object to Error Reporting service. This method helps users to transform the Ruby exception into an Error Reporting ErrorEvent gRPC structure, so users don't need to. This should be the prefered method to use when users wish to report captured exception in applications.

This public method creates a default Error Reporting client and reuse that between calls. The default client is initialized with parameters defined in ErrorReporting.configure.

The error event can be customized before reporting. See the example below and ErrorEvent class for avaiable error event fields.

Parameters
  • exception (Exception) — The captured Ruby Exception object
  • service_name (String) (defaults to: nil) — An identifier for running service. Optional.
  • service_version (String) (defaults to: nil) — A version identifier for running service.
Yields
  • (error_event)
Examples

Basic usage

# in app.rb
require "google/cloud/error_reporting"

begin
  fail "boom"
rescue => exception
  # Report exception using configuration parameters provided above
  Google::Cloud::ErrorReporting.report exception
end

The error event can be customized if needed

require "google/cloud/error_reporting"

begin
  fail "boom"
rescue => exception
  Google::Cloud::ErrorReporting.report exception do |error_event|
    error_event.user = "johndoh@example.com"
    error_event.http_status = "502"
  end
end

Constants

VERSION

value: "0.42.3".freeze