Skip to content

Commit

Permalink
setup sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Mar 26, 2024
1 parent 474ac83 commit e9ea91c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
-e git+https://github.com/GeoNode/geonode-importer.git@master#egg=geonode-importer
-e git+https://github.com/GeoNode/geonode.git@master#egg=GeoNode

git+https://github.com/adilhussain540/django-media-fixtures@django-4-fixes
git+https://github.com/adilhussain540/django-media-fixtures@django-4-fixes

sentry-sdk
sentry-sdk[celery]
sentry-sdk[django]
41 changes: 41 additions & 0 deletions src/urban/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,44 @@
INSTALLED_APPS += (
'django_media_fixtures',
)


SENTRY_DSN = os.getenv("SENTRY_DSN", None)
if SENTRY_DSN:
import logging
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.logging import LoggingIntegration
from sentry_sdk.integrations.redis import RedisIntegration
from sentry_sdk.integrations.celery import CeleryIntegration

SENTRY_LOG_LEVEL = int(os.getenv("DJANGO_SENTRY_LOG_LEVEL", logging.INFO))

sentry_logging = LoggingIntegration(
level=SENTRY_LOG_LEVEL, # Capture info and above as breadcrumbs
event_level=logging.ERROR, # Send errors as events
)

integrations = [sentry_logging, DjangoIntegration(), RedisIntegration(), CeleryIntegration()]

sentry_sdk.init(
dsn=SENTRY_DSN,
integrations=integrations,
environment=os.getenv("SENTRY_ENVIRONMENT", "production"),
traces_sample_rate=float(os.getenv("SENTRY_TRACES_SAMPLE_RATE", 0.1)),
)

LOGGING["loggers"] = {
"django.db.backends": {
"level": "ERROR",
"handlers": ["console"],
"propagate": False,
},
# Errors logged by the SDK itself
"sentry_sdk": {"level": "ERROR", "handlers": ["console"], "propagate": False},
"django.security.DisallowedHost": {
"level": "ERROR",
"handlers": ["console"],
"propagate": False,
},
}

0 comments on commit e9ea91c

Please sign in to comment.