Skip to content

Instantly share code, notes, and snippets.

@netshade
Last active December 15, 2015 01:09
Show Gist options
  • Save netshade/5177697 to your computer and use it in GitHub Desktop.
Save netshade/5177697 to your computer and use it in GitHub Desktop.
Capture Exceptions with Instrumental (tested in Rails 3.2.11)
# lib/instrumental/exception_reporter_middleware.rb
module Instrumental
class ExceptionReporterMiddleware
def initialize(app)
@app = app
end
def call(env)
@app.call(env)
rescue Exception => e
I.increment("app.exception.#{e.class.name}")
Rails.logger.debug "Notifying Instrumental of #{e.class.name} exception..."
raise
end
end
end
# config/initializers/instrumental.rb
require 'instrumental/exception_reporter_middleware'
I = Instrumental::Agent.new("MY_API_TOKEN")
Rails.application.config.middleware.use Instrumental::ExceptionReporterMiddleware
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment