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,
lib/google/cloud/error_reporting/v1beta1/doc/overview.rb,
lib/google/cloud/error_reporting/v1beta1/error_group_service_client.rb,
lib/google/cloud/error_reporting/v1beta1/error_stats_service_client.rb,
lib/google/cloud/error_reporting/v1beta1/report_errors_service_client.rb
Overview
Ruby Client for Stackdriver Error Reporting API (Alpha)
Stackdriver Error Reporting API: Stackdriver Error Reporting groups and counts similar errors from cloud services. The Stackdriver Error Reporting API provides a way to report new errors and read access to error groups and their associated errors.
Quick Start
In order to use this library, you first need to go through the following steps:
- Select or create a Cloud Platform project.
- Enable the Stackdriver Error Reporting API.
- Setup Authentication.
Installation
$ gem install google-cloud-error_reporting
Preview
ReportErrorsServiceClient
require "google/cloud/error_reporting"
report_errors_service_client = Google::Cloud::ErrorReporting::ReportErrors.new
formatted_project_name = Google::Cloud::ErrorReporting::V1beta1::ReportErrorsServiceClient.project_path(project_id)
message = "[MESSAGE]"
service = "[SERVICE]"
service_context = { service: service }
file_path = "path/to/file.lang"
line_number = 42
function_name = "meaningOfLife"
report_location = {
file_path: file_path,
line_number: line_number,
function_name: function_name
}
context = { report_location: report_location }
event = {
message: message,
service_context: service_context,
context: context
}
response = report_errors_service_client.report_error_event(formatted_project_name, event)
Next Steps
- Read the Stackdriver Error Reporting API Product documentation to learn more about the product and see How-to Guides.
- View this repository's main README to see the full list of Cloud APIs that we cover.
Defined Under Namespace
Modules: V1beta1 Classes: Credentials, ErrorEvent, Middleware, Project, Railtie
Constant Summary collapse
- VERSION =
"0.29.0".freeze
Class Method Summary collapse
-
.configure {|Google::Cloud.configure.error_reporting| ... } ⇒ Stackdriver::Core::Configuration
Configure the default Project client, allows the ErrorReporting.report public method to reuse these configured parameters.
-
.new(project_id: nil, credentials: nil, scope: nil, timeout: nil, client_config: nil, project: nil, keyfile: nil) ⇒ Google::Cloud::ErrorReporting::Project
Creates a new object for connecting to the Stackdriver 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 Stackdriver ErrorReporting service.
Class Method Details
.configure {|Google::Cloud.configure.error_reporting| ... } ⇒ Stackdriver::Core::Configuration
Configure the default Project client, allows the report public method to reuse these configured parameters.
See the Configuration Guide for full configuration parameters.
175 176 177 178 179 |
# File 'lib/google/cloud/error_reporting.rb', line 175 def self.configure yield Google::Cloud.configure.error_reporting if block_given? Google::Cloud.configure.error_reporting end |
.new(project_id: nil, credentials: nil, scope: nil, timeout: nil, client_config: nil, project: nil, keyfile: nil) ⇒ Google::Cloud::ErrorReporting::Project
Creates a new object for connecting to the Stackdriver Error Reporting service. Each call creates a new connection.
For more information on connecting to Google Cloud see the Authentication Guide.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/google/cloud/error_reporting.rb', line 124 def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil, client_config: nil, project: nil, keyfile: nil project_id ||= (project || ErrorReporting::Project.default_project_id) project_id = project_id.to_s fail ArgumentError, "project_id is missing" if project_id.empty? credentials ||= keyfile credentials ||= ErrorReporting::Credentials.default(scope: scope) unless credentials.is_a? Google::Auth::Credentials credentials = ErrorReporting::Credentials.new credentials, scope: scope end ErrorReporting::Project.new( ErrorReporting::Service.new( project_id, credentials, timeout: timeout, client_config: client_config ) ) 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 Stackdriver ErrorReporting service. This method helps users to transform the Ruby exception into an Stackdriver ErrorReporting 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 Stackdriver ErrorReporting 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.
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/google/cloud/error_reporting.rb', line 226 def self.report exception, service_name: nil, service_version: nil return if Google::Cloud.configure.use_error_reporting == false service_name ||= configure.service_name || Project.default_service_name service_version ||= configure.service_version || Project.default_service_version 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_client.report error_event end |