Class: Google::Cloud::ErrorReporting::ErrorEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/error_reporting/error_event.rb

Overview

ErrorEvent

An individual error event to report to Stackdriver Error Reporting service.

Google::Cloud::ErrorReporting::ErrorEvent is able to be transformed into Devtools::Clouderrorreporting::V1beta1::ReportedErrorEvent gRPC structure. Once an error event is reported, the GCP Stackdriver ErrorReporting service is able to parse the message and backtrace, then group the error events by content.

Examples:

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",
                                          service_version: "v8"
error_reporting.report error_event

See Also:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#event_timeObject

Time when the event occurred. If not provided, the time when the event was received by the Error Reporting system will be used.



49
50
51
# File 'lib/google/cloud/error_reporting/error_event.rb', line 49

def event_time
  @event_time
end

#file_pathObject

The source code filename, which can include a truncated relative path, or a full path from a production machine.



108
109
110
# File 'lib/google/cloud/error_reporting/error_event.rb', line 108

def file_path
  @file_path
end

#function_nameObject

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.



118
119
120
# File 'lib/google/cloud/error_reporting/error_event.rb', line 118

def function_name
  @function_name
end

#http_methodObject

The type of HTTP request, such as GET, POST, etc.



72
73
74
# File 'lib/google/cloud/error_reporting/error_event.rb', line 72

def http_method
  @http_method
end

#http_referrerObject

The referrer information that is provided with the request.



84
85
86
# File 'lib/google/cloud/error_reporting/error_event.rb', line 84

def http_referrer
  @http_referrer
end

#http_remote_ipObject

The IP address from which the request originated. This can be IPv4, IPv6, or a token which is derived from the IP address, depending on the data that has been provided in the error report.



94
95
96
# File 'lib/google/cloud/error_reporting/error_event.rb', line 94

def http_remote_ip
  @http_remote_ip
end

#http_statusObject

The HTTP response status code for the request.



88
89
90
# File 'lib/google/cloud/error_reporting/error_event.rb', line 88

def http_status
  @http_status
end

#http_urlObject

The URL of the request.



76
77
78
# File 'lib/google/cloud/error_reporting/error_event.rb', line 76

def http_url
  @http_url
end

#http_user_agentObject

The user agent information that is provided with the request.



80
81
82
# File 'lib/google/cloud/error_reporting/error_event.rb', line 80

def http_user_agent
  @http_user_agent
end

#line_numberObject

1-based. 0 indicates that the line number is unknown.



112
113
114
# File 'lib/google/cloud/error_reporting/error_event.rb', line 112

def line_number
  @line_number
end

#messageObject

A message describing the error. The message can contain an exception stack in one of the supported programming languages and formats. In that case, the message is parsed and detailed exception information is returned when retrieving the error event again.



56
57
58
# File 'lib/google/cloud/error_reporting/error_event.rb', line 56

def message
  @message
end

#service_nameObject

An identifier of the service, such as the name of the executable, job, or Google App Engine service name. This field is expected to have a low number of values that are relatively stable over time, as opposed to version, which can be changed whenever new code is deployed.



63
64
65
# File 'lib/google/cloud/error_reporting/error_event.rb', line 63

def service_name
  @service_name
end

#service_versionObject

Represents the source code version that the developer provided, which could represent a version label or a Git SHA-1 hash, for example.



68
69
70
# File 'lib/google/cloud/error_reporting/error_event.rb', line 68

def service_version
  @service_version
end

#userObject

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. See affectedUsersCount in ErrorGroupStats.



103
104
105
# File 'lib/google/cloud/error_reporting/error_event.rb', line 103

def user
  @user
end

Class Method Details

.from_exception(exception) ⇒ ErrorEvent

Construct an ErrorEvent object based on a given exception.

Parameters:

  • exception (Exception)

    A Ruby exception.

Returns:

  • (ErrorEvent)

    An ErrorEvent object containing information from the given exception.



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/google/cloud/error_reporting/error_event.rb', line 214

def self.from_exception exception
  backtrace = exception.backtrace
  message = "#{exception.message} (#{exception.class})"

  if !backtrace.nil? && !backtrace.empty?
    error_location = backtrace.first

    message = "#{error_location}: #{message}\n\t" +
              backtrace.drop(1).join("\n\t")
    file_path, line_number, function_name = error_location.split(":")
    function_name = function_name.to_s[/`(.*)'/, 1]
  end

  new.tap do |e|
    e.message = message
    e.file_path = file_path
    e.line_number = line_number.to_i
    e.function_name = function_name
  end
end

.from_grpc(grpc) ⇒ ErrorEvent

Build a new ErrorEvent from a Google::Devtools::Clouderrorreporting::V1beta1::ReportedErrorEvent object.

Parameters:

Returns:

  • (ErrorEvent)

    A new ErrorEvent instance derived from given grpc object



134
135
136
137
138
139
140
141
142
143
# File 'lib/google/cloud/error_reporting/error_event.rb', line 134

def self.from_grpc grpc
  return new if grpc.nil?
  new.tap do |event|
    event.event_time = extract_timestamp grpc.event_time
    event.message = grpc.message

    extract_service_context event, grpc.service_context
    extract_error_context event, grpc.context
  end
end

Instance Method Details

#to_grpcDevtools::Clouderrorreporting::V1beta1::ReportedErrorEvent

Convert ErrorEvent object to gRPC struct.

Returns:



240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/google/cloud/error_reporting/error_event.rb', line 240

def to_grpc
  error_event_hash = {
    event_time: event_time_hash,
    message: message,
    service_context: service_context_hash,
    context: error_context_hash
  }.delete_if { |_, v| v.nil? }

  grpc_class =
    Devtools::Clouderrorreporting::V1beta1::ReportedErrorEvent
  grpc_class.decode_json error_event_hash.to_json
end