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

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

Project

Projects are top-level containers in Google Cloud Platform. They store information about billing and authorized users, and they control access to Error Reporting. Each project has a friendly name and a unique ID. Projects can be created only in the Google Developers Console.

See new

Inherits

  • Object

Example

require "google/cloud/error_reporting"

error_reporting = Google::Cloud::ErrorReporting.new
error_event = error_reporting.error_event "Error with Backtrace",
                                          event_time: Time.now,
                                          service_name: "my_app_name"
error_reporting.report error_event

Methods

.default_project

def self.default_project() -> String

Find default project_id from the configuration, environment varaibles, or query from GCE meta service.

Returns
  • (String) — default valid GCP project_id

.default_project_id

def self.default_project_id() -> String

Find default project_id from the configuration, environment varaibles, or query from GCE meta service.

Returns
  • (String) — default valid GCP project_id

.default_service_name

def self.default_service_name() -> String

Find default service_name from the configuration, environment varaibles, or query from GCE meta service, or just "ruby".

Returns
  • (String) — default GCP service_name

.default_service_version

def self.default_service_version() -> String

Find default service_version from the configuration, environment varaibles, or query from GCE meta service.

Returns
  • (String) — default GCP service_version

#error_event

def error_event(message = nil, service_name: nil, service_version: nil, event_time: nil, user: nil, file_path: nil, line_number: nil, function_name: nil) -> ErrorEvent

Create a new ErrorEvent instance with given parameters.

Parameters
  • message (String) — The error message along with backtrace
  • service_name (String) (defaults to: nil) — The service's name. Default to Project.default_service_name
  • service_version (String) (defaults to: nil) — The service's version. Default to Project.default_service_version
  • event_time (Time) (defaults to: nil) — Time when the event occurred. If not provided, the time when the event was received by the Error Reporting system will be used.
  • user (String) (defaults to: nil) — The user who caused or was affected by the crash. This can be a user ID, an email address, or an arbitrary token that uniquely identifies the user. When sending an error report, leave this field empty if the user was not logged in. In this case the Error Reporting system will use other data, such as remote IP address, to distinguish affected users.
  • file_path (String) (defaults to: nil) — The source code filename, which can include a truncated relative path, or a full path from a production machine.
  • line_number (Number) (defaults to: nil) — 1-based. 0 indicates that the line number is unknown.
  • function_name (String) (defaults to: nil) — Human-readable name of a function or method. The value can include optional context like the class or package name. For example, my.package.MyClass.method in case of Java.
Returns
Example
require "google/cloud/error_reporting"

error_reporting = Google::Cloud::ErrorReporting.new

error_event =
  error_reporting.error_event "Error Message with Backtrace",
                              event_time: Time.now,
                              service_name: "my_app_name",
                              service_version: "v8",
                              user: "johndoh",
                              file_path: "MyController.rb",
                              line_number: 123,
                              function_name: "index"
error_reporting.report error_event

#project

def project() -> String
Alias Of: #project_id

Get the name of current project_id from underneath gRPC Service object.

Returns
  • (String) — The current project_id

#project_id

def project_id() -> String
Aliases

Get the name of current project_id from underneath gRPC Service object.

Returns
  • (String) — The current project_id

#report

def report(*args, &block)

Report a ErrorEvent to Error Reporting service.

Example
require "google/cloud/error_reporting"

error_reporting = Google::Cloud::ErrorReporting.new

error_event = error_reporting.error_event "Error with Backtrace"
error_reporting.report error_event

#report_exception

def report_exception(exception, service_name: nil, service_version: nil)

Create a ErrorEvent from the given exception, and report this ErrorEvent to Error Reporting service.

Parameters
Yields
  • (error_event)
Example
require "google/cloud/error_reporting"

error_reporting = Google::Cloud::ErrorReporting.new

begin
  fail StandardError, "A serious problem"
rescue => exception
  error_reporting.report_exception exception,
                                   service_name: "my_app_name",
                                   service_version: "v8"
end