Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python : How can I test that my error has been logged on sentry?

I have integrate my python default logger with raven . Now my errors are being logged on sentry.io/my_app. But I wanted to ask is there any way we can write unit tests for this function that generates an error and then somehow confirm that this error exits on sentry.

like image 747
M. Zulqarnain Avatar asked May 22 '17 11:05

M. Zulqarnain


1 Answers

In Raven-Python you can implement a custom transport to swap out the HTTP request for a simple callback. This is done by implementing an abstract class for which there does not exist a lot of documentation unfortunately and the data you get is a bytestring of json-encoded data. You can find the abstract class here: https://github.com/getsentry/raven-python/blob/285b257cf386bfac78f6fe334c9044af65f98561/raven/transport/base.py#L26

This is slightly easier in the new SDK where you can write (without providing a DSN):

events = []
init(transport=events.append)

to collect events into an array instead of sending them to a server.

like image 161
Markus Unterwaditzer Avatar answered Oct 05 '22 12:10

Markus Unterwaditzer