Reference documentation and code samples for the Error Reporting API class Google::Cloud::ErrorReporting::Middleware.
Middleware
Google::Cloud::ErrorReporting::Middleware defines a Rack Middleware that can automatically catch upstream exceptions and report them to Error Reporting.
Inherits
- Object
Methods
#call
def call(env)
Implements the mandatory Rack Middleware call method.
Catch all Exceptions from upstream and report them to Error Reporting. Unless the exception's class is defined to be ignored by this Middleware.
- env (Hash) — Rack environment hash
#error_event_from_exception
def error_event_from_exception(env, exception) -> Google::Cloud::ErrorReporting::ErrorEvent
Creates a ErrorEvent based on the exception. Fill in the HttpRequestContext section of the ErrorEvent based on the HTTP Request headers.
When used in Rails environment. It replies on ActionDispatch::ExceptionWrapper class to derive a HTTP status code based on the exception's class.
- env (Hash) — Rack environment hash
- exception (Exception) — Exception to convert from
- (Google::Cloud::ErrorReporting::ErrorEvent) — The gRPC ErrorEvent object that's based on given env and exception
#error_reporting
def error_reporting()
A Google::Cloud::ErrorReporting::Project client used to report error events.
#initialize
def initialize(app, error_reporting: nil, **kwargs) -> Google::Cloud::ErrorReporting::Middleware
Construct a new instance of Middleware.
- app (Rack::Application) — The Rack application
- error_reporting (Google::Cloud::ErrorReporting::Project) (defaults to: nil) — A Google::Cloud::ErrorReporting::Project client for reporting exceptions
- kwargs (Hash) — Hash of configuration settings. Used for backward API compatibility. See the Configuration Guide for the prefered way to set configuration parameters.
- (Google::Cloud::ErrorReporting::Middleware) — A new instance of Middleware
#report_exception
def report_exception(env, exception)
Report an given exception to Error Reporting.
While it reports most of the exceptions. Certain Rails exceptions that maps to a HTTP status code less than 500 will be treated as not the app fault and ignored.
- env (Hash) — Rack environment hash
- exception (Exception) — The Ruby exception to report.
Constants
EXCEPTION_KEYS
value: ["sinatra.error", "rack.exception"].freeze