Thanks everyone, I had fix the issue since posted it, but couldn’t reply. Indeed, I had made a mistake with setting the environment in configure_scope.
Here is what I did since then, this is my django manage.py
:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "some.settings")
from prettyconf import Configuration
from django.core.management import execute_from_command_line
from sentry_sdk import configure_scope, init
from sentry_sdk.integrations.django import DjangoIntegration
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# set up configuration
config_path = os.path.join(BASE_DIR, 'settings.ini')
config = Configuration(starting_path=config_path)
ENV = config('ENV', default='development')
ENABLE_SENTRY = config('ENABLE_SENTRY', default=True if (ENV == 'production' or ENV == 'staging') else False, cast=config.boolean)
if ENV == 'development' and sys.argv[1] == 'runserver':
if '--nostatic' not in sys.argv:
sys.argv.append('--nostatic')
if ENABLE_SENTRY:
# Enabling sentry for all "manage" commands - See https://docs.sentry.io/learn/environments/?platform=python
init(
dsn="IsThisSensibleInfoBTW?",
integrations=[DjangoIntegration()],
environment=ENV,
)
with configure_scope() as scope:
scope.set_tag("env", ENV)
scope.set_tag("sentry_startup_mode", 'manage.py')
execute_from_command_line(sys.argv)
I’m enabling Sentry right from the manage.py, I noticed it helped auto-detect issues like migrations, basically any command that goes through manage.py
gets “watched” and that’s actually awesome because I get the SQL queries ran in my server when a migration fails, for instance. <3
I also added a similar code in my settings.py
:
if ENABLE_SENTRY:
# Enable Sentry - See https://sentry.io/unly/studylink/#welcome
sentry_sdk.init(
dsn="IsThisSensibleInfoBTW?",
integrations=[DjangoIntegration()],
environment=ENV,
)
with configure_scope() as scope:
scope.set_tag("env", ENV)
scope.set_tag("sentry_startup_mode", 'settings.py')
I’m not sure if the duplicate is necessary though, I had first configured it in a middleware, then moved it to the settings.py, then duplicated it to manage.py to handle more errors.
Must say I love the tool so far!