Stackdriver Error Reporting Instrumentation
The google-cloud-error_reporting gem provides framework instrumentation features to make it easy to report exceptions from your application.
require "google/cloud/error_reporting" # Insert a Rack Middleware to report unhanded exceptions use :::::: # Or explicitly submit exceptions begin fail "Boom!" rescue => exception ::::. exception end
The default configuration enables Stackdriver instrumentation features to run on Google Cloud Platform. You can easily configure the instrumentation library if you want to run on a non Google Cloud environment or you want to customize the default behavior.
See the Configuration Guide for full configuration parameters.
Rack Middleware and Railtie
The google-cloud-error_reporting gem provides a Rack Middleware class that can easily integrate with Rack based application frameworks, such as Rails and Sinatra. When enabled, it automatically gathers application exceptions from requests and submits the information to the Stackdriver Error Reporting service. On top of that, the google-cloud-error_reporting also implements a Railtie class that automatically enables the Rack Middleware in Rails applications when used.
To use the Stackdriver Error Reporting Railtie for Ruby on Rails applications,
simply add this line to
Alternatively, check out the [stackdriver](https://googleapis.dev/ruby/stackdriver/latest gem, which enables this Railtie by default.
Other Rack-based framework can also directly leverage the Middleware directly:
require "google/cloud/error_reporting" use ::::::
Report Captured Exceptions
Captured Ruby exceptions can be reported directly to Stackdriver Error Reporting by using:
begin fail "Boom!" rescue => exception ::::. exception end
The reported error event can also be customized:
begin fail "Boom!" rescue => exception ::::. exception do |error_event| # Directly modify the Google::Cloud::ErrorReporting::ErrorEvent object before submission error_event. = "Custom error message" error_event.user = "firstname.lastname@example.org" error_event.http_status = 502 end end
Seeclass for all options.