diff --git a/doc/admin/config.rst b/doc/admin/config.rst index 6ca0d9e346..8e3d5e2169 100644 --- a/doc/admin/config.rst +++ b/doc/admin/config.rst @@ -16,7 +16,9 @@ the files found before. The file is expected to be in the INI format as specified in the `Python documentation`_. -The config file may contain the following sections (all settings are optional and have default values). +The config file may contain the following sections (all settings are optional and have +default values). We suggest that you start from the examples given in one of the +installation tutorials. pretix settings --------------- @@ -205,7 +207,6 @@ If no memcached is configured, pretix will use Django's built-in local-memory ca shared memcached instance, not multiple ones, because cache invalidations would not be propagated otherwise. - Redis ----- @@ -242,6 +243,19 @@ RabbitMQ might be the better choice if you have a complex, multi-server, high-pe but as you already should have a redis instance ready for session and lock storage, we recommend redis for convenience. See the `Celery documentation`_ for more details. +Sentry +------ + +pretix has native support for sentry, a tool that you can use to track errors in the +application. If you want to use sentry, you need to set a DSN in the configuration file. + + [sentry] + dsn=https://:@sentry.io/ + +``dsn`` + You will be given this value by your sentry installation. + + Secret length ------------- diff --git a/src/pretix/base/services/cart.py b/src/pretix/base/services/cart.py index 4be7162558..932aae9d34 100644 --- a/src/pretix/base/services/cart.py +++ b/src/pretix/base/services/cart.py @@ -218,7 +218,7 @@ def _add_items_to_cart(event: Event, items: List[dict], cart_id: str=None) -> No raise CartError(err) -@app.task(base=ProfiledTask, bind=True, max_retries=5, default_retry_delay=1) +@app.task(base=ProfiledTask, bind=True, max_retries=5, default_retry_delay=1, throws=(CartError,)) def add_items_to_cart(self, event: int, items: List[dict], cart_id: str=None) -> None: """ Adds a list of items to a user's cart. @@ -259,7 +259,7 @@ def _remove_items_from_cart(event: Event, items: List[dict], cart_id: str) -> No cp.delete() -@app.task(base=ProfiledTask, bind=True, max_retries=5, default_retry_delay=1) +@app.task(base=ProfiledTask, bind=True, max_retries=5, default_retry_delay=1, throws=(CartError,)) def remove_items_from_cart(self, event: int, items: List[dict], cart_id: str=None) -> None: """ Removes a list of items from a user's cart. diff --git a/src/pretix/base/services/orders.py b/src/pretix/base/services/orders.py index 020e3db525..e45935cc43 100644 --- a/src/pretix/base/services/orders.py +++ b/src/pretix/base/services/orders.py @@ -602,7 +602,7 @@ class OrderChangeManager: raise OrderError(error_messages['internal']) -@app.task(base=ProfiledTask, bind=True, max_retries=5, default_retry_delay=1) +@app.task(base=ProfiledTask, bind=True, max_retries=5, default_retry_delay=1, throws=(OrderError,)) def perform_order(self, event: str, payment_provider: str, positions: List[str], email: str=None, locale: str=None, address: int=None, meta_info: dict=None): try: @@ -614,7 +614,7 @@ def perform_order(self, event: str, payment_provider: str, positions: List[str], return OrderError(error_messages['busy']) -@app.task(base=ProfiledTask, bind=True, max_retries=5, default_retry_delay=1) +@app.task(base=ProfiledTask, bind=True, max_retries=5, default_retry_delay=1, throws=(OrderError,)) def cancel_order(self, order: int, user: int=None): try: try: diff --git a/src/pretix/celery.py b/src/pretix/celery.py index b451c0dd5a..4a5a598f73 100644 --- a/src/pretix/celery.py +++ b/src/pretix/celery.py @@ -9,3 +9,10 @@ from django.conf import settings app = Celery('pretix') app.config_from_object('django.conf:settings', namespace='CELERY') app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) + + +if hasattr(settings, 'RAVEN_CONFIG'): + # Celery signal registration + from raven.contrib.celery import register_signal + from raven.contrib.django.models import client + register_signal(client, ignore_expected=True) diff --git a/src/pretix/control/middleware.py b/src/pretix/control/middleware.py index 28350cb031..2a79457220 100644 --- a/src/pretix/control/middleware.py +++ b/src/pretix/control/middleware.py @@ -30,9 +30,11 @@ class PermissionMiddleware(MiddlewareMixin): def process_request(self, request): url = resolve(request.path_info) url_name = url.url_name + if not request.path.startswith(get_script_prefix() + 'control'): # This middleware should only touch the /control subpath return + if hasattr(request, 'organizer'): # If the user is on a organizer's subdomain, he should be redirected to pretix return redirect(urljoin(settings.SITE_URL, request.get_full_path())) diff --git a/src/pretix/settings.py b/src/pretix/settings.py index 4e2f026681..b030f16d4e 100644 --- a/src/pretix/settings.py +++ b/src/pretix/settings.py @@ -7,6 +7,7 @@ from django.contrib.messages import constants as messages # NOQA from django.utils.crypto import get_random_string from django.utils.translation import ugettext_lazy as _ # NOQA from pkg_resources import iter_entry_points +from . import __version__ config = configparser.RawConfigParser() config.read(['/etc/pretix/pretix.cfg', os.path.expanduser('~/.pretix.cfg'), 'pretix.cfg'], @@ -205,6 +206,19 @@ for entry_point in iter_entry_points(group='pretix.plugin', name=None): PLUGINS.append(entry_point.module_name) INSTALLED_APPS.append(entry_point.module_name) +if config.has_option('sentry', 'dsn'): + INSTALLED_APPS += [ + 'raven.contrib.django.raven_compat', + ] + DISABLE_SENTRY_INSTRUMENTATION = True # see celery.py for more, we use this differently + RAVEN_CONFIG = { + 'dsn': config.get('sentry', 'dsn'), + 'transport': 'raven.transport.threaded_requests.ThreadedRequestsHTTPTransport', + 'release': __version__, + 'environment': SITE_URL, + } + + CORE_MODULES = { ("pretix", "base"), ("pretix", "presale"), diff --git a/src/requirements/production.txt b/src/requirements/production.txt index 85f3d65431..bfac621621 100644 --- a/src/requirements/production.txt +++ b/src/requirements/production.txt @@ -29,4 +29,4 @@ csscompressor django-markup markdown bleach - +raven