Skip to content

Commit

Permalink
Enable Sentry error monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
heykarimoff committed Oct 2, 2024
1 parent 9ff9a97 commit c952aca
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 13 deletions.
66 changes: 53 additions & 13 deletions template/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions template/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ python = "^3.12"
uvicorn = "^0.24.0"
uvloop = { version = "^0.19.0", markers = "sys_platform != 'win32'" }
gunicorn = "^22.0.0"
sentry-sdk = "^2.15.0"

[tool.poetry.group.dev.dependencies]
bandit = "^1.7.4"
Expand Down
17 changes: 17 additions & 0 deletions template/src/project_name/main/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pathlib import Path

import environ
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand Down Expand Up @@ -144,3 +146,18 @@
},
},
}

# Sentry
sentry_sdk.init(
dsn=env("SENTRY_DSN", default=None),
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=env.float("SENTRY_TRACES_SAMPLE_RATE", default=1.0),
# Set profiles_sample_rate to 1.0 to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
profiles_sample_rate=env.float("SENTRY_PROFILES_SAMPLE_RATE", default=1.0),
integrations=[
DjangoIntegration(),
],
)
1 change: 1 addition & 0 deletions template/src/project_name/main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
urlpatterns = [
path("humans.txt", views.HumansTxt.as_view()),
path("release.json", views.Release.as_view()),
path("sentry-debug/", views.TriggerError.as_view()),
path("admin/", admin.site.urls),
]
11 changes: 11 additions & 0 deletions template/src/project_name/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@ def get(
"revision": settings.GIT_COMMIT_COUNT,
}
)


class TriggerError(generic.View):
"""
Trigger an error for testing Sentry
"""

def get(
self, request: http.HttpRequest, *args: Any, **kwargs: Any
) -> http.HttpResponse:
raise ValueError("Triggered error for Sentry testing")

0 comments on commit c952aca

Please sign in to comment.