lib/raven/rack.rb in sentry-raven-0.8.0 vs lib/raven/rack.rb in sentry-raven-0.9.0

- old
+ new

@@ -1,5 +1,7 @@ +require 'time' + module Raven # Middleware for Rack applications. Any errors raised by the upstream # application will be delivered to Sentry and re-raised. # # Synopsis: @@ -17,18 +19,20 @@ # end # # Use a standard Raven.configure call to configure your server credentials. class Rack def self.capture_exception(exception, env, options = {}) + options[:time_spent] = Time.now-env[:requested_at] Raven.capture_exception(exception, options) do |evt| evt.interface :http do |int| int.from_rack(env) end end end def self.capture_message(message, env, options = {}) + options[:time_spent] = Time.now-env[:requested_at] Raven.capture_message(message, options) do |evt| evt.interface :http do |int| int.from_rack(env) end end @@ -37,22 +41,24 @@ def initialize(app) @app = app end def call(env) + # clear context at the beginning of the request to ensure a clean slate + Context.clear! + # store the current environment in our local context for arbitrary # callers + env[:requested_at] = Time.now Raven.rack_context(env) begin response = @app.call(env) rescue Error raise # Don't capture Raven errors rescue Exception => e Raven::Rack.capture_exception(e, env) raise - ensure - Context.clear! end error = env['rack.exception'] || env['sinatra.error'] Raven::Rack.capture_exception(error, env) if error