-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
3d20276
commit 840b7d8
Showing
7 changed files
with
29 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,27 +4,15 @@ | |
|
||
### Enabling Error Reporting | ||
|
||
NetBox supports native integration with [Sentry](https://sentry.io/) for automatic error reporting. To enable this functionality, simply set `SENTRY_ENABLED` to True in `configuration.py`. Errors will be sent to a Sentry ingestor maintained by the NetBox team for analysis. | ||
|
||
```python | ||
SENTRY_ENABLED = True | ||
``` | ||
|
||
### Using a Custom DSN | ||
|
||
If you prefer instead to use your own Sentry ingestor, you'll need to first create a new project under your Sentry account to represent your NetBox deployment and obtain its corresponding data source name (DSN). This looks like a URL similar to the example below: | ||
|
||
``` | ||
https://[email protected]/0 | ||
``` | ||
|
||
Once you have obtained a DSN, configure Sentry in NetBox's `configuration.py` file with the following parameters: | ||
NetBox supports native integration with [Sentry](https://sentry.io/) for automatic error reporting. To enable this functionality, set `SENTRY_ENABLED` to True and define your unique [data source name (DSN)](https://docs.sentry.io/product/sentry-basics/concepts/dsn-explainer/) in `configuration.py`. | ||
|
||
```python | ||
SENTRY_ENABLED = True | ||
SENTRY_DSN = "https://[email protected]/0" | ||
``` | ||
|
||
Setting `SENTRY_ENABLED` to False will disable the Sentry integration. | ||
|
||
### Assigning Tags | ||
|
||
You can optionally attach one or more arbitrary tags to the outgoing error reports if desired by setting the `SENTRY_TAGS` parameter: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,14 @@ | |
from urllib.parse import urlencode, urlsplit | ||
|
||
import django | ||
import sentry_sdk | ||
from django.contrib.messages import constants as messages | ||
from django.core.exceptions import ImproperlyConfigured, ValidationError | ||
from django.core.validators import URLValidator | ||
from django.utils.encoding import force_str | ||
from sentry_sdk.integrations.django import DjangoIntegration | ||
try: | ||
import sentry_sdk | ||
except ModuleNotFoundError: | ||
pass | ||
|
||
from netbox.config import PARAMS | ||
from netbox.constants import RQ_QUEUE_DEFAULT, RQ_QUEUE_HIGH, RQ_QUEUE_LOW | ||
|
@@ -39,8 +41,6 @@ | |
f"NetBox requires Python 3.8 or later. (Currently installed: Python {platform.python_version()})" | ||
) | ||
|
||
DEFAULT_SENTRY_DSN = 'https://[email protected]/6396485' | ||
|
||
# | ||
# Configuration import | ||
# | ||
|
@@ -158,7 +158,7 @@ | |
SCRIPTS_ROOT = getattr(configuration, 'SCRIPTS_ROOT', os.path.join(BASE_DIR, 'scripts')).rstrip('/') | ||
SEARCH_BACKEND = getattr(configuration, 'SEARCH_BACKEND', 'netbox.search.backends.CachedValueSearchBackend') | ||
SECURE_SSL_REDIRECT = getattr(configuration, 'SECURE_SSL_REDIRECT', False) | ||
SENTRY_DSN = getattr(configuration, 'SENTRY_DSN', DEFAULT_SENTRY_DSN) | ||
SENTRY_DSN = getattr(configuration, 'SENTRY_DSN', None) | ||
SENTRY_ENABLED = getattr(configuration, 'SENTRY_ENABLED', False) | ||
SENTRY_SAMPLE_RATE = getattr(configuration, 'SENTRY_SAMPLE_RATE', 1.0) | ||
SENTRY_TRACES_SAMPLE_RATE = getattr(configuration, 'SENTRY_TRACES_SAMPLE_RATE', 0) | ||
|
@@ -517,12 +517,12 @@ def _setting(name, default=None): | |
# | ||
|
||
if SENTRY_ENABLED: | ||
try: | ||
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: | ||
raise ImproperlyConfigured("SENTRY_ENABLED is True but SENTRY_DSN has not been defined.") | ||
# If using the default DSN, force sampling rates | ||
if SENTRY_DSN == DEFAULT_SENTRY_DSN: | ||
SENTRY_SAMPLE_RATE = 1.0 | ||
SENTRY_TRACES_SAMPLE_RATE = 0 | ||
# Initialize the SDK | ||
sentry_sdk.init( | ||
dsn=SENTRY_DSN, | ||
|
@@ -537,9 +537,6 @@ def _setting(name, default=None): | |
# Assign any configured tags | ||
for k, v in SENTRY_TAGS.items(): | ||
sentry_sdk.set_tag(k, v) | ||
# If using the default DSN, append a unique deployment ID tag for error correlation | ||
if SENTRY_DSN == DEFAULT_SENTRY_DSN: | ||
sentry_sdk.set_tag('netbox.deployment_id', DEPLOYMENT_ID) | ||
|
||
|
||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters