Coverage for gwcelery/sentry/integrations/requests.py: 35%

20 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-11-14 05:52 +0000

1from requests.exceptions import HTTPError 

2from sentry_sdk.integrations import Integration 

3from sentry_sdk.scope import add_global_event_processor 

4 

5 

6class RequestsIntegration(Integration): 

7 """Sentry integration to capture detail about HTTP errors from requests.""" 

8 

9 identifier = 'requests' 

10 

11 @staticmethod 

12 def setup_once(): 

13 

14 @add_global_event_processor 

15 def capture(event, hint): 

16 if 'exc_info' not in hint: 

17 return event 

18 

19 _, e, _ = hint['exc_info'] 

20 if not isinstance(e, HTTPError): 

21 return event 

22 

23 breadcrumbs = event.get('breadcrumbs') 

24 if not breadcrumbs: 

25 return event 

26 

27 data = breadcrumbs[-1].setdefault('data', {}) 

28 data['response'] = e.response.text 

29 

30 return event