File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -21,20 +21,23 @@ def iter_default_integrations():
2121 - `DedupeIntegration`
2222 - `AtexitIntegration`
2323 - `ModulesIntegration`
24+ - `ArgvIntegration`
2425 """
2526 from sentry_sdk .integrations .logging import LoggingIntegration
2627 from sentry_sdk .integrations .stdlib import StdlibIntegration
2728 from sentry_sdk .integrations .excepthook import ExcepthookIntegration
2829 from sentry_sdk .integrations .dedupe import DedupeIntegration
2930 from sentry_sdk .integrations .atexit import AtexitIntegration
3031 from sentry_sdk .integrations .modules import ModulesIntegration
32+ from sentry_sdk .integrations .argv import ArgvIntegration
3133
3234 yield LoggingIntegration
3335 yield StdlibIntegration
3436 yield ExcepthookIntegration
3537 yield DedupeIntegration
3638 yield AtexitIntegration
3739 yield ModulesIntegration
40+ yield ArgvIntegration
3841
3942
4043def setup_integrations (integrations , with_defaults = True ):
Original file line number Diff line number Diff line change 1+ from __future__ import absolute_import
2+
3+ import sys
4+
5+ from sentry_sdk .hub import Hub
6+ from sentry_sdk .integrations import Integration
7+ from sentry_sdk .scope import add_global_event_processor
8+
9+
10+ class ArgvIntegration (Integration ):
11+ identifier = "argv"
12+
13+ @staticmethod
14+ def setup_once ():
15+ @add_global_event_processor
16+ def processor (event , hint ):
17+ if Hub .current .get_integration (ArgvIntegration ) is not None :
18+ extra = event .setdefault ("extra" , {})
19+ # If some event processor decided to set extra to e.g. an
20+ # `int`, don't crash. Not here.
21+ if isinstance (extra , dict ):
22+ extra ["sys.argv" ] = sys .argv
23+
24+ return event
Original file line number Diff line number Diff line change 1+ import sys
2+
3+ from sentry_sdk import capture_message
4+ from sentry_sdk .integrations .argv import ArgvIntegration
5+
6+
7+ def test_basic (sentry_init , capture_events , monkeypatch ):
8+ sentry_init (integrations = [ArgvIntegration ()])
9+
10+ argv = ["foo" , "bar" , "baz" ]
11+ monkeypatch .setattr (sys , "argv" , argv )
12+
13+ events = capture_events ()
14+ capture_message ("hi" )
15+ event , = events
16+ assert event ["extra" ]["sys.argv" ] == argv
You can’t perform that action at this time.
0 commit comments