From f40f30445799176a12628d89d66a90ddf4bc459b Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Sun, 5 Jun 2016 10:47:07 -0700 Subject: [PATCH] Use sentry for error reporting --- README.rst | 3 +-- cookiecutter.json | 3 +-- docs/project-generation-options.rst | 2 +- {{cookiecutter.project_slug}}/Procfile | 2 +- {{cookiecutter.project_slug}}/README.rst | 2 +- {{cookiecutter.project_slug}}/app.json | 8 ++------ .../config/settings/production.py | 18 +++++++----------- {{cookiecutter.project_slug}}/config/wsgi.py | 13 ++----------- {{cookiecutter.project_slug}}/env.example | 6 +----- .../requirements/production.txt | 8 +------- .../taskapp/celery.py | 2 +- 11 files changed, 19 insertions(+), 48 deletions(-) diff --git a/README.rst b/README.rst index 915cfa9b..fa7c88d3 100644 --- a/README.rst +++ b/README.rst @@ -118,8 +118,7 @@ Answer the prompts with your own desired options_. For example:: use_whitenoise [y]: n use_celery [n]: y use_mailhog [n]: n - use_sentry [n]: y - use_newrelic [n]: y + use_sentry_for_error_reporting [y]: y use_opbeat [n]: y use_pycharm [n]: y windows [n]: n diff --git a/cookiecutter.json b/cookiecutter.json index 0cae4073..89148ec2 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -10,8 +10,7 @@ "use_whitenoise": "y", "use_celery": "n", "use_mailhog": "n", - "use_sentry": "n", - "use_newrelic": "n", + "use_sentry_for_error_reporting": "y", "use_opbeat": "n", "use_pycharm": "n", "windows": "n", diff --git a/docs/project-generation-options.rst b/docs/project-generation-options.rst index 9ffad1e5..2ea27c53 100644 --- a/docs/project-generation-options.rst +++ b/docs/project-generation-options.rst @@ -39,7 +39,7 @@ use_mailhog [n] for development purposes. It runs a simple SMTP server which catches any message sent to it. Messages are displayed in a web interface which runs at ``http://localhost:8025/`` You need to download the MailHog executable for your operating system, see the 'Developing Locally' docs for instructions. -use_sentry [n] +use_sentry_for_error_reporting [n] Whether to use Sentry_ to log errors from your project. windows [n] diff --git a/{{cookiecutter.project_slug}}/Procfile b/{{cookiecutter.project_slug}}/Procfile index a5476341..c77d76d9 100644 --- a/{{cookiecutter.project_slug}}/Procfile +++ b/{{cookiecutter.project_slug}}/Procfile @@ -1,4 +1,4 @@ web: gunicorn config.wsgi:application {% if cookiecutter.use_celery == "y" -%} -worker: {% if cookiecutter.use_newrelic == "y" %}newrelic-admin run-program {% endif %}celery worker --app={{cookiecutter.project_slug}}.taskapp --loglevel=info +worker: celery worker --app={{cookiecutter.project_slug}}.taskapp --loglevel=info {%- endif %} diff --git a/{{cookiecutter.project_slug}}/README.rst b/{{cookiecutter.project_slug}}/README.rst index 38d923b6..170f66a7 100644 --- a/{{cookiecutter.project_slug}}/README.rst +++ b/{{cookiecutter.project_slug}}/README.rst @@ -104,7 +104,7 @@ The email server will exit when you exit the Grunt task on the CLI with Ctrl+C. {% endif %} {% endif %} -{% if cookiecutter.use_sentry == "y" %} +{% if cookiecutter.use_sentry_for_error_reporting == "y" %} Sentry ^^^^^^ diff --git a/{{cookiecutter.project_slug}}/app.json b/{{cookiecutter.project_slug}}/app.json index 6e6585fd..a2349458 100644 --- a/{{cookiecutter.project_slug}}/app.json +++ b/{{cookiecutter.project_slug}}/app.json @@ -20,12 +20,8 @@ "DJANGO_AWS_SECRET_ACCESS_KEY": "", "DJANGO_AWS_STORAGE_BUCKET_NAME": "", "DJANGO_MAILGUN_SERVER_NAME": "", - {% if cookiecutter.use_newrelic == "y" -%} - "NEW_RELIC_LICENSE_KEY": "", - "NEW_RELIC_APP_NAME": "", - {%- endif %} - "DJANGO_MAILGUN_API_KEY": ""{% if cookiecutter.use_sentry == "y" -%}, - "DJANGO_SENTRY_DSN": ""{%- endif %} + "DJANGO_MAILGUN_API_KEY": ""{% if cookiecutter.use_sentry_for_error_reporting == "y" -%}, + "DJANGO_SENTRY_DSN": ""{%- endif %} }, "scripts": { "postdeploy": "python manage.py migrate" diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 346bf7cb..ae00b472 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -6,7 +6,7 @@ Production Configurations - Use Amazon's S3 for storing static files and uploaded media - Use mailgun to send emails - Use Redis on Heroku -{% if cookiecutter.use_sentry == 'y' %} +{% if cookiecutter.use_sentry_for_error_reporting == 'y' %} - Use sentry for error logging {% endif %} {% if cookiecutter.use_opbeat == 'y' %} @@ -17,7 +17,7 @@ from __future__ import absolute_import, unicode_literals from boto.s3.connection import OrdinaryCallingFormat from django.utils import six -{% if cookiecutter.use_sentry == 'y' %} +{% if cookiecutter.use_sentry_for_error_reporting == 'y' %} import logging {% endif %} @@ -33,7 +33,8 @@ SECRET_KEY = env('DJANGO_SECRET_KEY') # This ensures that Django will be able to detect a secure connection # properly on Heroku. SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') -{%- if cookiecutter.use_sentry == 'y'-%} + +{%- if cookiecutter.use_sentry_for_error_reporting == 'y'-%} # raven sentry client # See https://docs.getsentry.com/hosted/clients/python/integrations/django/ INSTALLED_APPS += ('raven.contrib.django.raven_compat', ) @@ -44,7 +45,7 @@ INSTALLED_APPS += ('raven.contrib.django.raven_compat', ) WHITENOISE_MIDDLEWARE = ('whitenoise.middleware.WhiteNoiseMiddleware', ) MIDDLEWARE_CLASSES = WHITENOISE_MIDDLEWARE + MIDDLEWARE_CLASSES {% endif %} -{%- if cookiecutter.use_sentry == 'y' -%} +{%- if cookiecutter.use_sentry_for_error_reporting == 'y' -%} RAVEN_MIDDLEWARE = ('raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware', ) MIDDLEWARE_CLASSES = RAVEN_MIDDLEWARE + MIDDLEWARE_CLASSES {% endif %} @@ -161,11 +162,6 @@ ANYMAIL = { } EMAIL_BACKEND = "anymail.backends.mailgun.MailgunBackend" -{% if cookiecutter.use_newrelic == 'y'-%}# NEW RELIC -# ------------------------------------------------------------------------------ -NEW_RELIC_LICENSE_KEY = env('NEW_RELIC_LICENSE_KEY') -NEW_RELIC_APP_NAME = env('NEW_RELIC_APP_NAME') -{%- endif %} # TEMPLATE CONFIGURATION # ------------------------------------------------------------------------------ # See: @@ -195,7 +191,7 @@ CACHES = { } } -{% if cookiecutter.use_sentry == 'y' %} +{% if cookiecutter.use_sentry_for_error_reporting == 'y' %} # Sentry Configuration SENTRY_DSN = env('DJANGO_SENTRY_DSN') SENTRY_CLIENT = env('DJANGO_SENTRY_CLIENT', default='raven.contrib.django.raven_compat.DjangoClient') @@ -251,7 +247,7 @@ RAVEN_CONFIG = { 'CELERY_LOGLEVEL': env.int('DJANGO_SENTRY_LOG_LEVEL', logging.INFO), 'DSN': SENTRY_DSN } -{% elif cookiecutter.use_sentry == 'n' %} +{% elif cookiecutter.use_sentry_for_error_reporting == 'n' %} # LOGGING CONFIGURATION # ------------------------------------------------------------------------------ # See: https://docs.djangoproject.com/en/dev/ref/settings/#logging diff --git a/{{cookiecutter.project_slug}}/config/wsgi.py b/{{cookiecutter.project_slug}}/config/wsgi.py index 4790b1b5..636f547a 100644 --- a/{{cookiecutter.project_slug}}/config/wsgi.py +++ b/{{cookiecutter.project_slug}}/config/wsgi.py @@ -15,13 +15,8 @@ framework. """ import os -{% if cookiecutter.use_newrelic == 'y' -%} -if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production': - import newrelic.agent - newrelic.agent.initialize() -{%- endif %} from django.core.wsgi import get_wsgi_application -{% if cookiecutter.use_sentry == 'y' -%} +{% if cookiecutter.use_sentry_for_error_reporting == 'y' -%} if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production': from raven.contrib.django.raven_compat.middleware.wsgi import Sentry {%- endif %} @@ -36,14 +31,10 @@ 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 cookiecutter.use_sentry_for_error_reporting == 'y' -%} if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production': application = Sentry(application) {%- endif %} -{% if cookiecutter.use_newrelic == 'y' -%} -if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production': - application = newrelic.agent.WSGIApplicationWrapper(application) -{%- endif %} # Apply WSGI middleware here. # from helloworld.wsgi import HelloWorldApplication # application = HelloWorldApplication(application) diff --git a/{{cookiecutter.project_slug}}/env.example b/{{cookiecutter.project_slug}}/env.example index bbea38b2..a982dc92 100644 --- a/{{cookiecutter.project_slug}}/env.example +++ b/{{cookiecutter.project_slug}}/env.example @@ -12,13 +12,9 @@ DJANGO_MAILGUN_API_KEY= DJANGO_SERVER_EMAIL= DJANGO_SECURE_SSL_REDIRECT=False DJANGO_ACCOUNT_ALLOW_REGISTRATION=True -{% if cookiecutter.use_sentry == 'y' -%} +{% if cookiecutter.use_sentry_for_error_reporting == 'y' -%} DJANGO_SENTRY_DSN= {% endif %} -{% if cookiecutter.use_newrelic == 'y' -%} -NEW_RELIC_LICENSE_KEY= -NEW_RELIC_APP_NAME={{cookiecutter.project_slug}} -{% endif %} {% if cookiecutter.use_opbeat == 'y' -%} DJANGO_OPBEAT_ORGANIZATION_ID DJANGO_OPBEAT_APP_ID diff --git a/{{cookiecutter.project_slug}}/requirements/production.txt b/{{cookiecutter.project_slug}}/requirements/production.txt index 5ac46e62..16c7ea80 100644 --- a/{{cookiecutter.project_slug}}/requirements/production.txt +++ b/{{cookiecutter.project_slug}}/requirements/production.txt @@ -26,18 +26,12 @@ Collectfast==0.2.3 # ------------------------------------------------------- django-anymail==0.3.1 -{% if cookiecutter.use_sentry == "y" -%} +{% if cookiecutter.use_sentry_for_error_reporting == "y" -%} # Raven is the Sentry client # -------------------------- raven {%- endif %} -{% if cookiecutter.use_newrelic == "y" -%} -# Newrelic agent for performance monitoring -# ----------------------------------------- -newrelic -{%- endif %} - {% if cookiecutter.use_opbeat == "y" -%} # Opbeat agent for performance monitoring # ----------------------------------------- diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/taskapp/celery.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/taskapp/celery.py index 44c57f7c..7905e366 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/taskapp/celery.py +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/taskapp/celery.py @@ -24,7 +24,7 @@ class CeleryConfig(AppConfig): app.config_from_object('django.conf:settings') app.autodiscover_tasks(lambda: settings.INSTALLED_APPS, force=True) - {% if cookiecutter.use_sentry == 'y' -%} + {% if cookiecutter.use_sentry_for_error_reporting == 'y' -%} if hasattr(settings, 'RAVEN_CONFIG'): # Celery signal registration from raven import Client as RavenClient