getsentry / raven-python

Raven is the legacy Python client for Sentry (getsentry.com) — replaced by sentry-python
https://sentry.io
BSD 3-Clause "New" or "Revised" License
1.68k stars 657 forks source link

How to handle exceptions in raven itself? #1173

Open ralienpp opened 6 years ago

ralienpp commented 6 years ago

I ran into the following situation - the software crashed, raven rightfully stepped in and prepared a report to be sent to Sentry. However, the system where the client was running was experiencing Internet connectivity issues - thus raven itself crashed.


ERROR sentry.errors Sentry responded with an error: <urlopen error [Errno -2] Name or service not known> (url: https://example.com/api/3/store/)
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/raven/transport/threaded.py", line 165, in send_sync
super(ThreadedHTTPTransport, self).send(url, data, headers)
File "/usr/local/lib/python2.7/dist-packages/raven/transport/http.py", line 43, in send
ca_certs=self.ca_certs,
File "/usr/local/lib/python2.7/dist-packages/raven/utils/http.py", line 66, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/usr/local/lib/python2.7/dist-packages/raven/utils/http.py", line 46, in https_open
return self.do_open(ValidHTTPSConnection, req)
File "/usr/lib/python2.7/urllib2.py", line 1197, in do_open
raise URLError(err)
URLError: <urlopen error [Errno -2] Name or service not known>
ERROR sentry.errors.uncaught ]

Is there a way to define a handler for these situations? Or otherwise configure raven to try later or just ignore it? I have not found any discussion of these aspects in the documentation.

This is how I am using the software:

from sentry import Client
sentry_client = Client('https://xxxxxxxxxxxx')

# lots of other code
ashwoods commented 6 years ago

Currently raven logs internal errors to raven.errors and afaik will not propagate to the Sentry handler, and in theory should handle all errors, but some sneak in anyways. :)

ralienpp commented 6 years ago

I have looked into the code in an attempt to update the library myself and address this problem. I am wondering why this is happening though, because there is a "catch-all" exception handler that wraps the send_sync function: https://github.com/getsentry/raven-python/blob/master/raven/transport/threaded.py#L165

Is there a document that describes the architecture of the client, so I can get a better idea of what happens under the hood?