sentry-sdk import issue #9602

Closed
opened 2025-12-29 21:19:35 +01:00 by adam · 3 comments
Owner

Originally created by @kuhball on GitHub (May 7, 2024).

Originally assigned to: @tobiasge on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.0.0

Python Version

3.12

Steps to Reproduce

  1. Create new netbox-docker instance
  2. Enable sentry via the following lines:
SENTRY_ENABLED = False
SENTRY_DSN =""
  1. Start netbox

Expected Behavior

Netbox should start with enabled sentry.

@tobiasge already looked into this within netbox slack. This is not an issue within netbox-docker, but rather an issue created via a redesign within sentry.

Observed Behavior

Traceroute:

netbox-1               | Traceback (most recent call last):
netbox-1               |   File "/opt/netbox/netbox/./manage.py", line 10, in <module>
netbox-1               |     execute_from_command_line(sys.argv)
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
netbox-1               |     utility.execute()
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/management/__init__.py", line 382, in execute
netbox-1               |     settings.INSTALLED_APPS
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/conf/__init__.py", line 89, in __getattr__
netbox-1               |     self._setup(name)
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/conf/__init__.py", line 76, in _setup
netbox-1               |     self._wrapped = Settings(settings_module)
netbox-1               |                     ^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/conf/__init__.py", line 190, in __init__
netbox-1               |     mod = importlib.import_module(self.SETTINGS_MODULE)
netbox-1               |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
netbox-1               |     return _bootstrap._gcd_import(name[level:], package, level)
netbox-1               |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
netbox-1               |   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
netbox-1               |   File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
netbox-1               |   File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
netbox-1               |   File "<frozen importlib._bootstrap_external>", line 940, in exec_module
netbox-1               |   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
netbox-1               |   File "/opt/netbox/netbox/netbox/settings.py", line 525, in <module>
netbox-1               |     integrations=[sentry_sdk.integrations.django.DjangoIntegration()],
netbox-1               |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               | AttributeError: module 'sentry_sdk.integrations' has no attribute 'django'
Originally created by @kuhball on GitHub (May 7, 2024). Originally assigned to: @tobiasge on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.0.0 ### Python Version 3.12 ### Steps to Reproduce 1. Create new netbox-docker instance 2. Enable sentry via the following lines: ``` SENTRY_ENABLED = False SENTRY_DSN ="" ``` 3. Start netbox ### Expected Behavior Netbox should start with enabled sentry. @tobiasge already looked into this within [netbox slack](https://netdev-community.slack.com/archives/C01P0GEVBU7/p1715068607861949). This is not an issue within netbox-docker, but rather an issue created via a redesign within sentry. ### Observed Behavior Traceroute: ``` netbox-1 | Traceback (most recent call last): netbox-1 | File "/opt/netbox/netbox/./manage.py", line 10, in <module> netbox-1 | execute_from_command_line(sys.argv) netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line netbox-1 | utility.execute() netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/management/__init__.py", line 382, in execute netbox-1 | settings.INSTALLED_APPS netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/conf/__init__.py", line 89, in __getattr__ netbox-1 | self._setup(name) netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/conf/__init__.py", line 76, in _setup netbox-1 | self._wrapped = Settings(settings_module) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/conf/__init__.py", line 190, in __init__ netbox-1 | mod = importlib.import_module(self.SETTINGS_MODULE) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module netbox-1 | return _bootstrap._gcd_import(name[level:], package, level) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "<frozen importlib._bootstrap>", line 1204, in _gcd_import netbox-1 | File "<frozen importlib._bootstrap>", line 1176, in _find_and_load netbox-1 | File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked netbox-1 | File "<frozen importlib._bootstrap>", line 690, in _load_unlocked netbox-1 | File "<frozen importlib._bootstrap_external>", line 940, in exec_module netbox-1 | File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed netbox-1 | File "/opt/netbox/netbox/netbox/settings.py", line 525, in <module> netbox-1 | integrations=[sentry_sdk.integrations.django.DjangoIntegration()], netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | AttributeError: module 'sentry_sdk.integrations' has no attribute 'django' ```
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 21:19:35 +01:00
adam closed this issue 2025-12-29 21:19:35 +01:00
Author
Owner

@tobiasge commented on GitHub (May 7, 2024):

Form our Slack conversation:
Could be fixed with this

diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py
index 53eaffed5..355ff9f58 100644
--- a/netbox/netbox/settings.py
+++ b/netbox/netbox/settings.py
@@ -514,6 +514,7 @@ MAINTENANCE_EXEMPT_PATHS = (
 if SENTRY_ENABLED:
     try:
         import sentry_sdk
+        from sentry_sdk.integrations.django import DjangoIntegration
     except ModuleNotFoundError:
         raise ImproperlyConfigured("SENTRY_ENABLED is True but the sentry-sdk package is not installed.")
     if not SENTRY_DSN:
@@ -522,7 +523,7 @@ if SENTRY_ENABLED:
     sentry_sdk.init(
         dsn=SENTRY_DSN,
         release=VERSION,
-        integrations=[sentry_sdk.integrations.django.DjangoIntegration()],
+        integrations=[DjangoIntegration()],
         sample_rate=SENTRY_SAMPLE_RATE,
         traces_sample_rate=SENTRY_TRACES_SAMPLE_RATE,
         send_default_pii=True,

or by removing the integrations= completely.

@tobiasge commented on GitHub (May 7, 2024): Form our Slack conversation: Could be fixed with this ```patch diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 53eaffed5..355ff9f58 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -514,6 +514,7 @@ MAINTENANCE_EXEMPT_PATHS = ( if SENTRY_ENABLED: try: import sentry_sdk + from sentry_sdk.integrations.django import DjangoIntegration except ModuleNotFoundError: raise ImproperlyConfigured("SENTRY_ENABLED is True but the sentry-sdk package is not installed.") if not SENTRY_DSN: @@ -522,7 +523,7 @@ if SENTRY_ENABLED: sentry_sdk.init( dsn=SENTRY_DSN, release=VERSION, - integrations=[sentry_sdk.integrations.django.DjangoIntegration()], + integrations=[DjangoIntegration()], sample_rate=SENTRY_SAMPLE_RATE, traces_sample_rate=SENTRY_TRACES_SAMPLE_RATE, send_default_pii=True, ``` or by removing the `integrations=` completely.
Author
Owner

@jeremystretch commented on GitHub (May 7, 2024):

Thanks for digging into this. I wasn't able to immediately track down the responsible change, but it's likely from the recent v2.0 release a couple weeks ago.

@jeremystretch commented on GitHub (May 7, 2024): Thanks for digging into this. I wasn't able to immediately track down the responsible change, but it's likely from the recent v2.0 release a couple weeks ago.
Author
Owner

@tobiasge commented on GitHub (May 7, 2024):

I created the PR #15998 to fix this.

@tobiasge commented on GitHub (May 7, 2024): I created the PR #15998 to fix this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9602