Skip to content

Commit

Permalink
set up sentry integration
Browse files Browse the repository at this point in the history
  • Loading branch information
fgregg committed Aug 12, 2024
1 parent a90c280 commit 6ce07d2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
34 changes: 30 additions & 4 deletions camp_fin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,41 @@
ALLOWED_HOSTS = allowed_hosts.split(",") if allowed_hosts else []

# Configure Sentry for error logging
if os.getenv("SENTRY_DSN"):
SENTRY_DSN = os.getenv("SENTRY_DSN")

if SENTRY_DSN:
import logging

import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.logging import LoggingIntegration

sentry_sdk.init(
dsn=os.environ["SENTRY_DSN"],
integrations=[DjangoIntegration()],
def custom_sampler(ctx):
if "wsgi_environ" in ctx:
path = ctx["wsgi_environ"].get("PATH_INFO", "")
# Don't trace performance of static assets
if path.startswith("/static/"):
return 0

# Sample other pages at 5% rate
return 0.05

sentry_logging = LoggingIntegration(
level=logging.INFO, # Capture info and above as breadcrumbs
event_level=logging.WARNING, # Send warnings and above as events
)

sentry_sdk.init(
dsn=SENTRY_DSN,
integrations=[DjangoIntegration(), sentry_logging],
# If you wish to associate users to errors (assuming you are using
# django.contrib.auth) you may enable sending PII data.
send_default_pii=True,
release=f"{os.environ['HEROKU_RELEASE_VERSION']}-{os.environ['HEROKU_APP_NAME']}",
enable_tracing=True,
traces_sampler=custom_sampler,
profiles_sample_rate=0.05,
)

# Application definition

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pytz==2024.1
django-ckeditor==6.7.1
Pillow==10.3.0
djangorestframework-csv==3.0.2
sentry-sdk[django]==1.39.1
sentry-sdk[django]==1.39.2
python-dateutil==2.9.0.post0
dj-database-url
whitenoise
Expand Down

0 comments on commit 6ce07d2

Please sign in to comment.