Address several comments from Code review

This commit is contained in:
Bruno Alla 2019-03-13 15:20:07 +00:00
parent 139e1ba89c
commit 9d2edc161f
4 changed files with 74 additions and 47 deletions

View File

@ -173,7 +173,6 @@ COMPRESS_ENABLED = env.bool('COMPRESS_ENABLED', default=True)
COMPRESS_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_URL
COMPRESS_URL = STATIC_URL
{% endif %}
{%- if cookiecutter.use_whitenoise == 'n' -%}
# Collectfast
@ -181,32 +180,16 @@ COMPRESS_URL = STATIC_URL
# https://github.com/antonagestam/collectfast#installation
INSTALLED_APPS = ['collectfast'] + INSTALLED_APPS # noqa F405
AWS_PRELOAD_METADATA = True
{% endif %}
{%- if cookiecutter.use_sentry == 'y' -%}
# Sentry
# ------------------------------------------------------------------------------
SENTRY_DSN = env('SENTRY_DSN')
SENTRY_CELERY_LOGLEVEL = env.int('DJANGO_SENTRY_LOG_LEVEL', logging.INFO)
sentry_logging = LoggingIntegration(
level=DJANGO_SENTRY_LOG_LEVEL, # Capture info and above as breadcrumbs
event_level=None # Send no events from log messages
)
sentry_sdk.init(
dsn="SENTRY_DSN",
integrations=[sentry_logging, DjangoIntegration()]
)
{%- else %}
# LOGGING
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
# https://docs.djangoproject.com/en/dev/ref/settings/#logging
# See https://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
{%- if cookiecutter.use_sentry == 'n' -%}
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See https://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
@ -246,7 +229,57 @@ LOGGING = {
}
}
}
{% else %}
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s '
'%(process)d %(thread)d %(message)s'
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
}
},
'loggers': {
'django.db.backends': {
'level': 'ERROR',
'handlers': ['console'],
'propagate': False,
},
# Errors logged by the SDK itself
'sentry_sdk': {
'level': 'ERROR',
'handlers': ['console'],
'propagate': False,
},
'django.security.DisallowedHost': {
'level': 'ERROR',
'handlers': ['console'],
'propagate': False,
},
},
}
# Sentry
# ------------------------------------------------------------------------------
SENTRY_DSN = env('SENTRY_DSN')
SENTRY_LOGLEVEL = env.int('DJANGO_SENTRY_LOG_LEVEL', logging.INFO)
sentry_logging = LoggingIntegration(
level=SENTRY_LOGLEVEL, # Capture info and above as breadcrumbs
event_level=None, # Send no events from log messages
)
sentry_sdk.init(
dsn=SENTRY_DSN,
integrations=[sentry_logging, DjangoIntegration()]
)
{% endif %}
# Your stuff...
# ------------------------------------------------------------------------------

View File

@ -22,11 +22,7 @@ from django.core.wsgi import get_wsgi_application
# {{ cookiecutter.project_slug }} directory.
app_path = os.path.abspath(os.path.join(
os.path.dirname(os.path.abspath(__file__)), os.pardir))
sys.path.append(os.path.join(app_path, '{{ cookiecutter.project_slug }}'))
{% if cookiecutter.use_sentry == 'y' -%}
if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production':
from raven.contrib.django.raven_compat.middleware.wsgi import Sentry
{%- endif %}
sys.path.append(os.path.join(app_path, "{{ cookiecutter.project_slug }}"))
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
@ -37,10 +33,6 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
application = get_wsgi_application()
{% if cookiecutter.use_sentry == 'y' -%}
if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production':
application = Sentry(application)
{%- endif %}
# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)

View File

@ -8,7 +8,7 @@ psycopg2==2.7.4 --no-binary psycopg2 # https://github.com/psycopg/psycopg2
Collectfast==0.6.2 # https://github.com/antonagestam/collectfast
{%- endif %}
{%- if cookiecutter.use_sentry == "y" %}
sentry-sdk==0.3.7 # https://docs.sentry.io/quickstart/?platform=python
sentry-sdk==0.7.6 # https://github.com/getsentry/sentry-python
{%- endif %}
# Django

View File

@ -1,7 +1,6 @@
{% if cookiecutter.use_celery == 'y' %}
import os
from celery import Celery
from django.apps import apps, AppConfig
from django.conf import settings
@ -26,26 +25,29 @@ 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 cookiecutter.use_pycharm == 'y' -%}
# Since raven is required in production only,
{% 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' -%}
{%- 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_CELERY_LOGLEVEL, # 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 %}
{%- endif %}
sentry_logging = LoggingIntegration(
level=settings.SENTRY_LOGLEVEL, # 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)