From 961294500036fde4dd2f64b150bff18282847207 Mon Sep 17 00:00:00 2001 From: Jarrett Lusso Date: Fri, 24 Nov 2023 09:13:09 -0500 Subject: [PATCH] Fix `ActionDispatchSpy#render_exception` for Rails 7.1 (#1423) In Rails 7.1 `render_exception` was changed to take an ActionDispatch::ExceptionWrapper instead of an Exception. I've added support for the new way while keeping support for pre 7.1. --- lib/elastic_apm/spies/action_dispatch.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/elastic_apm/spies/action_dispatch.rb b/lib/elastic_apm/spies/action_dispatch.rb index 73c65a478..9dccce3e8 100644 --- a/lib/elastic_apm/spies/action_dispatch.rb +++ b/lib/elastic_apm/spies/action_dispatch.rb @@ -24,11 +24,19 @@ module Spies class ActionDispatchSpy # @api private module Ext - def render_exception(env, exception) - context = ElasticAPM.build_context(rack_env: env, for_type: :error) + def render_exception(request, exception_or_wrapper) + context = ElasticAPM.build_context( + rack_env: request, for_type: :error + ) + exception = + if exception_or_wrapper.is_a?(ActionDispatch::ExceptionWrapper) + exception_or_wrapper.exception + else + exception_or_wrapper + end ElasticAPM.report(exception, context: context, handled: false) - super(env, exception) + super(request, exception_or_wrapper) end end