|
8 | 8 | import warnings |
9 | 9 | from urllib.parse import urlsplit |
10 | 10 |
|
| 11 | +import sentry_sdk |
11 | 12 | from django.contrib.messages import constants as messages |
12 | 13 | from django.core.exceptions import ImproperlyConfigured, ValidationError |
13 | 14 | from django.core.validators import URLValidator |
| 15 | +from sentry_sdk.integrations.django import DjangoIntegration |
14 | 16 |
|
15 | 17 | from netbox.config import PARAMS |
16 | 18 |
|
|
113 | 115 | REPORTS_ROOT = getattr(configuration, 'REPORTS_ROOT', os.path.join(BASE_DIR, 'reports')).rstrip('/') |
114 | 116 | RQ_DEFAULT_TIMEOUT = getattr(configuration, 'RQ_DEFAULT_TIMEOUT', 300) |
115 | 117 | SCRIPTS_ROOT = getattr(configuration, 'SCRIPTS_ROOT', os.path.join(BASE_DIR, 'scripts')).rstrip('/') |
| 118 | +SENTRY_DSN = getattr(configuration, 'SENTRY_DSN', None) |
| 119 | +SENTRY_ENABLED = getattr(configuration, 'SENTRY_ENABLED', False) |
| 120 | +SENTRY_TAGS = getattr(configuration, 'SENTRY_TAGS', {}) |
116 | 121 | SESSION_FILE_PATH = getattr(configuration, 'SESSION_FILE_PATH', None) |
117 | 122 | SESSION_COOKIE_NAME = getattr(configuration, 'SESSION_COOKIE_NAME', 'sessionid') |
118 | 123 | SHORT_DATE_FORMAT = getattr(configuration, 'SHORT_DATE_FORMAT', 'Y-m-d') |
@@ -428,6 +433,26 @@ def _setting(name, default=None): |
428 | 433 | ) |
429 | 434 |
|
430 | 435 |
|
| 436 | +# |
| 437 | +# Sentry |
| 438 | +# |
| 439 | + |
| 440 | +if SENTRY_ENABLED: |
| 441 | + if not SENTRY_DSN: |
| 442 | + raise ImproperlyConfigured("SENTRY_ENABLED is True but SENTRY_DSN has not been defined.") |
| 443 | + sentry_sdk.init( |
| 444 | + dsn=SENTRY_DSN, |
| 445 | + release=VERSION, |
| 446 | + integrations=[DjangoIntegration()], |
| 447 | + traces_sample_rate=1.0, |
| 448 | + send_default_pii=True, |
| 449 | + http_proxy=HTTP_PROXIES.get('http') if HTTP_PROXIES else None, |
| 450 | + https_proxy=HTTP_PROXIES.get('https') if HTTP_PROXIES else None |
| 451 | + ) |
| 452 | + for k, v in SENTRY_TAGS.items(): |
| 453 | + sentry_sdk.set_tag(k, v) |
| 454 | + |
| 455 | + |
431 | 456 | # |
432 | 457 | # Django social auth |
433 | 458 | # |
|
0 commit comments