Skip to content

Commit

Permalink
Add sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
JPolonia committed Apr 7, 2022
1 parent 1f1cd41 commit 7862820
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
47 changes: 33 additions & 14 deletions config/settings/production.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
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 .base import * # noqa
from .base import env

Expand Down Expand Up @@ -105,40 +112,52 @@
# the site admins on every HTTP 500 error when DEBUG=False.
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"filters": {"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}},
"disable_existing_loggers": True,
"formatters": {
"verbose": {
"format": "%(levelname)s %(asctime)s %(module)s "
"%(process)d %(thread)d %(message)s"
}
},
"handlers": {
"mail_admins": {
"level": "ERROR",
"filters": ["require_debug_false"],
"class": "django.utils.log.AdminEmailHandler",
},
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "verbose",
},
}
},
"root": {"level": "INFO", "handlers": ["console"]},
"loggers": {
"django.request": {
"handlers": ["mail_admins"],
"django.db.backends": {
"level": "ERROR",
"propagate": True,
"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", "mail_admins"],
"propagate": True,
"handlers": ["console"],
"propagate": False,
},
},
}

# Your stuff...
# Sentry
# ------------------------------------------------------------------------------
SENTRY_DSN = env("SENTRY_DSN")
SENTRY_LOG_LEVEL = env.int("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()]

sentry_sdk.init(
dsn=SENTRY_DSN,
integrations=integrations,
environment=env("SENTRY_ENVIRONMENT", default="production"),
traces_sample_rate=env.float("SENTRY_TRACES_SAMPLE_RATE", default=0.0),
)
1 change: 1 addition & 0 deletions requirements/production.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

gunicorn==20.1.0 # https://github.com/benoitc/gunicorn
psycopg2==2.9.3 # https://github.com/psycopg/psycopg2
sentry-sdk==1.5.8 # https://github.com/getsentry/sentry-python

# Django
# ------------------------------------------------------------------------------
Expand Down

0 comments on commit 7862820

Please sign in to comment.