File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed
tests/integrations/modules Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -23,12 +23,14 @@ def get_default_integrations():
23
23
from sentry_sdk .integrations .excepthook import ExcepthookIntegration
24
24
from sentry_sdk .integrations .dedupe import DedupeIntegration
25
25
from sentry_sdk .integrations .atexit import AtexitIntegration
26
+ from sentry_sdk .integrations .modules import ModulesIntegration
26
27
27
28
yield LoggingIntegration ()
28
29
yield StdlibIntegration ()
29
30
yield ExcepthookIntegration ()
30
31
yield DedupeIntegration ()
31
32
yield AtexitIntegration ()
33
+ yield ModulesIntegration ()
32
34
33
35
34
36
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
+ from sentry_sdk .api import configure_scope
4
+ from sentry_sdk .integrations import Integration
5
+
6
+ _installed_modules = None
7
+
8
+
9
+ def _generate_installed_modules ():
10
+ try :
11
+ import pkg_resources
12
+ except ImportError :
13
+ return
14
+
15
+ for info in pkg_resources .working_set :
16
+ yield info .key , info .version
17
+
18
+
19
+ def _get_installed_modules ():
20
+ global _installed_modules
21
+ if _installed_modules is None :
22
+ _installed_modules = dict (_generate_installed_modules ())
23
+ return _installed_modules
24
+
25
+
26
+ class ModulesIntegration (Integration ):
27
+ identifier = "modules"
28
+
29
+ def install (self ):
30
+ with configure_scope () as scope :
31
+
32
+ @scope .add_event_processor
33
+ def processor (event , hint ):
34
+ if "modules" not in event :
35
+ event ["modules" ] = dict (_get_installed_modules ())
36
+ return event
Original file line number Diff line number Diff line change
1
+ import sentry_sdk
2
+
3
+ from sentry_sdk .integrations .modules import ModulesIntegration
4
+
5
+
6
+ def test_basic (sentry_init , capture_events ):
7
+ sentry_init (integrations = [ModulesIntegration ()])
8
+ events = capture_events ()
9
+
10
+ sentry_sdk .capture_exception (ValueError ())
11
+
12
+ event , = events
13
+ assert "sentry-sdk" in event ["modules" ]
14
+ assert "pytest" in event ["modules" ]
You can’t perform that action at this time.
0 commit comments