Skip to content

Improve SDK's error handling#1298

Merged
st0012 merged 13 commits intomasterfrom
implement-#1290
Mar 7, 2021
Merged

Improve SDK's error handling#1298
st0012 merged 13 commits intomasterfrom
implement-#1290

Conversation

@st0012
Copy link
Copy Markdown
Contributor

@st0012 st0012 commented Feb 25, 2021

This implements the error handling rules described in #1290

closes #1246, #1290 and #1289

@st0012 st0012 self-assigned this Feb 25, 2021
@st0012 st0012 added the wip label Feb 25, 2021
@st0012 st0012 force-pushed the implement-#1290 branch 2 times, most recently from 6898ada to 763cd8a Compare February 27, 2021 10:49
@st0012 st0012 added this to the 4.3.0 milestone Mar 1, 2021
@st0012
Copy link
Copy Markdown
Contributor Author

st0012 commented Mar 4, 2021

@sujh not sure if you'd want to give this a look before I merge it?

@sujh
Copy link
Copy Markdown

sujh commented Mar 5, 2021

Hope this can be merged as soon as possible!

@st0012 st0012 removed the wip label Mar 7, 2021
st0012 added 12 commits March 7, 2021 11:01
Sentry::Error represents errors SDK raises intentionally.
Sentry::ExternalError represents errors by the SDK, but casused by
external reasons, like networking issues.
The code invoked by the SDK itself, whether it's an external service
call (like sending events) or a user-defined callback (like async or
before_send), shouldn't cause the user's application to crash.

Although some may think errors caused by user-defined callbacks should
be raised for debugging purpose, it's actually a bad practice in reality.

Most of the users only activate the SDK in production and they don't write
tests for the callbacks. So if there's any bug in the callbacks,
they will usually be spotted in production.

Also, because the SDK is usually placed at the farthest layer of the
app to catch all the possible exceptions, there won't be anything to
capture exceptions triggered by the SDK.

So from the SDK's perspective, we can either raise them or swallow them:

- If we raise them, the user's customers will see broken apps. Good for
  spotting bugs, very bad user experience.
- If we rescue them, the user's customers won't spot a thing. It may be
  harder for the user to spot the buggy callback, but at least their
  customers won't be angry.

This is why I decided to swallow any errors happen in the
`Client#capture_event`.
@st0012 st0012 force-pushed the implement-#1290 branch from 763cd8a to 8e7e7b0 Compare March 7, 2021 03:02
@codecov-io
Copy link
Copy Markdown

codecov-io commented Mar 7, 2021

Codecov Report

Merging #1298 (0343f1b) into master (b967ec5) will increase coverage by 0.62%.
The diff coverage is 98.89%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1298      +/-   ##
==========================================
+ Coverage   98.02%   98.65%   +0.62%     
==========================================
  Files         205      112      -93     
  Lines        8970     5263    -3707     
==========================================
- Hits         8793     5192    -3601     
+ Misses        177       71     -106     
Impacted Files Coverage Δ
sentry-ruby/lib/sentry/transport.rb 97.56% <ø> (-0.36%) ⬇️
sentry-ruby/spec/sentry/client_spec.rb 95.69% <ø> (-1.11%) ⬇️
sentry-ruby/lib/sentry/client.rb 97.05% <93.10%> (+0.63%) ⬆️
...ntry-ruby/spec/sentry/client/event_sending_spec.rb 99.45% <99.45%> (ø)
sentry-ruby/lib/sentry-ruby.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/background_worker.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/event.rb 98.78% <100.00%> (+0.07%) ⬆️
sentry-ruby/lib/sentry/exceptions.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/transport/http_transport.rb 100.00% <100.00%> (ø)
sentry-ruby/spec/sentry/event_spec.rb 100.00% <100.00%> (ø)
... and 99 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b967ec5...0343f1b. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sentry::Transport swallows network errors

3 participants