The google-cloud-error_reporting gem provides framework instrumentation features
to make it easy to report exceptions from your application.
Quick Start
require"google/cloud/error_reporting"# Insert a Rack Middleware to report unhanded exceptionsuseGoogle::Cloud::ErrorReporting::Middleware# Or explicitly submit exceptionsbeginfail"Boom!"rescue=>exceptionGoogle::Cloud::ErrorReporting.reportexceptionend
Configuration
The default configuration enables Google Cloud Error Reporting 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.
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 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.
Rails Integration
To use the Error Reporting Railtie for Ruby on Rails applications,
simply add this line to config/application.rb:
beginfail"Boom!"rescue=>exceptionGoogle::Cloud::ErrorReporting.reportexceptiondo|error_event|# Directly modify the Google::Cloud::ErrorReporting::ErrorEvent object before submissionerror_event.message="Custom error message"error_event.user="johndoh@example.com"error_event.http_status=502endend
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["Version latestkeyboard_arrow_down\n\n- [0.44.0 (latest)](/ruby/docs/reference/google-cloud-error_reporting/latest/INSTRUMENTATION)\n- [0.43.0](/ruby/docs/reference/google-cloud-error_reporting/0.43.0/INSTRUMENTATION)\n- [0.42.3](/ruby/docs/reference/google-cloud-error_reporting/0.42.3/INSTRUMENTATION) \n\nError Reporting Instrumentation\n===============================\n\nThe google-cloud-error_reporting gem provides framework instrumentation features\nto make it easy to report exceptions from your application.\n\nQuick Start\n-----------\n\n```ruby\nrequire \"google/cloud/error_reporting\"\n\n# Insert a Rack Middleware to report unhanded exceptions\nuse Google::Cloud::ErrorReporting::Middleware\n\n# Or explicitly submit exceptions\nbegin\n fail \"Boom!\"\nrescue =\u003e exception\n Google::Cloud::ErrorReporting.report exception\nend\n```\n\nConfiguration\n-------------\n\nThe default configuration enables Google Cloud Error Reporting instrumentation features to run on\nGoogle Cloud Platform. You can easily configure the instrumentation library if\nyou want to run on a non Google Cloud environment or you want to customize the\ndefault behavior.\n\nSee the [Configuration\nGuide](https://googleapis.dev/ruby/stackdriver/latest/file.INSTRUMENTATION_CONFIGURATION.html)\nfor full configuration parameters.\n\nRack Middleware and Railtie\n---------------------------\n\nThe google-cloud-error_reporting gem provides a Rack Middleware class that can\neasily integrate with Rack based application frameworks, such as Rails and\nSinatra. When enabled, it automatically gathers application exceptions from\nrequests and submits the information to the Error Reporting service.\nOn top of that, the google-cloud-error_reporting also implements a Railtie class\nthat automatically enables the Rack Middleware in Rails applications when used.\n\n### Rails Integration\n\nTo use the Error Reporting Railtie for Ruby on Rails applications,\nsimply add this line to `config/application.rb`: \n\n```ruby\nrequire \"google/cloud/error_reporting/rails\"\n```\n\nAlternatively, check out the\n\\[stackdriver\\](\u003chttps://googleapis.dev/ruby/stackdriver/latest\u003e\ngem, which enables this Railtie by default.\n\n### Rack Integration\n\nOther Rack-based framework can also directly leverage the Middleware directly: \n\n```ruby\nrequire \"google/cloud/error_reporting\"\n\nuse Google::Cloud::ErrorReporting::Middleware\n```\n\nReport Captured Exceptions\n--------------------------\n\nCaptured Ruby exceptions can be reported directly to Error Reporting\nby using [Google::Cloud::ErrorReporting.report](/ruby/docs/reference/google-cloud-error_reporting/latest/Google-Cloud-ErrorReporting#Google__Cloud__ErrorReporting_report_class_ \"Google::Cloud::ErrorReporting.report (method)\"): \n\n```ruby\nbegin\n fail \"Boom!\"\nrescue =\u003e exception\n Google::Cloud::ErrorReporting.report exception\nend\n```\n\nThe reported error event can also be customized: \n\n```ruby\nbegin\n fail \"Boom!\"\nrescue =\u003e exception\n Google::Cloud::ErrorReporting.report exception do |error_event|\n # Directly modify the Google::Cloud::ErrorReporting::ErrorEvent object before submission\n error_event.message = \"Custom error message\"\n error_event.user = \"johndoh@example.com\"\n error_event.http_status = 502\n end\nend\n```\n\nSee [Google::Cloud::ErrorReporting::ErrorEvent](/ruby/docs/reference/google-cloud-error_reporting/latest/Google-Cloud-ErrorReporting-ErrorEvent \"Google::Cloud::ErrorReporting::ErrorEvent (class)\") class for all options."]]