Skip to content

Commit 335387f

Browse files
committed
chore: set up Sentry
1 parent 3a5f7c2 commit 335387f

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

appcontainer/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ eligibility-api==2023.01.1
55
opencensus-ext-azure==1.1.6
66
opencensus-ext-django==0.8.0
77
requests==2.28.2
8+
sentry-sdk==1.15.0
89
six==1.16.0

benefits/settings.py

+22
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"""
44
import os
55
import benefits.logging
6+
import sentry_sdk
7+
from sentry_sdk.integrations.django import DjangoIntegration
68

79

810
def _filter_empty(ls):
@@ -227,6 +229,26 @@ def _filter_empty(ls):
227229
LOG_LEVEL = os.environ.get("DJANGO_LOG_LEVEL", "DEBUG" if DEBUG else "WARNING")
228230
LOGGING = benefits.logging.get_config(LOG_LEVEL, enable_azure=ENABLE_AZURE_INSIGHTS)
229231

232+
SENTRY_DSN = os.environ.get("SENTRY_DSN")
233+
if SENTRY_DSN:
234+
print("Enabling Sentry…")
235+
236+
sentry_sdk.init(
237+
dsn=SENTRY_DSN,
238+
integrations=[
239+
DjangoIntegration(),
240+
],
241+
# Set traces_sample_rate to 1.0 to capture 100%
242+
# of transactions for performance monitoring.
243+
# We recommend adjusting this value in production.
244+
traces_sample_rate=1.0,
245+
# If you wish to associate users to errors (assuming you are using
246+
# django.contrib.auth) you may enable sending PII data.
247+
send_default_pii=True,
248+
)
249+
else:
250+
print("SENTRY_DSN not set, so won't send events")
251+
230252
# Analytics configuration
231253

232254
ANALYTICS_KEY = os.environ.get("ANALYTICS_KEY")

benefits/urls.py

+8
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,20 @@
1616
handler404 = "benefits.core.views.page_not_found"
1717
handler500 = "benefits.core.views.server_error"
1818

19+
20+
# based on
21+
# https://docs.sentry.io/platforms/python/guides/django/#verify
22+
def trigger_error(request):
23+
raise RuntimeError("Test error")
24+
25+
1926
urlpatterns = [
2027
path("", include("benefits.core.urls")),
2128
path("eligibility/", include("benefits.eligibility.urls")),
2229
path("enrollment/", include("benefits.enrollment.urls")),
2330
path("i18n/", include("django.conf.urls.i18n")),
2431
path("oauth/", include("benefits.oauth.urls")),
32+
path("sentry-debug/", trigger_error),
2533
]
2634

2735
if settings.ADMIN:

docs/configuration/environment-variables.md

+10
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,13 @@ Enables [log collection](../../deployment/troubleshooting/#logs). Set the value
171171
[app-service-config]: https://docs.microsoft.com/en-us/azure/app-service/configure-common?tabs=portal
172172
[benefits-secrets]: https://github.com/cal-itp/benefits-secrets
173173
[getting-started_create-env]: ../getting-started/README.md#create-an-environment-file
174+
175+
## Sentry
176+
177+
### `SENTRY_DSN`
178+
179+
!!! tldr "Sentry docs"
180+
181+
[Data Source Name (DSN)](https://docs.sentry.io/product/sentry-basics/dsn-explainer/)
182+
183+
Enables [sending events to Sentry](../../deployment/troubleshooting/#error-monitoring).

docs/deployment/troubleshooting.md

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ az webapp log tail --resource-group RG-CDT-PUB-VIP-CALITP-P-001 --name AS-CDT-PU
4545

4646
<https://as-cdt-pub-vip-calitp-p-001-dev.scm.azurewebsites.net/api/logs/docker>
4747

48+
### Sentry
49+
50+
Cal-ITP's Sentry instance collects both [errors ("Issues")](https://sentry.calitp.org/organizations/sentry/issues/?project=3) and app [performance info](https://sentry.calitp.org/organizations/sentry/performance/?project=3).
51+
52+
[Alerts are sent to #benefits-notify in Slack.](https://sentry.calitp.org/organizations/sentry/alerts/rules/benefits/9/details/) [Others can be configured.](https://sentry.calitp.org/organizations/sentry/alerts/rules/)
53+
4854
## Specific issues
4955

5056
This section serves as the [runbook](https://www.pagerduty.com/resources/learn/what-is-a-runbook/) for Benefits.

0 commit comments

Comments
 (0)