Coverage for gwcelery/sentry/integrations/subprocess.py: 32%
22 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 subprocess import CalledProcessError
3from sentry_sdk.integrations import Integration
4from sentry_sdk.scope import add_global_event_processor
7class SubprocessIntegration(Integration):
8 """Capture stderr and stdout from CalledProcessError exceptions."""
10 identifier = 'subprocess'
12 @staticmethod
13 def setup_once():
15 @add_global_event_processor
16 def capture(event, hint):
17 if 'exc_info' not in hint:
18 return event
20 _, e, _ = hint['exc_info']
21 if not isinstance(e, CalledProcessError):
22 return event
24 breadcrumbs = event.get('breadcrumbs')
25 if not breadcrumbs:
26 return event
28 data = breadcrumbs[-1].setdefault('data', {})
29 for key in ['stderr', 'stdout']:
30 value = getattr(e, key)
31 data[key] = value.decode(errors='replace')
33 return event