diff --git a/lib/phusion_passenger/rails3_extensions/init.rb b/lib/phusion_passenger/rails3_extensions/init.rb
index <HASH>..<HASH> 100644
--- a/lib/phusion_passenger/rails3_extensions/init.rb
+++ b/lib/phusion_passenger/rails3_extensions/init.rb
@@ -55,8 +55,12 @@ class AnalyticsLogging < ActiveSupport::LogSubscriber
 		end
 		
 		if defined?(ActionDispatch::ShowExceptions)
+			exceptions_middleware = ActionDispatch::ShowExceptions
+			if defined?(ActionDispatch::DebugExceptions)
+				exceptions_middleware = ActionDispatch::DebugExceptions
+			end
 			Rails.application.middleware.insert_after(
-				ActionDispatch::ShowExceptions,
+				exceptions_middleware,
 				ExceptionLogger, analytics_logger)
 		end
fix exception analytics for rails <I>