|
176 | 176 | SECURE_HSTS_PRELOAD = getattr(configuration, 'SECURE_HSTS_PRELOAD', False) |
177 | 177 | SECURE_HSTS_SECONDS = getattr(configuration, 'SECURE_HSTS_SECONDS', 0) |
178 | 178 | SECURE_SSL_REDIRECT = getattr(configuration, 'SECURE_SSL_REDIRECT', False) |
| 179 | +SENTRY_CONFIG = getattr(configuration, 'SENTRY_CONFIG', {}) |
| 180 | +# TODO: Remove in NetBox v4.5 |
179 | 181 | SENTRY_DSN = getattr(configuration, 'SENTRY_DSN', None) |
180 | 182 | SENTRY_ENABLED = getattr(configuration, 'SENTRY_ENABLED', False) |
| 183 | +# TODO: Remove in NetBox v4.5 |
181 | 184 | SENTRY_SAMPLE_RATE = getattr(configuration, 'SENTRY_SAMPLE_RATE', 1.0) |
| 185 | +# TODO: Remove in NetBox v4.5 |
182 | 186 | SENTRY_SEND_DEFAULT_PII = getattr(configuration, 'SENTRY_SEND_DEFAULT_PII', False) |
183 | 187 | SENTRY_TAGS = getattr(configuration, 'SENTRY_TAGS', {}) |
| 188 | +# TODO: Remove in NetBox v4.5 |
184 | 189 | SENTRY_TRACES_SAMPLE_RATE = getattr(configuration, 'SENTRY_TRACES_SAMPLE_RATE', 0) |
185 | 190 | SESSION_COOKIE_NAME = getattr(configuration, 'SESSION_COOKIE_NAME', 'sessionid') |
186 | 191 | SESSION_COOKIE_PATH = CSRF_COOKIE_PATH |
@@ -598,18 +603,29 @@ def _setting(name, default=None): |
598 | 603 | import sentry_sdk |
599 | 604 | except ModuleNotFoundError: |
600 | 605 | raise ImproperlyConfigured("SENTRY_ENABLED is True but the sentry-sdk package is not installed.") |
601 | | - if not SENTRY_DSN: |
602 | | - raise ImproperlyConfigured("SENTRY_ENABLED is True but SENTRY_DSN has not been defined.") |
| 606 | + |
| 607 | + # Construct default Sentry initialization parameters from legacy SENTRY_* config parameters |
| 608 | + sentry_config = { |
| 609 | + 'dsn': SENTRY_DSN, |
| 610 | + 'sample_rate': SENTRY_SAMPLE_RATE, |
| 611 | + 'send_default_pii': SENTRY_SEND_DEFAULT_PII, |
| 612 | + 'traces_sample_rate': SENTRY_TRACES_SAMPLE_RATE, |
| 613 | + # TODO: Support proxy routing |
| 614 | + 'http_proxy': HTTP_PROXIES.get('http') if HTTP_PROXIES else None, |
| 615 | + 'https_proxy': HTTP_PROXIES.get('https') if HTTP_PROXIES else None, |
| 616 | + } |
| 617 | + # Override/extend the default parameters with any provided via SENTRY_CONFIG |
| 618 | + sentry_config.update(SENTRY_CONFIG) |
| 619 | + # Check for a DSN |
| 620 | + if not sentry_config.get('dsn'): |
| 621 | + raise ImproperlyConfigured( |
| 622 | + "Sentry is enabled but a DSN has not been specified. Set one under the SENTRY_CONFIG parameter." |
| 623 | + ) |
| 624 | + |
603 | 625 | # Initialize the SDK |
604 | 626 | sentry_sdk.init( |
605 | | - dsn=SENTRY_DSN, |
606 | 627 | release=RELEASE.full_version, |
607 | | - sample_rate=SENTRY_SAMPLE_RATE, |
608 | | - traces_sample_rate=SENTRY_TRACES_SAMPLE_RATE, |
609 | | - send_default_pii=SENTRY_SEND_DEFAULT_PII, |
610 | | - # TODO: Support proxy routing |
611 | | - http_proxy=HTTP_PROXIES.get('http') if HTTP_PROXIES else None, |
612 | | - https_proxy=HTTP_PROXIES.get('https') if HTTP_PROXIES else None |
| 628 | + **sentry_config |
613 | 629 | ) |
614 | 630 | # Assign any configured tags |
615 | 631 | for k, v in SENTRY_TAGS.items(): |
|
0 commit comments