Skip to content

Commit

Permalink
Clear Rails' default backtrace filters from Sentry's backtrace cleaner
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
st0012 committed Nov 27, 2024
1 parent a9b3687 commit 02c782b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sentry-rails/lib/sentry/rails/backtrace_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ class BacktraceCleaner < ActiveSupport::BacktraceCleaner

def initialize
super
# we don't want any default silencers because they're too aggressive
# We don't want any default silencers because they're too aggressive
remove_silencers!
# We don't want any default filters because Rails 7.2 starts shortening the paths. See #2472
remove_filters!

@root = "#{Sentry.configuration.project_root}/"
add_filter do |line|
Expand Down
10 changes: 10 additions & 0 deletions sentry-rails/spec/sentry/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,16 @@ def capture_in_separate_process(exit_code:)
expect(traces.dig(-1, "function")).to be_nil
end

it "makes sure BacktraceCleaner gem cleanup doesn't affect context lines population" do
get "/view_exception"

traces = event.dig("exception", "values", 0, "stacktrace", "frames")
gem_frame = traces.find { |t| t["abs_path"].match(/actionview/) }
expect(gem_frame["pre_context"]).not_to be_empty
expect(gem_frame["post_context"]).not_to be_empty
expect(gem_frame["context_line"]).not_to be_empty
end

it "doesn't filters exception backtrace if backtrace_cleanup_callback is overridden" do
make_basic_app do |config|
config.backtrace_cleanup_callback = lambda { |backtrace| backtrace }
Expand Down

0 comments on commit 02c782b

Please sign in to comment.