Exception reporting / monitoring through external services.

Namespace
Methods
A
C
R
W
Class Public methods
add( klass )

Add an exception reporter class to the set of reporters. See the Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter class for an overview.

Whenever the middleware’s own exception handler catches an exception, it will run through the set of exception reporters (if any) and call each one to report exception details.

Reporters are maintained in a Set. Only one class will ever be stored and called once per exception; the original order of addition before duplicates is maintained (so if you add class A, then B, then A again, then class A is called first and only once, then B once).

Each reporter is called from its own Ruby Thread so that client API call response is kept fast. If a call fails, a debug log entry is made but processing of other reporters continues uninterrupted. It is up to individual reporter classes to manage thread safety.

klass

Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter subclass (class, not instance) to add.

# File lib/hoodoo/services/middleware/exception_reporting/exception_reporting.rb, line 43
def self.add( klass )
  unless klass < Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter
    raise "Hoodoo::Services::Middleware.add must be called with a Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter subclass"
  end

  @@reporter_pool.add( klass.instance )
end
contextual_report( exception, context )

Call all added exception reporters (see ::add) to report an exception based on the context of an in-flight request/response cycle. Reporters need to support the contextual reporting mechanism. If any do not, the simpler ::report mechanism is used as a fallback.

exception

Exception or Exception subclass instance to report.

context

Hoodoo::Services::Context instance describing the in-flight request/response cycle.

# File lib/hoodoo/services/middleware/exception_reporting/exception_reporting.rb, line 88
def self.contextual_report( exception, context )
  payload = Payload.new( exception: exception, context: context )
  @@reporter_pool.communicate( payload )
end
remove( klass )

Remove an exception reporter class from the set of reporters. See ::add for details.

klass

Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter subclass (class, not instance) to remove.

# File lib/hoodoo/services/middleware/exception_reporting/exception_reporting.rb, line 57
def self.remove( klass )
  unless klass < Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter
    raise "Hoodoo::Services::Middleware.remove must be called with a Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter subclass"
  end

  @@reporter_pool.remove( klass.instance )
end
report( exception, rack_env = nil )

Call all added exception reporters (see ::add) to report an exception.

exception

Exception or Exception subclass instance to report.

rack_env

Optional Rack environment hash for the inbound request, for exception reports made in the context of Rack request handling.

# File lib/hoodoo/services/middleware/exception_reporting/exception_reporting.rb, line 73
def self.report( exception, rack_env = nil )
  payload = Payload.new( exception: exception, rack_env: rack_env )
  @@reporter_pool.communicate( payload )
end
wait( timeout = 5 )

Wait for all executing reporter threads to catch up before continuing.

timeout

Optional timeout wait delay for each thread. Default is 5 seconds.

# File lib/hoodoo/services/middleware/exception_reporting/exception_reporting.rb, line 98
def self.wait( timeout = 5 )
  @@reporter_pool.wait( per_instance_timeout: timeout )
end