Skip to content

Commit 02c782b

Browse files
committed
Clear Rails' default backtrace filters from Sentry's backtrace cleaner
In Rails 7.2, Rails's backtrace cleaner, which sentry-rails' backtrace cleaner inherits from, starts shortening gem's paths in backtraces. This will prevent sentry-ruby's `Sentry::Backtrace` from handling them correctly, which will result in issues like #2472. This commit avoids the issue by clearing the default filters that Sentry's backtrace cleaner inherits.
1 parent a9b3687 commit 02c782b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

sentry-rails/lib/sentry/rails/backtrace_cleaner.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ class BacktraceCleaner < ActiveSupport::BacktraceCleaner
1111

1212
def initialize
1313
super
14-
# we don't want any default silencers because they're too aggressive
14+
# We don't want any default silencers because they're too aggressive
1515
remove_silencers!
16+
# We don't want any default filters because Rails 7.2 starts shortening the paths. See #2472
17+
remove_filters!
1618

1719
@root = "#{Sentry.configuration.project_root}/"
1820
add_filter do |line|

sentry-rails/spec/sentry/rails_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ def capture_in_separate_process(exit_code:)
242242
expect(traces.dig(-1, "function")).to be_nil
243243
end
244244

245+
it "makes sure BacktraceCleaner gem cleanup doesn't affect context lines population" do
246+
get "/view_exception"
247+
248+
traces = event.dig("exception", "values", 0, "stacktrace", "frames")
249+
gem_frame = traces.find { |t| t["abs_path"].match(/actionview/) }
250+
expect(gem_frame["pre_context"]).not_to be_empty
251+
expect(gem_frame["post_context"]).not_to be_empty
252+
expect(gem_frame["context_line"]).not_to be_empty
253+
end
254+
245255
it "doesn't filters exception backtrace if backtrace_cleanup_callback is overridden" do
246256
make_basic_app do |config|
247257
config.backtrace_cleanup_callback = lambda { |backtrace| backtrace }

0 commit comments

Comments
 (0)