0

I am using Sentry to power up exception handling logging in my app.

The issue arises in the following code snippet:

@api_view(['POST'])
def testView(request):
    a = 1/0 # This error is reported to Sentry
    TestThread().start()
    return f_response_ok()

class TestThread(threading.Thread):

    def __init__(self, *args, **kwargs):
        super(TestThread, self).__init__(*args, **kwargs)

    def run(self):
        print('Test')
        a = 1/0 # but this one is not
        return True

Is it possible to make Sentry report errors that have occurred in parallel thread?

And a bit off-topic: I would appreciate if someone provides a short comment as to whether such programming pattern is obsolete (and stuff like RabbitMQ should be used instead).

Edgar Navasardyan
  • 4,261
  • 8
  • 58
  • 121

1 Answers1

3

You could manually log them to sentry.

https://docs.sentry.io/clients/python/#capture-an-error

Assuming you are using django

from raven.contrib.django.raven_compat.models import client

class TestThread(threading.Thread):

    def __init__(self, *args, **kwargs):
        super(TestThread, self).__init__(*args, **kwargs)

    def run(self):
        print('Test')
        try:
            a = 1/0 # error is not reported in Sentry
        except: # I would suggest putting here expected exceptions
            client.captureException()
        return True
Sardorbek Imomaliev
  • 14,861
  • 2
  • 51
  • 63
  • This is extremely useful hint, Sardorbek. You solved one more related issue for me. Thanks !!! I will wait for a while. And unless I get more generic answer, will accept this one as solution – Edgar Navasardyan Jun 05 '18 at 14:51