Skip to content

Commit

Permalink
Properly configure (or not) bugsnag
Browse files Browse the repository at this point in the history
  • Loading branch information
przemub committed Nov 23, 2024
1 parent 800ddfd commit ce9c8a5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
16 changes: 16 additions & 0 deletions anime_quiz/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
"class": "logging.StreamHandler",
"formatter": "default",
},
"bugsnag": {
"level": "WARNING",
"class": "bugsnag.handlers.BugsnagHandler",
"formatter": "default",
},
},
"formatters": {
"default": {
Expand Down Expand Up @@ -181,5 +186,16 @@

INTERNAL_IPS = os.getenv("INTERNAL_IPS", "192.168.1.1").split(",")

BUGSNAG = None
if "QUIZ_BUGSNAG" in os.environ:
BUGSNAG = {
"api_key": os.environ["QUIZ_BUGSNAG"],
"project_root": "/usr/src/app",
"ignore_classes": ["django.http.Http404"],
"release_stage": "development"
}
LOGGING["loggers"]["root"]["handlers"].append("bugsnag")
MIDDLEWARE.append("bugsnag.django.middleware.BugsnagMiddleware")

# Redis database used as a queue for tasks.
QUEUE_DB = "redis://redis:6379/1"
18 changes: 2 additions & 16 deletions anime_quiz/settings_prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,5 @@
else:
raise Exception("QUIZ_SECRET_KEY environment variable is not set!")

if os.environ.get("QUIZ_BUGSNAG", None):
BUGSNAG = {
"api_key": os.environ["QUIZ_BUGSNAG"],
"project_root": "/usr/src/app",
"ignore_classes": ["django.http.Http404"],
"release_stage": "production"
}

LOGGING["handlers"]["bugsnag"] = {
"level": "INFO",
"class": "bugsnag.handlers.BugsnagHandler",
"formatter": "default",
}
LOGGING["loggers"]["root"]["handlers"].append("bugsnag")

MIDDLEWARE += ["bugsnag.django.middleware.BugsnagMiddleware"]
if BUGSNAG is not None:
BUGSNAG["release_stage"] = "production"
4 changes: 3 additions & 1 deletion quiz/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def listen_for_tasks(self) -> NoReturn:
self.name,
kwargs
)
if settings.get("BUGSNAG"):
if settings.BUGSNAG is not None:
bugsnag.notify(e)
else:
logger.info(
Expand Down Expand Up @@ -211,6 +211,8 @@ def listen_for_tasks():

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "anime_quiz.settings")
django.setup()
if settings.BUGSNAG is not None:
bugsnag.configure(**settings.BUGSNAG)

try:
listen_for_tasks()
Expand Down

0 comments on commit ce9c8a5

Please sign in to comment.