Skip to content

Commit

Permalink
Ignore low-level Puma exceptions by default (#2055)
Browse files Browse the repository at this point in the history
* Ignore low-level Puma exceptions by default

This is a follow-up to #2026. The idea is to ignore low-level Puma
exceptions by default, but allow users to opt-in to capturing them.

Please see comments in #2026
for more details.

* Update changelog
  • Loading branch information
st0012 authored Jun 21, 2023
1 parent 11ecd25 commit 75aa456
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### Bug Fixes

- Support Rails 7.1's show exception check [#2049](https://github.com/getsentry/sentry-ruby/pull/2049)
- Ignore low-level Puma exceptions by default [#2055](https://github.com/getsentry/sentry-ruby/pull/2055)

## 5.9.0

Expand Down
11 changes: 10 additions & 1 deletion sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,15 @@ def capture_exception_frame_locals=(value)
# @!visibility private
attr_reader :errors, :gem_specs

# These exceptions could enter Puma's `lowlevel_error_handler` callback and the SDK's Puma integration
# But they are mostly considered as noise and should be ignored by default
# Please see https://github.com/getsentry/sentry-ruby/pull/2026 for more information
PUMA_IGNORE_DEFAULT = [
'Puma::MiniSSL::SSLError',
'Puma::HttpParserError',
'Puma::HttpParserError501'
].freeze

# Most of these errors generate 4XX responses. In general, Sentry clients
# only automatically report 5xx responses.
IGNORE_DEFAULT = [
Expand Down Expand Up @@ -306,7 +315,7 @@ def initialize
self.environment = environment_from_env
self.enabled_environments = []
self.exclude_loggers = []
self.excluded_exceptions = IGNORE_DEFAULT.dup
self.excluded_exceptions = IGNORE_DEFAULT + PUMA_IGNORE_DEFAULT
self.inspect_exception_causes_for_exclusion = true
self.linecache = ::Sentry::LineCache.new
self.logger = ::Sentry::Logger.new(STDOUT)
Expand Down
33 changes: 33 additions & 0 deletions sentry-ruby/spec/isolated/puma_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,39 @@ def server_run(app, lowlevel_error_handler: nil, &block)
end
end

context "when puma raises its own errors" do
[Puma::MiniSSL::SSLError, Puma::HttpParserError, Puma::HttpParserError501].each do |error_class|
it "doesn't capture #{error_class}" do
app = proc { raise error_class.new("foo") }

res = server_run(app) do |server|
server.send_http_and_read("GET / HTTP/1.0\r\n\r\n")
end

expect(res).to match(/500 Internal Server Error/)
events = sentry_events
expect(events.count).to eq(0)
end

it "captures #{error_class} when it is removed from the SDK's config.excluded_exceptions" do
Sentry.configuration.excluded_exceptions.delete(error_class.name)

app = proc { raise error_class.new("foo") }

res = server_run(app) do |server|
server.send_http_and_read("GET / HTTP/1.0\r\n\r\n")
end

expect(res).to match(/500 Internal Server Error/)
events = sentry_events
expect(events.count).to eq(1)
event = events.first
expect(event.exception.values.first.type).to match(error_class.name)
expect(event.exception.values.first.value).to match("foo")
end
end
end

context "when Sentry.capture_exception causes error" do
it "doesn't affect the response" do
expect(Sentry).to receive(:capture_exception).and_raise("bar")
Expand Down

0 comments on commit 75aa456

Please sign in to comment.