improve logging to sentry

This commit is contained in:
Your Name 2024-05-12 22:39:44 -04:00 committed by Henri Dickson
parent 90ef826344
commit 9a58ddb785
2 changed files with 8 additions and 1 deletions

View file

@ -1,4 +1,5 @@
import os import os
import sys
import environ import environ
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -102,6 +103,7 @@ env = environ.FileAwareEnv(
# SSL only, better be True for production security # SSL only, better be True for production security
SSL_ONLY=(bool, False), SSL_ONLY=(bool, False),
NEODB_SENTRY_DSN=(str, ""), NEODB_SENTRY_DSN=(str, ""),
NEODB_SENTRY_SAMPLE_RATE=(float, 0),
NEODB_FANOUT_LIMIT_DAYS=(int, 9), NEODB_FANOUT_LIMIT_DAYS=(int, 9),
) )
@ -564,10 +566,14 @@ if SENTRY_DSN:
from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.loguru import LoguruIntegration from sentry_sdk.integrations.loguru import LoguruIntegration
sentry_env = sys.argv[0].split("/")[-1]
if len(sys.argv) > 1 and sentry_env in ("manage.py", "django-admin"):
sentry_env = sys.argv[1]
sentry_sdk.init( sentry_sdk.init(
dsn=SENTRY_DSN, dsn=SENTRY_DSN,
environment=sentry_env or "unknown",
integrations=[LoguruIntegration(), DjangoIntegration()], integrations=[LoguruIntegration(), DjangoIntegration()],
release=NEODB_VERSION, release=NEODB_VERSION,
send_default_pii=True, send_default_pii=True,
traces_sample_rate=1 if DEBUG else 0.001, traces_sample_rate=env("NEODB_SENTRY_SAMPLE_RATE"),
) )

View file

@ -36,6 +36,7 @@ x-shared:
NEODB_MIN_MARKS_FOR_DISCOVER: NEODB_MIN_MARKS_FOR_DISCOVER:
NEODB_SENTRY_DSN: NEODB_SENTRY_DSN:
TAKAHE_SENTRY_DSN: TAKAHE_SENTRY_DSN:
NEODB_SENTRY_SAMPLE_RATE:
NEODB_DB_URL: ${NEODB_DB_URL:-postgres://neodb:aubergine@neodb-db/neodb} NEODB_DB_URL: ${NEODB_DB_URL:-postgres://neodb:aubergine@neodb-db/neodb}
TAKAHE_DB_URL: ${TAKAHE_DB_URL:-postgres://takahe:aubergine@takahe-db/takahe} TAKAHE_DB_URL: ${TAKAHE_DB_URL:-postgres://takahe:aubergine@takahe-db/takahe}
NEODB_REDIS_URL: ${NEODB_REDIS_URL:-redis://redis:6379/0} NEODB_REDIS_URL: ${NEODB_REDIS_URL:-redis://redis:6379/0}