Module: Google::Cloud::ErrorReporting
- Defined in:
- lib/google/cloud/error_reporting.rb,
lib/google/cloud/error_reporting/rails.rb,
lib/google/cloud/error_reporting/project.rb,
lib/google/cloud/error_reporting/service.rb,
lib/google/cloud/error_reporting/version.rb,
lib/google/cloud/error_reporting/middleware.rb,
lib/google/cloud/error_reporting/credentials.rb,
lib/google/cloud/error_reporting/error_event.rb,
lib/google/cloud/error_reporting/async_error_reporter.rb
Overview
Error Reporting
Error Reporting counts, analyzes and aggregates the crashes in your running cloud services.
Defined Under Namespace
Classes: Credentials, ErrorEvent, Middleware, Project, Railtie
Constant Summary collapse
- VERSION =
"0.43.0".freeze
Class Method Summary collapse
-
.configure {|Google::Cloud.configure.error_reporting| ... } ⇒ Google::Cloud::Config
Configure the default Project client, allows the ErrorReporting.report public method to reuse these configured parameters.
-
.default_reporter(&block) ⇒ #report
Returns the global default reporter used by middleware and the ErrorReporting.report convenience method.
-
.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.
-
.report(exception, service_name: nil, service_version: nil) {|error_event| ... } ⇒ Object
Provides an easy-to-use interface to Report a Ruby exception object to Error Reporting service.
Class Method Details
.configure {|Google::Cloud.configure.error_reporting| ... } ⇒ Google::Cloud::Config
Configure the default Project client, allows the 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 parameterproject
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 parameterkeyfile
is considered deprecated, but may also be used.)scope
- (String, Array) The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. 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, ornil
to use the default endpoint.service_name
- (String) Name for the application.service_version
- (String) Version identifier for the application.ignore_classes
- (Array) Array of exception types that should not be reported. on_error
- (Proc) A Proc to be run when an error is encountered on a background thread, such as report or Middleware. The Proc must take the error object as the single argument. If ErrorReporting is being used to report errors usingGoogle::Cloud::cofigure.on_error
, then thison_error
should be configured to report errors raised when reporting through ErrorReporting.
See the Configuration Guide for full configuration parameters.
160 161 162 163 164 |
# File 'lib/google/cloud/error_reporting.rb', line 160 def self.configure yield Google::Cloud.configure.error_reporting if block_given? Google::Cloud.configure.error_reporting end |
.default_reporter(&block) ⇒ #report
Returns the global default reporter used by middleware and the 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.
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/google/cloud/error_reporting.rb', line 266 def self.default_reporter &block @default_reporter_mutex.synchronize do @default_reporter ||= if block block.call else project_id = Project.default_project_id credentials = default_credentials AsyncErrorReporter.new( new(project_id: project_id, credentials: credentials) ) end end @default_reporter end |
.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.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/google/cloud/error_reporting.rb', line 79 def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil, endpoint: nil, project: nil, keyfile: nil project_id ||= project project_id ||= ErrorReporting::Project.default_project_id scope ||= configure.scope timeout ||= configure.timeout endpoint ||= configure.endpoint credentials ||= keyfile || default_credentials(scope: scope) credentials = resolve_credentials credentials, scope project_id = resolve_project_id project_id, credentials service = ErrorReporting::Service.new project_id, credentials, host: endpoint, timeout: timeout ErrorReporting::Project.new service end |
.report(exception, service_name: nil, service_version: nil) {|error_event| ... } ⇒ Object
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 configure.
The error event can be customized before reporting. See the example below and ErrorEvent class for avaiable error event fields.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/google/cloud/error_reporting.rb', line 211 def self.report exception, service_name: nil, service_version: nil return if Google::Cloud.configure.use_error_reporting == false service_name ||= Project.default_service_name service_version ||= Project.default_service_version # Ensure the reported exception has a backtrace exception.set_backtrace caller if exception.backtrace.nil? error_event = ErrorEvent.from_exception(exception).tap do |event| event.service_name = service_name event.service_version = service_version end yield error_event if block_given? default_reporter.report error_event end |