Skip to content

Commit

Permalink
Feature/disable iopipe (#96)
Browse files Browse the repository at this point in the history
* adding option to disable iopipe plugin using env var

* added readme note for disabling iopipe plugin using env var

* addition to docstring for disabling iopipe

* enabled config implementation changed as suggested

* additional tests for enabling/disabling iopipe
  • Loading branch information
mislavcimpersak authored and kolanos committed Oct 4, 2017
1 parent a4159c0 commit f7917d3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ def handler(event, context):

This makes it easy to add custom data and telemetry within your function.

### Disabling IOpipe

If you need to disable IOpipe monitoring during development or in any other situation you can set `IOPIPE_ENABLED` environment variable to `False`.

Default for `IOPIPE_ENABLED` environment variable is `True`.

## Copyright

Provided under the Apache-2.0 license. See LICENSE for details.
Expand Down
2 changes: 2 additions & 0 deletions iopipe/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from distutils.util import strtobool
import os

from .collector import get_collector_path, get_hostname
Expand All @@ -14,6 +15,7 @@ def set_config(**config):
config.setdefault('network_timeout', 5000)
config.setdefault('timeout_window', os.getenv('IOPIPE_TIMEOUT_WINDOW', 150))
config.setdefault('install_method', 'manual')
config.setdefault('enabled', bool(strtobool(os.getenv('IOPIPE_ENABLED', 'true'))))
config.setdefault('plugins', [])

if 'url' in config:
Expand Down
4 changes: 4 additions & 0 deletions iopipe/iopipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def err(self, err):

def decorator(self, fun):
def wrapped(event, context):
# if env var IOPIPE_ENABLED is set to False skip reporting
if self.config['enabled'] is False:
return fun(event, context)

if not self.config['client_id']:
warnings.warn('Your function is decorated with iopipe, but a valid token was not found.')

Expand Down
36 changes: 36 additions & 0 deletions iopipe/tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os

from iopipe.config import set_config


def test_set_config__iopipe_enabled__default():
config = set_config()
assert config['enabled'] is True


def test_set_config__iopipe_enabled__title_case_true():
os.environ['IOPIPE_ENABLED'] = 'True'

config = set_config()
assert config['enabled'] is True


def test_set_config__iopipe_enabled__small_caps_true():
os.environ['IOPIPE_ENABLED'] = 'true'

config = set_config()
assert config['enabled'] is True


def test_set_config__iopipe_enabled__title_case_false():
os.environ['IOPIPE_ENABLED'] = 'False'

config = set_config()
assert config['enabled'] is False


def test_set_config__iopipe_enabled__small_caps_false():
os.environ['IOPIPE_ENABLED'] = 'false'

config = set_config()
assert config['enabled'] is False

0 comments on commit f7917d3

Please sign in to comment.