class Google::Cloud::ErrorReporting::Project
Projects are top-level containers in Google
Cloud
Platform. They store information about billing and authorized users, and they control access to Stackdriver ErrorReporting
. Each project has a friendly name and a unique ID. Projects can be created only in the [Google Developers Console](console.developers.google.com).
@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
See {Google::Cloud::ErrorReporting.new}
Attributes
@private The Service
object
Public Class Methods
Find default project_id
from the configuration, environment varaibles, or query from GCE meta service.
@return [String] default valid GCP project_id
# File lib/google/cloud/error_reporting/project.rb, line 51 def self.default_project_id Google::Cloud.configure.error_reporting.project_id || Google::Cloud.configure.project_id || Google::Cloud.env.project_id end
Find default service_name from the configuration, environment varaibles, or query from GCE meta service, or just “ruby”.
@return [String] default GCP service_name
# File lib/google/cloud/error_reporting/project.rb, line 66 def self.default_service_name Google::Cloud.configure.error_reporting.service_name || Google::Cloud.configure.service_name || Google::Cloud.env.app_engine_service_id || "ruby" end
Find default service_version from the configuration, environment varaibles, or query from GCE meta service.
@return [String] default GCP service_version
# File lib/google/cloud/error_reporting/project.rb, line 79 def self.default_service_version Google::Cloud.configure.error_reporting.service_version || Google::Cloud.configure.service_version || Google::Cloud.env.app_engine_service_version end
@private Create a new Project
instance.
@param [Google::Cloud::ErrorReporting::Service] service The underlying
Service object
@return [Google::Cloud::ErrorReporting::Project] A new Project
instance
# File lib/google/cloud/error_reporting/project.rb, line 98 def initialize service @service = service end
Public Instance Methods
Create a new {Google::Cloud::ErrorReporting::ErrorEvent} instance with given parameters.
@param [String] message The error message along with backtrace @param [String] service_name The service's name.
Default to {default_service_name}
@param [String] service_version The service's version.
Default to {default_service_version}
@param [Time] event_time Time when the event occurred. If not
provided, the time when the event was received by the Error Reporting system will be used.
@param [String] user 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.
@param [String] file_path The source code filename, which can include
a truncated relative path, or a full path from a production machine.
@param [Number] line_number 1-based. 0 indicates that the line number
is unknown.
@param [String] function_name 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.
@return [ErrorEvent] A new ErrorEvent
instance
@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
# File lib/google/cloud/error_reporting/project.rb, line 211 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.new.tap do |e| e.message = message e.event_time = event_time e.service_name = service_name || self.class.default_service_name e.service_version = service_version || self.class.default_service_version e.user = user e.file_path = file_path e.line_number = line_number e.function_name = function_name end end
Get the name of current project_id
from underneath gRPC Service
object.
@return [String] The current project_id
# File lib/google/cloud/error_reporting/project.rb, line 108 def project_id service.project end
Report a {Google::Cloud::ErrorReporting::ErrorEvent} to Stackdriver 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
# File lib/google/cloud/error_reporting/project.rb, line 125 def report *args, &block service.report *args, &block end
Create a {Google::Cloud::ErrorReporting::ErrorEvent} from the given exception, and report this ErrorEvent
to Stackdriver Error Reporting service.
@param [Exception] exception A Ruby exception @param [String] service_name The service's name.
Default to {default_service_name}
@param [String] service_version The service's version.
Default to {default_service_version}
@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
# File lib/google/cloud/error_reporting/project.rb, line 153 def report_exception exception, service_name: nil, service_version: nil error_event = ErrorEvent.from_exception exception error_event.service_name = service_name || self.class.default_service_name error_event.service_version = service_version || self.class.default_service_version yield error_event if block_given? report error_event end