Skip to content

Commit 18b473d

Browse files
committed
Sentry
1 parent 10e3fe0 commit 18b473d

File tree

8 files changed

+132
-4
lines changed

8 files changed

+132
-4
lines changed

34-sentry.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# install and configure sentry
2+
3+
poetry add 'sentry-sdk[django]==*'
4+
5+
6+
# put some settings to configure sentry
7+
8+
sed -i "/import environ/a import sentry_sdk" "$DJANGO_PROJECT_NAME/settings.py"
9+
10+
cat <<EOF >> "$DJANGO_PROJECT_NAME/settings.py"
11+
12+
SENTRY_DSN = env.str('SENTRY_DSN', default='')
13+
if SENTRY_DSN:
14+
sentry_sdk.init(
15+
dsn=SENTRY_DSN,
16+
traces_sample_rate=0.01,
17+
)
18+
EOF
19+
20+
poetry run isort .
21+
22+
git add --all
23+
git commit -m "Install and configure Sentry"

50-user-model.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ EOL
2020
rm users/admin.py users/views.py users/tests.py
2121

2222
# Update the settings.py file to use the custom user model
23-
echo "AUTH_USER_MODEL = 'users.User'" >> "$DJANGO_PROJECT_NAME/settings.py"
23+
cat <<EOF >> "$DJANGO_PROJECT_NAME/settings.py"
24+
25+
AUTH_USER_MODEL = 'users.User'
26+
EOF
2427

2528
# Create initial migration for the 'users' app
2629
poetry run env $(cat example.env) python manage.py makemigrations --no-header

everything.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ source "$script_dir/31-0-django-environ.sh"
1616
source "$script_dir/31-5-django-https.sh"
1717
source "$script_dir/32-psycopg.sh"
1818
source "$script_dir/33-whitenoise.sh"
19+
source "$script_dir/34-sentry.sh"
1920
source "$script_dir/40-heroku.sh"
2021
source "$script_dir/50-user-model.sh"

example/commits.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@
6767
pyproject.toml | 1 +
6868
4 files changed, 26 insertions(+), 1 deletion(-)
6969

70+
--- Install and configure Sentry
71+
72+
example/settings.py | 8 ++++++
73+
poetry.lock | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
74+
pyproject.toml | 1 +
75+
3 files changed, 89 insertions(+), 1 deletion(-)
76+
7077
--- Configure the project for Heroku deployment
7178

7279
Procfile | 2 ++
@@ -77,10 +84,10 @@
7784

7885
--- Custom user model using UUID4 as the primary key
7986

80-
example/settings.py | 2 ++
87+
example/settings.py | 3 +++
8188
users/__init__.py | 0
8289
users/apps.py | 6 ++++++
8390
users/migrations/0001_initial.py | 44 ++++++++++++++++++++++++++++++++++++++++
8491
users/migrations/__init__.py | 0
8592
users/models.py | 8 ++++++++
86-
6 files changed, 60 insertions(+)
93+
6 files changed, 61 insertions(+)

example/example/settings.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pathlib import Path
1414

1515
import environ
16+
import sentry_sdk
1617

1718

1819
# Build paths inside the project like this: BASE_DIR / 'subdir'.
@@ -142,4 +143,12 @@
142143
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
143144
},
144145
}
146+
147+
SENTRY_DSN = env.str('SENTRY_DSN', default='')
148+
if SENTRY_DSN:
149+
sentry_sdk.init(
150+
dsn=SENTRY_DSN,
151+
traces_sample_rate=0.01,
152+
)
153+
145154
AUTH_USER_MODEL = 'users.User'

example/poetry.lock

Lines changed: 80 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ django = "*"
1111
django-environ = "*"
1212
psycopg = "*"
1313
whitenoise = "*"
14+
sentry-sdk = {version = "*", extras = ["django"]}
1415
gunicorn = "*"
1516

1617

test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,10 @@ cp example.env .env
2222
poetry run python manage.py collectstatic --no-input
2323
poetry run pytest
2424

25+
# remove the virtual env, it may be stored outside the temporary directory
26+
poetry env remove --all
27+
2528
# Navigate back to the original directory
2629
popd
30+
31+
echo "All good!"

0 commit comments

Comments
 (0)