Skip to content

Commit a1c5282

Browse files
authored
fix(rails): set mechanism.handled based on error handling status (#2892)
1 parent 7c802b3 commit a1c5282

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

sentry-rails/lib/sentry/rails/error_subscriber.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def report(error, handled:, severity:, context:, source: nil)
2727
hint.merge!(context.delete(:hint))
2828
end
2929

30+
hint[:mechanism] ||= Sentry::Mechanism.new(type: Sentry::Rails.integration_name, handled: handled)
31+
3032
Sentry::Rails.capture_exception(error, level: severity, contexts: { "rails.error" => context }, tags: tags, hint: hint)
3133
end
3234
end

sentry-rails/spec/sentry/rails/error_subscriber_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,24 @@
7171
end
7272
end
7373

74+
context 'when handled: true' do
75+
it 'sets mechanism.handled to true' do
76+
expect(Sentry::Rails).to receive(:capture_exception) do |_, hint:, **_|
77+
expect(hint[:mechanism].handled).to eq(true)
78+
end
79+
described_class.new.report(StandardError.new, handled: true, severity: :error, context: {})
80+
end
81+
end
82+
83+
context 'when handled: false' do
84+
it 'sets mechanism.handled to false' do
85+
expect(Sentry::Rails).to receive(:capture_exception) do |_, hint:, **_|
86+
expect(hint[:mechanism].handled).to eq(false)
87+
end
88+
described_class.new.report(StandardError.new, handled: false, severity: :error, context: {})
89+
end
90+
end
91+
7492
context 'when passed a context with hint key' do
7593
context 'when hint is a Hash' do
7694
it 'merges the hint into the event' do

0 commit comments

Comments
 (0)