Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to new sentry-sdk #4

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ You must provide a Sentry DSN::

sentry.dsn = https://xxxxxx:[email protected]/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::

Expand All @@ -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
29 changes: 22 additions & 7 deletions ckanext/sentry/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
'''
Expand All @@ -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))
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
raven==6.1.0
blinker==1.4
sentry-sdk==1.3.1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down