Skip to content

Commit

Permalink
Move Sentry configuration to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
realsuayip committed Nov 7, 2024
1 parent bc12a79 commit a75bbbd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
12 changes: 5 additions & 7 deletions asu/apps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.apps import AppConfig
from django.conf import settings
from django.utils.translation import pgettext_lazy

import sentry_sdk
from envanter import env
from sentry_sdk.integrations.celery import CeleryIntegration
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.logging import ignore_logger
Expand All @@ -17,13 +17,11 @@ class AsuConfig(AppConfig):
verbose_name = pgettext_lazy("app name", "asu")

def ready(self) -> None:
enabled = env.bool("SENTRY_ENABLED")

if enabled:
if settings.SENTRY_ENABLED:
sentry_sdk.init( # pragma: no cover
dsn=env.str("SENTRY_DSN"),
environment=env.str("SENTRY_ENVIRONMENT"),
traces_sample_rate=env.float("SENTRY_TRACES_SAMPLE_RATE"),
dsn=settings.SENTRY_DSN,
environment=settings.PROJECT_ENVIRONMENT,
traces_sample_rate=settings.SENTRY_TRACES_SAMPLE_RATE,
integrations=[DjangoIntegration(), CeleryIntegration()],
send_default_pii=True,
)
Expand Down
9 changes: 8 additions & 1 deletion asu/settings/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,25 @@
}

THUMBNAIL_REDIS_URL = REDIS_URL
THUMBNAIL_FORCE_OVERWRITE = True

AWS_ACCESS_KEY_ID = env.str("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = env.str("AWS_SECRET_ACCESS_KEY")
AWS_STORAGE_BUCKET_NAME = env.str("AWS_STORAGE_BUCKET_NAME")
AWS_S3_ENDPOINT_URL = env.str("AWS_S3_ENDPOINT_URL")
AWS_S3_REGION_NAME = env.str("AWS_S3_REGION_NAME")

THUMBNAIL_FORCE_OVERWRITE = True
SENTRY_ENABLED = env.bool("SENTRY_ENABLED")
SENTRY_DSN = env.str("SENTRY_DSN")
SENTRY_TRACES_SAMPLE_RATE = env.float("SENTRY_TRACES_SAMPLE_RATE")


# ----- Local apps -----

PROJECT_BRAND = env.str("PROJECT_BRAND")
PROJECT_ENVIRONMENT = env.choice(
"PROJECT_ENVIRONMENT", choices=("dev", "stage", "production")
)
PROJECT_SUPPORT_EMAIL = env.str("PROJECT_SUPPORT_EMAIL")
PROJECT_URL_ACCOUNT_CREATION = env.str("PROJECT_URL_ACCOUNT_CREATION")
PROJECT_URL_PASSWORD_RESET = env.str("PROJECT_URL_PASSWORD_RESET")
Expand Down
2 changes: 2 additions & 0 deletions asu/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
INSTALLED_APPS.remove("debug_toolbar") # noqa: F405
EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"
CELERY_TASK_ALWAYS_EAGER = True

PROJECT_ENVIRONMENT = "production"
4 changes: 2 additions & 2 deletions conf/dev/django.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ EMAIL_USE_TLS=false
DEFAULT_FROM_EMAIL=webmaster@localhost

PROJECT_BRAND=asu
PROJECT_ENVIRONMENT=dev
PROJECT_SUPPORT_EMAIL=support@example.com
PROJECT_URL_ACCOUNT_CREATION="#Stub-AccountCreation"
PROJECT_URL_PASSWORD_RESET="#Stub-PasswordReset"
Expand All @@ -42,8 +43,7 @@ CORS_ALLOWED_ORIGINS=http://127.0.0.1

SENTRY_ENABLED=false
SENTRY_DSN=
SENTRY_ENVIRONMENT=dev
SENTRY_TRACES_SAMPLE_RATE=0.1
SENTRY_TRACES_SAMPLE_RATE=0

DEFAULT_FILE_STORAGE=django.core.files.storage.FileSystemStorage
STATICFILES_STORAGE=django.contrib.staticfiles.storage.StaticFilesStorage
Expand Down
2 changes: 1 addition & 1 deletion conf/prod/django.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ EMAIL_USE_TLS=false
DEFAULT_FROM_EMAIL=webmaster@localhost

PROJECT_BRAND=asu
PROJECT_ENVIRONMENT=production
PROJECT_SUPPORT_EMAIL=support@example.com
PROJECT_URL_ACCOUNT_CREATION="#Stub-AccountCreation"
PROJECT_URL_PASSWORD_RESET="#Stub-PasswordReset"
Expand All @@ -43,7 +44,6 @@ SECURE_PROXY_SSL_HEADER=HTTP_X_FORWARDED_PROTO,https

SENTRY_ENABLED=false
SENTRY_DSN=
SENTRY_ENVIRONMENT=production
SENTRY_TRACES_SAMPLE_RATE=0.1

DEFAULT_FILE_STORAGE=django.core.files.storage.FileSystemStorage
Expand Down

0 comments on commit a75bbbd

Please sign in to comment.