From efd6c23f0044b24ab96088f362d508dc0b6bd890 Mon Sep 17 00:00:00 2001 From: Michael Lavers Date: Tue, 18 Jun 2019 18:21:39 -0700 Subject: [PATCH 1/2] Fix IOPIPE_TRACE_AUTO_HTTP_ENABLED env var logic --- iopipe/contrib/trace/plugin.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/iopipe/contrib/trace/plugin.py b/iopipe/contrib/trace/plugin.py index bfb64e0f..b0de41a9 100644 --- a/iopipe/contrib/trace/plugin.py +++ b/iopipe/contrib/trace/plugin.py @@ -31,9 +31,11 @@ def __init__( :type http_headers: list|tuple """ self.auto_measure = auto_measure - self.auto_http = auto_http is True or strtobool( - os.getenv("IOPIPE_TRACE_AUTO_HTTP_ENABLED", "false") - ) + self.auto_http = auto_http + if "IOPIPE_TRACE_AUTO_HTTP_ENABLED" in os.environ: + self.auto_http = strtobool( + os.getenv("IOPIPE_TRACE_AUTO_HTTP_ENABLED", "true") + ) self.http_filter = http_filter self.http_headers = http_headers From d70809a2bc4598d6608e047bcfdf52f2aae8b274 Mon Sep 17 00:00:00 2001 From: Michael Lavers Date: Tue, 18 Jun 2019 19:31:46 -0700 Subject: [PATCH 2/2] Add test --- iopipe/contrib/trace/plugin.py | 4 ++-- tests/contrib/trace/test_plugin.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/iopipe/contrib/trace/plugin.py b/iopipe/contrib/trace/plugin.py index b0de41a9..6e225fdf 100644 --- a/iopipe/contrib/trace/plugin.py +++ b/iopipe/contrib/trace/plugin.py @@ -33,8 +33,8 @@ def __init__( self.auto_measure = auto_measure self.auto_http = auto_http if "IOPIPE_TRACE_AUTO_HTTP_ENABLED" in os.environ: - self.auto_http = strtobool( - os.getenv("IOPIPE_TRACE_AUTO_HTTP_ENABLED", "true") + self.auto_http = bool( + strtobool(os.environ["IOPIPE_TRACE_AUTO_HTTP_ENABLED"]) ) self.http_filter = http_filter self.http_headers = http_headers diff --git a/tests/contrib/trace/test_plugin.py b/tests/contrib/trace/test_plugin.py index f005d9bd..6c5def37 100644 --- a/tests/contrib/trace/test_plugin.py +++ b/tests/contrib/trace/test_plugin.py @@ -1,5 +1,8 @@ import mock +from iopipe import IOpipeCore +from iopipe.contrib.trace import TracePlugin + @mock.patch("iopipe.report.send_report", autospec=True) def test__trace_plugin(mock_send_report, handler_with_trace, mock_context): @@ -180,3 +183,11 @@ def test_trace_plugin__auto_http__filter_request( assert len(traces) == 1 assert "request" not in traces[0] assert "response" in traces[0] + + +def test__trace_plugin__auto_http__env_var(monkeypatch): + monkeypatch.setenv("IOPIPE_TRACE_AUTO_HTTP_ENABLED", "false") + + iopipe = IOpipeCore(plugins=[TracePlugin()]) + + assert iopipe.plugins[0].auto_http is False