Skip to content

Commit 6b656e4

Browse files
committed
Add basic config for Sentry instrumentation
- Adds Django-specific sentry-sdk package in Pipfile - Updates .env.example with hints for DSN - Updates settings.py with the Sentry init and defaults for a development env
1 parent f3507d6 commit 6b656e4

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ 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 and for the
18+
# defaults and options that may be set.
19+
DSN=''
20+
1521
# Add the following to your local .env file. They will be used in the CI process
1622
# and you can largely forget about them, but including them in your .env file
1723
# 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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,23 @@
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+
# - 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+
sentry_sdk.init(
22+
traces_sample_rate = os.environ.get('SENTRY_TRACES_SAMPLE_RATE', 1.0),
23+
profiles_sample_rate = os.environ.get('SENTRY_PROFILES_SAMPLE_RATE', 1.0),
24+
environment = os.environ.get('SENTRY_ENVIRONMENT', 'development'),
25+
debug = os.environ.get('SENTRY_DEBUG', 'True'),
26+
attach_stacktrace = os.environ.get('SENTRY_ATTACH_STACK_TRACE', 'True')
27+
)
28+
29+
1630
# Build paths inside the project like this: BASE_DIR / 'subdir'.
1731
BASE_DIR: Path = Path(__file__).resolve().parent.parent
1832

@@ -131,6 +145,7 @@
131145

132146
# Django chache
133147
# https://docs.djangoproject.com/en/4.2/topics/cache/#redis
148+
134149
CACHES: dict[str, dict[str, str]] = {
135150
'default': {
136151
'BACKEND': 'django.core.cache.backends.redis.RedisCache',

0 commit comments

Comments
 (0)