diff --git a/README.rst b/README.rst index f9ecb05..671f587 100644 --- a/README.rst +++ b/README.rst @@ -34,7 +34,7 @@ You must provide a Sentry DSN:: sentry.dsn = https://xxxxxx:xxxxxx@sentry.domain.com/1 -You can see a full list of supported options for the Sentry client on the `official Raven documentation`_. +You can see a full list of supported options for the Sentry client on the `official Sentry documentation`_. If you want Sentry to record your log messages, you can turn it on adding the following options:: @@ -55,5 +55,5 @@ The configuration also supports env vars named like the `ckanext-envvars`_ exten .. _Sentry: http://getsentry.com/ -.. _official Raven documentation: http://raven.readthedocs.org/en/latest/advanced.html#configuring-the-client +.. _official Sentry documentation: https://docs.sentry.io/error-reporting/configuration/?platform=python .. _ckanext-envvars: https://github.com/okfn/ckanext-envvars diff --git a/ckanext/sentry/plugins.py b/ckanext/sentry/plugins.py index ac7b978..0e25cb4 100644 --- a/ckanext/sentry/plugins.py +++ b/ckanext/sentry/plugins.py @@ -4,8 +4,10 @@ import os import logging -from raven.contrib.pylons import Sentry -from raven.handlers.logging import SentryHandler +import sentry_sdk +from sentry_sdk.integrations.logging import LoggingIntegration, SentryHandler +from sentry_sdk.integrations.flask import FlaskIntegration +from sentry_sdk.integrations.rq import RqIntegration from ckan import plugins @@ -44,7 +46,16 @@ def make_error_log_middleware(self, app, config): self._configure_logging(config) log.debug('Adding Sentry middleware...') - return Sentry(app, config) + sentry_log_level = config.get('sentry.log_level', logging.INFO) + sentry_sdk.init( + dsn=config.get('sentry.dsn'), + integrations=[ + FlaskIntegration(), + LoggingIntegration(level=sentry_log_level), + RqIntegration() + ] + ) + return app def _configure_logging(self, config): ''' @@ -53,15 +64,19 @@ def _configure_logging(self, config): Based on @rshk work on https://github.com/opendatatrentino/ckanext-sentry ''' - handler = SentryHandler(config.get('sentry.dsn')) + handler = SentryHandler() handler.setLevel(logging.NOTSET) - loggers = ['', 'ckan', 'ckanext', 'sentry.errors'] sentry_log_level = config.get('sentry.log_level', logging.INFO) - for name in loggers: - logger = logging.getLogger(name) + logger = logging.getLogger() + # ensure we haven't already registered the handler + if SentryHandler not in map(lambda x: x.__class__, logger.handlers): logger.addHandler(handler) logger.setLevel(sentry_log_level) + # Add StreamHandler to sentry's default so you can catch missed exceptions + logger = logging.getLogger('sentry.errors') + logger.propagate = False + logger.addHandler(logging.StreamHandler()) log.debug('Setting up Sentry logger with level {0}'.format( sentry_log_level)) diff --git a/requirements.txt b/requirements.txt index eb0d457..8c2e42a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -raven==6.1.0 +blinker==1.4 +sentry-sdk==1.3.1 diff --git a/setup.py b/setup.py index dde9b93..e5cfadb 100644 --- a/setup.py +++ b/setup.py @@ -50,7 +50,7 @@ def rst(filename): namespace_packages=['ckanext'], include_package_data=True, zip_safe=False, - install_requires=['raven'], + install_requires=['sentry_sdk'], entry_points={ 'ckan.plugins': [ 'sentry = ckanext.sentry.plugins:SentryPlugin',