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 Error Reporting service.

Google::Cloud::ErrorReporting::ErrorEvent is able to be transformed into the Google::Cloud::ErrorReporting::V1beta1::ReportedErrorEvent gRPC structure. Once an error event is reported, the GCP Error Reporting 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.



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

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.



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

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.



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

def function_name
  @function_name
end

#http_methodObject

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



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

def http_method
  @http_method
end

#http_referrerObject

The referrer information that is provided with the request.



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

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.



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

def http_remote_ip
  @http_remote_ip
end

#http_statusObject

The HTTP response status code for the request.



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

def http_status
  @http_status
end

#http_urlObject

The URL of the request.



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

def http_url
  @http_url
end

#http_user_agentObject

The user agent information that is provided with the request.



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

def http_user_agent
  @http_user_agent
end

#line_numberObject

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



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

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.



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

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.



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

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.



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

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.



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

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.



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/google/cloud/error_reporting/error_event.rb', line 210

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

  if !backtrace.nil? && !backtrace.empty?
    message = "#{message}\n\t" + backtrace.join("\n\t")

    file_path, line_number, function_name = backtrace.first.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::Cloud::ErrorReporting::V1beta1::ReportedErrorEvent object.

Parameters:

  • grpc (Google::Cloud::ErrorReporting::V1beta1::ReportedErrorEvent)

    A Google::Cloud::ErrorReporting::V1beta1::ReportedErrorEvent object

Returns:

  • (ErrorEvent)

    A new ErrorEvent instance derived from given grpc object



130
131
132
133
134
135
136
137
138
139
# File 'lib/google/cloud/error_reporting/error_event.rb', line 130

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_grpcGoogle::Cloud::ErrorReporting::V1beta1::ReportedErrorEvent

Convert ErrorEvent object to gRPC struct.

Returns:

  • (Google::Cloud::ErrorReporting::V1beta1::ReportedErrorEvent)

    gRPC struct that represent an ErrorEvent.



234
235
236
237
238
239
240
241
# File 'lib/google/cloud/error_reporting/error_event.rb', line 234

def to_grpc
  Google::Cloud::ErrorReporting::V1beta1::ReportedErrorEvent.new(
    event_time: event_time_grpc,
    message: message.to_s,
    service_context: service_context_grpc,
    context: error_context_grpc
  )
end