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():
2323 from sentry_sdk .integrations .excepthook import ExcepthookIntegration
2424 from sentry_sdk .integrations .dedupe import DedupeIntegration
2525 from sentry_sdk .integrations .atexit import AtexitIntegration
26+ from sentry_sdk .integrations .modules import ModulesIntegration
2627
2728 yield LoggingIntegration ()
2829 yield StdlibIntegration ()
2930 yield ExcepthookIntegration ()
3031 yield DedupeIntegration ()
3132 yield AtexitIntegration ()
33+ yield ModulesIntegration ()
3234
3335
3436def 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