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():
21
21
- `DedupeIntegration`
22
22
- `AtexitIntegration`
23
23
- `ModulesIntegration`
24
+ - `ArgvIntegration`
24
25
"""
25
26
from sentry_sdk .integrations .logging import LoggingIntegration
26
27
from sentry_sdk .integrations .stdlib import StdlibIntegration
27
28
from sentry_sdk .integrations .excepthook import ExcepthookIntegration
28
29
from sentry_sdk .integrations .dedupe import DedupeIntegration
29
30
from sentry_sdk .integrations .atexit import AtexitIntegration
30
31
from sentry_sdk .integrations .modules import ModulesIntegration
32
+ from sentry_sdk .integrations .argv import ArgvIntegration
31
33
32
34
yield LoggingIntegration
33
35
yield StdlibIntegration
34
36
yield ExcepthookIntegration
35
37
yield DedupeIntegration
36
38
yield AtexitIntegration
37
39
yield ModulesIntegration
40
+ yield ArgvIntegration
38
41
39
42
40
43
def 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