Skip to content

Commit e04e60e

Browse files
authored
Merge pull request #29 from cmu-delphi/add-sentry-integration
Configure for Sentry
2 parents f3507d6 + 70980e8 commit e04e60e

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ CSRF_TRUSTED_ORIGINS='http://127.0.0.1:8000,http://localhost:8000'
1212
SECRET_KEY='secret_key'
1313
DEBUG='True'
1414

15+
# Sentry
16+
# Modify the Sentry config here. A DSN string is the minimum. Check the
17+
# application's Sentry init section and the Sentry documentation for the
18+
# defaults and options that may be set. If you don't want to use Sentry you can
19+
# leave this as is.
20+
#SENTRY_DSN=''
21+
1522
# Add the following to your local .env file. They will be used in the CI process
1623
# and you can largely forget about them, but including them in your .env file
1724
# will act like a safe default and help suppress warnings.

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ django-filter = "*"
99
django-extensions = "*"
1010
pillow = "*"
1111
pre-commit = "*"
12-
sentry-sdk = "*"
12+
'sentry-sdk[django]' = "*"
1313
python-dotenv = "*"
1414
django-health-check = "*"
1515
django-cors-headers = "*"

src/signal_documentation/settings.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,30 @@
1010
https://docs.djangoproject.com/en/4.2/ref/settings/
1111
"""
1212
import os
13+
import sentry_sdk
1314
from pathlib import Path
1415
from typing import Any
1516

17+
# Sentry init and config:
18+
# - If you want to use Sentry, specify the DSN via the env var of `SENTRY_DSN`.
19+
# - Useful defaults for a development environment are set below. They can be
20+
# changed by modifying env vars.
21+
from sentry_sdk.integrations.django import DjangoIntegration
22+
from sentry_sdk.integrations.redis import RedisIntegration
23+
24+
SENTRY_DSN = os.environ.get('SENTRY_DSN')
25+
if SENTRY_DSN:
26+
sentry_sdk.init(
27+
dsn=SENTRY_DSN,
28+
integrations=[DjangoIntegration(), RedisIntegration(max_data_size=0)],
29+
traces_sample_rate=os.environ.get('SENTRY_TRACES_SAMPLE_RATE', 1.0),
30+
profiles_sample_rate=os.environ.get('SENTRY_PROFILES_SAMPLE_RATE', 1.0),
31+
environment=os.environ.get('SENTRY_ENVIRONMENT', 'development'),
32+
debug=os.environ.get('SENTRY_DEBUG', 'True'),
33+
attach_stacktrace=os.environ.get('SENTRY_ATTACH_STACKTRACE', 'True')
34+
)
35+
36+
1637
# Build paths inside the project like this: BASE_DIR / 'subdir'.
1738
BASE_DIR: Path = Path(__file__).resolve().parent.parent
1839

@@ -131,6 +152,7 @@
131152

132153
# Django chache
133154
# https://docs.djangoproject.com/en/4.2/topics/cache/#redis
155+
134156
CACHES: dict[str, dict[str, str]] = {
135157
'default': {
136158
'BACKEND': 'django.core.cache.backends.redis.RedisCache',

0 commit comments

Comments
 (0)