diff --git a/README.md b/README.md index 8798108..8e75d20 100644 --- a/README.md +++ b/README.md @@ -30,10 +30,16 @@ Example: And that's all. Deploy your zappa function and you should see any errors appearing on sentry. +If you want the exception handler to capture the exception and capture it, just replace `zappa_sentry.unhandled_exceptions` by `zappa_sentry.capture_exceptions`. This version won't let the exceptions propagate. + # Sentry raven client If you need sentry's client to add extra information just do: -`from zappa_sentry import raven_client` +``` +from zappa_sentry import get_raven_client + +raven_client = get_raven_client() +``` And you'll get an already initialized raven_client. Feel free to use to add context, tags, etc. diff --git a/setup.py b/setup.py index c595f60..c5d9dbc 100644 --- a/setup.py +++ b/setup.py @@ -3,12 +3,12 @@ setup( name = 'zappa_sentry', packages = ['zappa_sentry'], - version = '0.1.6', + version = '0.2.0', description = 'Easy integration with sentry for zappa apps', author = 'João Miguel Neves', author_email = 'joao@silvaneves.org', url = 'https://github.com/jneves/zappa-sentry', - download_url = 'https://github.com/jneves/zappa-sentry/archive/0.1.4.tar.gz', + download_url = 'https://github.com/jneves/zappa-sentry/archive/0.2.0.tar.gz', keywords = 'logging zappa sentry', install_requires=[ 'raven' diff --git a/zappa_sentry/__init__.py b/zappa_sentry/__init__.py index cc4aacf..00dd88b 100644 --- a/zappa_sentry/__init__.py +++ b/zappa_sentry/__init__.py @@ -1,13 +1,25 @@ +from configparser import ConfigParser import json import os from raven import Client from raven.transport.http import HTTPTransport -raven_client = Client(os.environ['SENTRY_DSN'], transport=HTTPTransport) + +raven_config = ConfigParser(os.environ) +_raven_client = None + + +def get_raven_client(): + if not _raven_client: + _raven_client = Client(raven_config.get('DEFAULT', 'SENTRY_DSN'), transport=HTTPTransport) + return _raven_client def unhandled_exceptions(e, event, context): + """Exception handler reports exceptions to sentry but does not capture them.""" + raven_client = get_raven_client() + try: package_info_file = open('package_info.json', 'r') package_info = json.load(package_info_file) @@ -36,4 +48,11 @@ def unhandled_exceptions(e, event, context): }}) raven_client.captureException() + return False + + +def capture_exceptions(e, event, context): + """Exception handler that makes exceptions disappear after processing them.""" + + unhandled_exceptions(e, event, context) return True