Skip to content

Commit

Permalink
Config: Configure Sentry for backend (#638)
Browse files Browse the repository at this point in the history
* deps: Add pip-tools to dev requirements and sentry-sdk to base requirements

* config: Add Sentry integration

* docker: Add SENTRY_DSN environment variable to docker-compose.yaml

* docs: Document SENTRY_DSN environment variable

* chore(deps): Fix requirements rebase conflicts by re-running pip-compile
  • Loading branch information
drikusroor authored Dec 20, 2023
1 parent 2850f9b commit 1a46254
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ SQL_PASSWORD=musclepassword # change this to a safe password when running in pro
SQL_HOST=db # name of database container, don't change
SQL_PORT=5432 # port where to reach the database, don't change

SENTRY_DSN= # optional: link to sentry instance, e.g. https://xxx@xxx.ingest.sentry.io/xxx

AML_SECRET_KEY=supersecret # change this to a safe password when running in production
AML_DEBUG=true # change this to false when running in production
DJANGO_SETTINGS_MODULE=aml.development_settings # change this to aml.production_settings when running in production
Expand Down
13 changes: 13 additions & 0 deletions backend/aml/base_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import os
from corsheaders.defaults import default_headers
import sentry_sdk

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand Down Expand Up @@ -163,3 +164,15 @@
LOCALE_PATHS = [os.path.join(BASE_DIR, 'locale')]

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

# Sentry
sentry_sdk.init(
dsn=os.getenv("SENTRY_DSN", ""),
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
traces_sample_rate=0.2,
# Set profiles_sample_rate to 1.0 to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
profiles_sample_rate=0.2,
)
4 changes: 4 additions & 0 deletions backend/aml/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
path('section/', include('section.urls')),
path('session/', include('session.urls')),
path('admin/', admin.site.urls),

# Sentry debug (uncomment to test Sentry)
# path('sentry-debug/', lambda request: 1 / 0),

] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# ^ The static helper function only works in debug mode
# (https://docs.djangoproject.com/en/3.0/howto/static-files/)
Expand Down
3 changes: 3 additions & 0 deletions backend/requirements.in/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ IPToCC
# PostgrSQL database client
psycopg2

# Sentry SDK, for monitoring performance & errors. See also sentry.io.
sentry-sdk

# print progress
tqdm

Expand Down
3 changes: 3 additions & 0 deletions backend/requirements.in/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ autopep8

# for simulating http requests in tests
requests

# Add pip-tools so we can use pip-compile in our develop environment
pip-tools
34 changes: 31 additions & 3 deletions backend/requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ audioread==2.1.9
# via -r requirements.in/base.txt
autopep8==1.5.7
# via -r requirements.in/dev.txt
build==1.0.3
# via pip-tools
certifi==2023.7.22
# via requests
# via
# requests
# sentry-sdk
charset-normalizer==2.1.0
# via requests
click==8.1.7
# via genbadge
# via
# genbadge
# pip-tools
coverage==7.3.2
# via -r requirements.in/base.txt
defusedxml==0.7.1
Expand All @@ -38,6 +44,8 @@ genbadge[coverage]==1.1.1
# via -r requirements.in/base.txt
idna==3.3
# via requests
importlib-metadata==7.0.0
# via build
iptocc==2.1.2
# via -r requirements.in/base.txt
isort==5.9.3
Expand All @@ -48,10 +56,14 @@ mccabe==0.6.1
# via pylint
numpy==1.22.0
# via pandas
packaging==23.2
# via build
pandas==1.3.4
# via iptocc
pillow==10.1.0
# via genbadge
pip-tools==7.3.0
# via -r requirements.in/dev.txt
platformdirs==2.4.0
# via pylint
psycopg2==2.9.1
Expand All @@ -67,6 +79,8 @@ pylint-django==2.4.4
# via -r requirements.in/dev.txt
pylint-plugin-utils==0.6
# via pylint-django
pyproject-hooks==1.0.0
# via build
python-dateutil==2.8.2
# via pandas
python-dotenv==0.19.1
Expand All @@ -79,6 +93,8 @@ requests==2.31.0
# via
# -r requirements.in/dev.txt
# genbadge
sentry-sdk==1.38.0
# via -r requirements.in/base.txt
six==1.16.0
# via python-dateutil
sqlparse==0.4.4
Expand All @@ -89,16 +105,28 @@ toml==0.10.2
# via
# autopep8
# pylint
tomli==2.0.1
# via
# build
# pip-tools
# pyproject-hooks
tqdm==4.65.0
# via -r requirements.in/base.txt
typing-extensions==3.10.0.2
# via
# astroid
# pylint
urllib3==1.26.18
# via requests
# via
# requests
# sentry-sdk
wheel==0.42.0
# via pip-tools
wrapt==1.13.2
# via astroid
zipp==3.17.0
# via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
# pip
# setuptools
10 changes: 8 additions & 2 deletions backend/requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ asgiref==3.7.2
audioread==3.0.0
# via -r requirements.in/base.txt
certifi==2023.11.17
# via requests
# via
# requests
# sentry-sdk
charset-normalizer==3.3.2
# via requests
click==8.1.7
Expand Down Expand Up @@ -53,6 +55,8 @@ pytz==2023.3
# pandas
requests==2.31.0
# via genbadge
sentry-sdk==1.38.0
# via -r requirements.in/base.txt
six==1.16.0
# via python-dateutil
sqlparse==0.4.4
Expand All @@ -62,7 +66,9 @@ tqdm==4.65.0
typing-extensions==4.6.3
# via asgiref
urllib3==2.1.0
# via requests
# via
# requests
# sentry-sdk

# The following packages are considered to be unsafe in a requirements file:
# setuptools
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ services:
- DJANGO_SUPERUSER_PASSWORD=${DJANGO_SUPERUSER_PASSWORD}
- DJANGO_SUPERUSER_EMAIL=${DJANGO_SUPERUSER_EMAIL}
- AML_LOCATION_PROVIDER=${AML_LOCATION_PROVIDER}
- SENTRY_DSN=${SENTRY_DSN}
- SQL_DATABASE=${SQL_DATABASE}
- SQL_USER=${SQL_USER}
- SQL_PASSWORD=${SQL_PASSWORD}
Expand Down

0 comments on commit 1a46254

Please sign in to comment.