Permalink
Browse files

Upgrade sentry.

Uses latest sentry and the raven client.

You can easily run the sentry server inside of vagrant:

    $ ./dev-sentry.sh

More docs forthcoming
  • Loading branch information...
1 parent 8e1fc9d commit 2801e85375b8867e2f9274f3b5d2bc1d3986a225 @honza honza committed Apr 20, 2012
View
1 .gitignore
@@ -3,6 +3,7 @@
*.swo
*.swp
*.orig
+*.db
pip-log.txt
deploy/src/*
*.sqlite3
View
1 Vagrantfile
@@ -7,6 +7,7 @@ Vagrant::Config.run do |config|
config.vm.forward_port 80, 8000
config.vm.forward_port 8983, 8983
+ config.vm.forward_port 9000, 9000
config.vm.share_folder "unisubs", "/opt/unisubs", "."
View
1 apps/accountlinker/views.py
@@ -33,7 +33,6 @@
from videos.types.youtube import YouTubeApiBridge
import logging
-import sentry_logger # Magical import to make sure Sentry's error recording happens.
logger = logging.getLogger("authbelt.views")
View
7 apps/messages/tasks.py
@@ -32,7 +32,8 @@
from django.template.loader import render_to_string
from django.contrib.contenttypes.models import ContentType
-from sentry.client.models import client
+from raven.contrib.django.models import get_client
+
from celery.task import task
from auth.models import CustomUser as User
@@ -47,6 +48,10 @@
from utils import get_object_or_none
from utils.translation import get_language_label
+
+client = get_client()
+
+
def get_url_base():
return "http://" + Site.objects.get_current().domain
View
6 apps/teams/models.py
@@ -16,6 +16,7 @@
# along with this program. If not, see
# http://www.gnu.org/licenses/agpl-3.0.html.
import datetime
+import logging
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
@@ -50,6 +51,8 @@
from videos.models import Video, SubtitleLanguage, SubtitleVersion
+logger = logging.getLogger(__name__)
+
ALL_LANGUAGES = [(val, _(name))for val, name in settings.ALL_LANGUAGES]
@@ -2139,9 +2142,6 @@ class TeamNotificationSetting(models.Model):
objects = TeamNotificationSettingManager()
def get_notification_class(self):
- # move this import to the module level and test_settings break. Fun.
- import sentry_logger
- logger = sentry_logger.logging.getLogger("teams.models")
try:
from notificationclasses import NOTIFICATION_CLASS_MAP
View
4 apps/teams/notifications.py
@@ -25,8 +25,8 @@
from libs.unilangs import LanguageCode
from videos.models import Video
-import sentry_logger
-logger = sentry_logger.logging.getLogger("team-notifier")
+import logging
+logger = logging.getLogger("team-notifier")
class BaseNotification(object):
"""
View
2 apps/teams/views.py
@@ -79,8 +79,6 @@
from widget.srt_subs import GenerateSubtitlesHandler
-import sentry_logger # Magical import to make Sentry's error recording happen.
-assert sentry_logger # It's okay, Pyflakes. Trust me.
logger = logging.getLogger("teams.views")
View
4 apps/videos/management/commands/update_video_metadata.py
@@ -2,13 +2,13 @@
from apps.videos.models import Video
from apps.videos.metadata_manager import update_metadata
from time import sleep
-import sentry_logger
import logging
-logger = logging.getLogger(__name__)
import sys
from time import sleep
import math
+logger = logging.getLogger(__name__)
+
class Command(BaseCommand):
def handle(self, *args, **kwargs):
View
9 apps/videos/models.py
@@ -53,6 +53,9 @@
from apps.teams.moderation_const import (
WAITING_MODERATION, APPROVED, MODERATION_STATUSES, UNMODERATED, REJECTED
)
+from raven.contrib.django.models import get_client
+
+client = get_client()
NO_SUBTITLES, SUBTITLES_FINISHED = range(2)
@@ -251,8 +254,7 @@ def update_view_counter(self):
try:
st_video_view_handler_update.delay(video_id=self.video_id)
except:
- from sentry.client.models import client
- client.create_from_exception()
+ client.captureException()
def update_subtitles_fetched(self, lang=None):
"""Queue a Celery task that will increment the number of times this video's subtitles were fetched."""
@@ -264,8 +266,7 @@ def update_subtitles_fetched(self, lang=None):
update_subtitles_fetched_counter_for_sl.delay(sl_pk=lang.pk)
except:
- from sentry.client.models import client
- client.create_from_exception()
+ client.captureException()
def get_thumbnail(self, fallback=True):
"""Return a URL to this video's thumbnail.
View
9 apps/videos/tasks.py
@@ -30,16 +30,17 @@
from django.utils import simplejson as json
from django.utils.http import urlquote_plus
from haystack import site
-from sentry.client.handlers import SentryHandler
-from sentry.client.models import client
+from raven.contrib.django.models import get_client
from messages.models import Message
from utils import send_templated_email, DEFAULT_PROTOCOL
from videos.models import VideoFeed, SubtitleLanguage, Video
from videos.feed_parser import FeedParser
+client = get_client()
celery_logger = logging.getLogger('celery.task')
-celery_logger.addHandler(SentryHandler())
+
+
def process_failure_signal(exception, traceback, sender, task_id,
signal, args, kwargs, einfo, **kw):
exc_info = (type(exception), exception, traceback)
@@ -108,7 +109,7 @@ def update_video_feed(video_feed_id):
video_feed.update()
except VideoFeed:
msg = '**update_video_feed**. VideoFeed does not exist. ID: %s' % video_feed_id
- client.create_from_text(msg, logger='celery')
+ client.captureMessage(msg)
@task(ignore_result=False)
def add(a, b):
View
2 apps/videos/types/youtube.py
@@ -206,8 +206,6 @@ def set_values(self, video_obj):
try:
self.get_subtitles(video_obj)
except :
- import sentry_logger
- logger = logging.getLogger("youtube")
logger.exception("Error getting subs from youtube:" )
return video_obj
View
1 apps/videos/views.py
@@ -64,6 +64,7 @@
'VideosApi': VideosApiClass()
})
+
def index(request):
context = widget.add_onsite_js_files({})
context['all_videos'] = Video.objects.count()
View
2 apps/widget/tests.py
@@ -972,8 +972,6 @@ def test_set_title(self):
self.assertEquals(title, language.get_title())
def test_youtube_ei_failure(self):
- import sentry_logger
- assert sentry_logger # Shut up, Pyflakes.
from utils.requestfactory import RequestFactory
rf = RequestFactory()
request = rf.get("/")
View
3 deploy/requirements.txt
@@ -34,7 +34,8 @@ vendor/boto-2.1.0-0.tar.gz
python-memcached
feedparser
lxml==2.3
-django-sentry==1.8.3.1
+django-sentry
+raven
vendor/indifex-transifex-client-0.5.tar.gz
django-extensions==0.4.1
# do we really need this in prod?
View
3 dev-sentry.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+sentry --config=sentry.dev.conf.py start
View
48 dev_settings.py
@@ -75,6 +75,54 @@
COMPRESS_MEDIA = not DEBUG
+LOGGING = {
+ 'version': 1,
+ 'disable_existing_loggers': True,
+ 'root': {
+ 'level': 'WARNING',
+ 'handlers': ['sentry'],
+ },
+ 'formatters': {
+ 'verbose': {
+ 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
+ },
+ },
+ 'handlers': {
+ 'sentry': {
+ 'level': 'WARNING',
+ 'class': 'raven.contrib.django.handlers.SentryHandler',
+ },
+ 'console': {
+ 'level': 'DEBUG',
+ 'class': 'logging.StreamHandler',
+ 'formatter': 'verbose'
+ }
+ },
+ 'loggers': {
+ 'django.db.backends': {
+ 'level': 'ERROR',
+ 'handlers': ['sentry'],
+ 'propagate': False,
+ },
+ 'raven': {
+ 'level': 'DEBUG',
+ 'handlers': ['console'],
+ 'propagate': False,
+ },
+ 'sentry.errors': {
+ 'level': 'DEBUG',
+ 'handlers': ['console'],
+ 'propagate': False,
+ },
+ },
+}
+
+# Change this to your local sentry dsn
+# You can find it under the account tab
+# Also, make sure that the host is `localhost` and the port is `9000`
+SENTRY_DSN = "change this to your local dsn"
+SENTRY_DEBUG = True
+
try:
from settings_local import *
except ImportError:
View
47 sentry.dev.conf.py
@@ -0,0 +1,47 @@
+
+import os.path
+
+CONF_ROOT = os.path.dirname(__file__)
+
+DATABASES = {
+ 'default': {
+ # You can swap out the engine for MySQL easily by changing this value
+ # to ``django.db.backends.mysql`` or to PostgreSQL with
+ # ``django.db.backends.postgresql_psycopg2``
+ 'ENGINE': 'django.db.backends.sqlite3',
+ 'NAME': os.path.join(CONF_ROOT, 'sentry.db'),
+ 'USER': 'postgres',
+ 'PASSWORD': '',
+ 'HOST': '',
+ 'PORT': '',
+ }
+}
+
+SENTRY_KEY = 'XHysAJPnkHmeRjcZzFxzgDgCD6FyYADOnAjrzxPxTOTOJeYHS1Y1mg=='
+
+# Set this to false to require authentication
+SENTRY_PUBLIC = True
+
+# You should configure the absolute URI to Sentry. It will attempt to guess it if you don't
+# but proxies may interfere with this.
+# SENTRY_URL_PREFIX = 'http://sentry.example.com' # No trailing slash!
+
+SENTRY_WEB_HOST = '0.0.0.0'
+SENTRY_WEB_PORT = 9000
+SENTRY_WEB_OPTIONS = {
+ 'workers': 3, # the number of gunicorn workers
+ # 'worker_class': 'gevent',
+}
+
+# Mail server configuration
+
+# For more information check Django's documentation:
+# https://docs.djangoproject.com/en/1.3/topics/email/?from=olddocs#e-mail-backends
+
+EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
+
+EMAIL_HOST = 'localhost'
+EMAIL_HOST_PASSWORD = ''
+EMAIL_HOST_USER = ''
+EMAIL_PORT = 25
+EMAIL_USE_TLS = False
View
30 sentry_logger.py
@@ -1,30 +0,0 @@
-# Amara, universalsubtitles.org
-#
-# Copyright (C) 2012 Participatory Culture Foundation
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see
-# http://www.gnu.org/licenses/agpl-3.0.html.
-
-import logging
-from sentry.client.handlers import SentryHandler
-
-logger = logging.getLogger()
-# ensure we havent already registered the handler
-if SentryHandler not in map(lambda x: x.__class__, logger.handlers):
- logger.addHandler(SentryHandler(logging.WARNING))
-
- # Add StreamHandler to sentry's default so you can catch missed exceptions
- logger = logging.getLogger('sentry.errors')
- logger.propagate = False
- logger.addHandler(logging.StreamHandler())
View
5 settings.py
@@ -310,6 +310,8 @@ def rel(*x):
MIDDLEWARE_CLASSES = (
+ 'raven.contrib.django.middleware.SentryResponseErrorIdMiddleware',
+ 'raven.contrib.django.middleware.Sentry404CatchMiddleware',
'middleware.ResponseTimeMiddleware',
'utils.ajaxmiddleware.AjaxErrorMiddleware',
'localeurl.middleware.LocaleURLMiddleware',
@@ -368,8 +370,7 @@ def rel(*x):
'livesettings',
'paging',
'rosetta',
- 'sentry',
- 'sentry.client',
+ 'raven.contrib.django',
'sorl.thumbnail',
'south',
'tastypie',
View
1 urls.py
@@ -24,7 +24,6 @@
from sitemaps import sitemaps, sitemap_view, sitemap_index
from socialauth.models import (AuthMeta, OpenidProfile, TwitterUserProfile,
FacebookUserProfile)
-import sentry_logger
admin.autodiscover()
View
4 utils/__init__.py
@@ -170,7 +170,9 @@ def send_templated_email(to, subject, body_template, body_dict,
print >> sys.stderr, "Oboe error: %s" % e
return email.send(fail_silently)
-from sentry.client.models import client
+from raven.contrib.django.models import get_client
+
+client = get_client()
def catch_exception(exceptions, subject="", default=None, ignore=False):
"""
View
6 utils/ajaxmiddleware.py
@@ -5,8 +5,10 @@
from django.db.models.base import ObjectDoesNotExist
from django.http import HttpResponse, Http404
from django.utils.translation import ugettext as _
-from sentry.client.models import client
+from raven.contrib.django.models import get_client
+
+client = get_client()
class AjaxErrorMiddleware(object):
'''Return AJAX errors to the browser in a sensible way.
@@ -55,7 +57,7 @@ def bad_request(self, request, exception):
def server_error(self, request, exception):
exc_info = sys.exc_info()
- client.create_from_exception(exc_info)
+ client.captureException()
if settings.DEBUG:
(exc_type, exc_info, tb) = exc_info
View
6 utils/amazon/__init__.py
@@ -18,7 +18,9 @@
from django.conf import settings
from django.core.files.storage import FileSystemStorage
from django.core.files import File
-from sentry.client.models import client
+from raven.contrib.django.models import get_client
+
+client = get_client()
from fields import S3EnabledImageField, S3EnabledFileField
@@ -90,7 +92,7 @@ def _save(self, name, content):
key.make_public()
return name
except (BotoClientError, BotoServerError), e:
- client.create_from_exception()
+ client.captureException()
raise S3StorageError(*e.args)
def _get_traceback(self):
View
2 utils/celery_search_index.py
@@ -31,8 +31,6 @@ def remove_handler(self, instance, **kwargs):
def log(*args, **kwargs):
- import sentry_logger
- assert sentry_logger # Shut up, Pyflakes.
import logging
logger = logging.getLogger('search.index.updater')
logger.warning(*args, **kwargs)
View
7 utils/commands.py
@@ -1,9 +1,12 @@
from django.core.management.base import BaseCommand
-from sentry.client.models import client
+from raven.contrib.django.models import get_client
+
+client = get_client()
+
class ErrorHandlingCommand(BaseCommand):
def handle_error(self, exc_info):
- client.create_from_exception(exc_info)
+ client.captureException()
def print_to_console(self, msg, min_verbosity=1):
if self.verbosity >= min_verbosity:
View
5 utils/errorreport.py
@@ -18,7 +18,10 @@
import datetime
from django.contrib.sites.models import Site
-from sentry.models import GroupedMessage
+try:
+ from sentry.models import GroupedMessage
+except ImportError:
+ pass
def _errors_seen_on(date, last_seen=True):
View
7 utils/management/commands/clean_sentry.py
@@ -17,7 +17,10 @@
# http://www.gnu.org/licenses/agpl-3.0.html.
from django.core.management.base import BaseCommand
-from sentry.models import Message, GroupedMessage, FilterValue
+try:
+ from sentry.models import Message, GroupedMessage, FilterValue
+except ImportError:
+ pass
class Command(BaseCommand):
@@ -30,4 +33,4 @@ def handle(self, *args, **kwargs):
count = GroupedMessage.objects.count()
print 'Delete %s GroupedMessage' % count
- GroupedMessage.objects.all().delete()
+ GroupedMessage.objects.all().delete()
View
2 utils/management/commands/version_s3.py
@@ -17,11 +17,11 @@
# http://www.gnu.org/licenses/agpl-3.0.html.
from django.core.management.base import BaseCommand
-from sentry.models import Message, GroupedMessage, FilterValue
import datetime
from storages.backends import s3boto
try:
from boto.s3 import Key
+ from sentry.models import Message, GroupedMessage, FilterValue
except:
from boto.s3 import key
Key = key.Key

0 comments on commit 2801e85

Please sign in to comment.