diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 16c2ca088..546f2364f 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -5,6 +5,9 @@ import sentry_sdk from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.integrations.logging import LoggingIntegration +{%- if cookiecutter.use_celery == 'y' %} +from sentry_sdk.integrations.celery import CeleryIntegration +{% endif %} {% endif -%} from .base import * # noqa @@ -275,7 +278,14 @@ sentry_logging = LoggingIntegration( event_level=None, # Send no events from log messages ) +{%- if cookiecutter.use_celery == 'y' %} +sentry_sdk.init( + dsn=SENTRY_DSN, + integrations=[sentry_logging, DjangoIntegration(), CeleryIntegration()], +) +{% else %} sentry_sdk.init(dsn=SENTRY_DSN, integrations=[sentry_logging, DjangoIntegration()]) +{% endif -%} {% endif %} # Your stuff... # ------------------------------------------------------------------------------ diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/taskapp/celery.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/taskapp/celery.py index 58c67718f..529da1ae0 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/taskapp/celery.py +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/taskapp/celery.py @@ -27,33 +27,6 @@ class CeleryAppConfig(AppConfig): def ready(self): installed_apps = [app_config.name for app_config in apps.get_app_configs()] app.autodiscover_tasks(lambda: installed_apps, force=True) - {%- if cookiecutter.use_sentry == 'y' %} - - if hasattr(settings, "SENTRY_DSN"): - # Celery signal registration - {% if cookiecutter.use_pycharm == 'y' -%} - # Since Sentry is required in production only, - # imports might (most surely will) be wiped out - # during PyCharm code clean up started - # in other environments. - # @formatter:off - {%- endif %} - import sentry_sdk - from sentry_sdk.integrations.celery import CeleryIntegration - from sentry_sdk.integrations.logging import LoggingIntegration - - {% if cookiecutter.use_pycharm == 'y' -%} - # @formatter:on - {%- endif %} - sentry_logging = LoggingIntegration( - level=settings.SENTRY_LOG_LEVEL, # Capture info and above as breadcrumbs - event_level=None, # Send no events from log messages - ) - sentry_sdk.init( - dsn=settings.SENTRY_DSN, - integrations=[sentry_logging, CeleryIntegration()], - ) - {%- endif %} @app.task(bind=True)