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
« 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
6class RequestsIntegration(Integration):
7 """Sentry integration to capture detail about HTTP errors from requests."""
9 identifier = 'requests'
11 @staticmethod
12 def setup_once():
14 @add_global_event_processor
15 def capture(event, hint):
16 if 'exc_info' not in hint:
17 return event
19 _, e, _ = hint['exc_info']
20 if not isinstance(e, HTTPError):
21 return event
23 breadcrumbs = event.get('breadcrumbs')
24 if not breadcrumbs:
25 return event
27 data = breadcrumbs[-1].setdefault('data', {})
28 data['response'] = e.response.text
30 return event