Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Kevin Glisson <kevgliss>
Mike Grima <mikegrima> @THISisPLACEHLDR
Michal Przytulski <mprzytulski>
Björn Andersson <bjorn-spire>
Joakim Uddholm <tethik>
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ unhandled exceptions, forwards them to Sentry and returns the exception like
any regular error generated by your function.

### Local Development
By default the library will only forward errors to Sentry when deployed on
AWS Lambda, not during local development. If you want to change this behavior
set the `filter_local` config option to `False`.
By default the library will not forward errors is if either the `IS_OFFLINE` or `IS_LOCAL` environment variable is set.
If you want to change this behavior set the `filter_local` config option to `False`.

### Detecting Slow Running Code
It's a good practice to specify the function timeout in `serverless.yml` to
Expand Down
5 changes: 5 additions & 0 deletions raven_python_lambda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def configure_raven_client(config):
is_local_env = os.environ.get('IS_OFFLINE') or os.environ.get('IS_LOCAL')
if config['filter_local'] and is_local_env:
logger.warning('Sentry is disabled in local environment')
config["enabled"] = False
return None

defaults = {
'include_paths': (
Expand Down Expand Up @@ -110,6 +112,9 @@ def __init__(self, config=None):
else:
self.config['raven_client'] = configure_raven_client(self.config)

if self.config['logging'] and self.config['raven_client']:
setup_logging(SentryHandler(self.config['raven_client']))

if self.config['logging']:
handler = SentryHandler(self.config['raven_client'])
handler.setLevel(self.config['log_level'])
Expand Down
25 changes: 24 additions & 1 deletion raven_python_lambda/tests/test_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_can_override_configuration():

assert r.config['logging'] is False, 'expected the config option to be overridden'


class FakeContext(object):
def get_remaining_time_in_millis(self):
return 300000
Expand Down Expand Up @@ -49,3 +49,26 @@ def test_func(event, context):
# Check that it sent to SQS:
messages = sqs.receive_message(QueueUrl=sqs_queue)["Messages"]
assert len(messages) == 1


def test_that_local_environment_is_ignored(monkeypatch):
keys = ['IS_OFFLINE', 'IS_LOCAL']
for k in keys:
monkeypatch.setenv(k, 'yes.')
wrapper = RavenLambdaWrapper()
assert not wrapper.config['enabled']
assert not wrapper.config['raven_client']
monkeypatch.delenv(k)


def test_that_remote_environment_is_not_ignored(monkeypatch):
keys = ['IS_OFFLINE', 'IS_LOCAL']
for k in keys:
try:
monkeypatch.delenv(k)
except:
pass

wrapper = RavenLambdaWrapper()
assert wrapper.config['enabled']
assert wrapper.config['raven_client']