Skip to content

Commit cc4e71f

Browse files
committed
Remove premature path-removal filter
This filter removes the project root part from the stacktrace, which prevents sentry-ruby from retaining the correct absolute path of it.
1 parent 02c782b commit cc4e71f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ def initialize
1616
# We don't want any default filters because Rails 7.2 starts shortening the paths. See #2472
1717
remove_filters!
1818

19-
@root = "#{Sentry.configuration.project_root}/"
20-
add_filter do |line|
21-
line.start_with?(@root) ? line.from(@root.size) : line
22-
end
2319
add_filter do |line|
2420
if line =~ RENDER_TEMPLATE_PATTERN
2521
line.sub(RENDER_TEMPLATE_PATTERN, "")

sentry-rails/spec/sentry/rails/event_spec.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
it 'marks in_app correctly' do
3333
frames = hash[:exception][:values][0][:stacktrace][:frames]
3434
expect(frames[0][:filename]).to eq("test/some/other/path")
35+
expect(frames[0][:abs_path]).to eq("test/some/other/path")
3536
expect(frames[0][:in_app]).to eq(true)
3637
expect(frames[1][:filename]).to eq("/app/some/other/path")
3738
expect(frames[1][:in_app]).to eq(false)
@@ -41,7 +42,7 @@
4142
expect(frames[3][:in_app]).to eq(true)
4243
expect(frames[4][:filename]).to eq("vendor/bundle/some_gem.rb")
4344
expect(frames[4][:in_app]).to eq(false)
44-
expect(frames[5][:filename]).to eq("vendor/bundle/cache/other_gem.rb")
45+
expect(frames[5][:filename]).to eq("dummy/test_rails_app/vendor/bundle/cache/other_gem.rb")
4546
expect(frames[5][:in_app]).to eq(false)
4647
end
4748

@@ -50,6 +51,7 @@
5051
$LOAD_PATH << "#{Rails.root}/app/models"
5152
frames = hash[:exception][:values][0][:stacktrace][:frames]
5253
expect(frames[3][:filename]).to eq("app/models/user.rb")
54+
expect(frames[3][:abs_path]).to eq("#{Rails.root}/app/models/user.rb")
5355
$LOAD_PATH.delete("#{Rails.root}/app/models")
5456
end
5557
end
@@ -58,15 +60,17 @@
5860
it 'normalizes the filename using the load path' do
5961
$LOAD_PATH.push "vendor/bundle"
6062
frames = hash[:exception][:values][0][:stacktrace][:frames]
61-
expect(frames[5][:filename]).to eq("cache/other_gem.rb")
63+
expect(frames[5][:filename]).to eq("dummy/test_rails_app/vendor/bundle/cache/other_gem.rb")
64+
expect(frames[5][:abs_path]).to eq("#{Rails.root}/vendor/bundle/cache/other_gem.rb")
6265
$LOAD_PATH.pop
6366
end
6467
end
6568

6669
context "when a non-in_app path under project_root isn't on the load path" do
6770
it 'normalizes the filename using project_root' do
6871
frames = hash[:exception][:values][0][:stacktrace][:frames]
69-
expect(frames[5][:filename]).to eq("vendor/bundle/cache/other_gem.rb")
72+
expect(frames[5][:filename]).to eq("dummy/test_rails_app/vendor/bundle/cache/other_gem.rb")
73+
expect(frames[5][:abs_path]).to eq("#{Rails.root}/vendor/bundle/cache/other_gem.rb")
7074
end
7175
end
7276
end

0 commit comments

Comments
 (0)