Skip to content

Commit

Permalink
Merge branch 'dbca-wa:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
RickWangPerth authored Jul 16, 2024
2 parents 75e68fc + 63484e4 commit 4866444
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
6 changes: 5 additions & 1 deletion observations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,11 @@ def opts(self):
return self._meta

def __str__(self):
return f"Encounter {self.pk} on {self.when} by {self.observer}"
when = self.when.astimezone(settings.TZ).strftime("%d-%b-%Y %H:%M")
if self.encounter_type:
return f"{self.get_encounter_type_display().capitalize()} encounter on {when} by {self.observer.name}"
else:
return f"Encounter {self.pk} on {when} by {self.observer.name}"

@property
def status_colour(self):
Expand Down
22 changes: 21 additions & 1 deletion wastd/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from dbca_utils.utils import env
from django.core.exceptions import DisallowedHost
from django.db.utils import OperationalError
import dj_database_url
import os
from pathlib import Path
Expand Down Expand Up @@ -299,7 +301,24 @@
}


# Sentry settings
def sentry_excluded_exceptions(event, hint):
"""Exclude defined class(es) of Exception from being reported to Sentry.
These exception classes are generally related to operational or configuration issues,
and they are not errors that we want to capture.
https://docs.sentry.io/platforms/python/configuration/filtering/#filtering-error-events
"""
if "exc_info" in hint and hint["exc_info"]:
# Exclude database-related errors (connection error, timeout, DNS failure, etc.)
if hint["exc_info"][0] is OperationalError:
return None
# Exclude exceptions related to host requests not in ALLOWED_HOSTS.
elif hint["exc_info"][0] is DisallowedHost:
return None

return event


# Sentry config
SENTRY_DSN = env("SENTRY_DSN", None)
SENTRY_SAMPLE_RATE = env("SENTRY_SAMPLE_RATE", 1.0) # Error sampling rate
SENTRY_TRANSACTION_SAMPLE_RATE = env("SENTRY_TRANSACTION_SAMPLE_RATE", 0.0) # Transaction sampling
Expand All @@ -315,4 +334,5 @@
profiles_sample_rate=SENTRY_PROFILES_SAMPLE_RATE,
environment=SENTRY_ENVIRONMENT,
release=VERSION_NO,
before_send=sentry_excluded_exceptions,
)

0 comments on commit 4866444

Please sign in to comment.