Skip to content

Commit 302583c

Browse files
authored
Disable LumigoChalice when outside AWS or by switch-off env var (#256)
1 parent 3a83209 commit 302583c

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

.secrets.baseline

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,14 @@
200200
"filename": "src/test/unit/test_tracer.py",
201201
"hashed_secret": "f13de0da12f8375756b1bc56b248cc8e62e0c302",
202202
"is_verified": false,
203-
"line_number": 329
203+
"line_number": 344
204204
},
205205
{
206206
"type": "Secret Keyword",
207207
"filename": "src/test/unit/test_tracer.py",
208208
"hashed_secret": "dabe695c9892b5cb937379817679c0fb0be6a3df",
209209
"is_verified": false,
210-
"line_number": 407
210+
"line_number": 422
211211
}
212212
],
213213
"src/test/unit/wrappers/http/test_http_parser.py": [
@@ -220,5 +220,5 @@
220220
}
221221
]
222222
},
223-
"generated_at": "2022-08-08T04:42:17Z"
223+
"generated_at": "2022-08-17T15:30:21Z"
224224
}

src/lumigo_tracer/tracer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ class LumigoChalice:
109109
"on_dynamodb_record",
110110
]
111111

112+
def __new__(cls, app, *args, **kwargs):
113+
if is_aws_environment() and not is_kill_switch_on():
114+
return super().__new__(cls)
115+
get_logger().debug("Disabling LumigoChalice")
116+
return app
117+
112118
def __init__(self, app, *args, **kwargs):
113119
self.lumigo_conf_args = args
114120
self.lumigo_conf_kwargs = kwargs

src/test/unit/test_tracer.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@ def lambda_test_function(event, context):
228228
assert http_spans[0]["info"]["httpInfo"]["request"]["headers"]
229229

230230

231-
def test_lumigo_chalice(context):
231+
def test_lumigo_chalice(context, monkeypatch):
232+
# mimic aws env
233+
monkeypatch.setenv("AWS_LAMBDA_FUNCTION_VERSION", "true")
234+
232235
class App:
233236
@property
234237
def a(self):
@@ -255,7 +258,7 @@ def __call__(self, *args, **kwargs):
255258

256259
def test_lumigo_chalice_create_extra_lambdas(monkeypatch, context):
257260
# mimic aws env
258-
monkeypatch.setitem(os.environ, "AWS_LAMBDA_FUNCTION_VERSION", "true")
261+
monkeypatch.setenv("AWS_LAMBDA_FUNCTION_VERSION", "true")
259262

260263
class Chalice:
261264
"""
@@ -293,6 +296,18 @@ def handler(event, context):
293296
assert SpansContainer._span
294297

295298

299+
def test_lumigo_chalice_disabled_when_not_in_aws(monkeypatch):
300+
monkeypatch.delenv("AWS_LAMBDA_FUNCTION_VERSION", raising=False)
301+
monkeypatch.delenv("LUMIGO_SWITCH_OFF", raising=False)
302+
assert LumigoChalice("myApp") == "myApp"
303+
304+
305+
def test_lumigo_chalice_disabled_when_switch_off(monkeypatch):
306+
monkeypatch.setenv("AWS_LAMBDA_FUNCTION_VERSION", "true")
307+
monkeypatch.setenv("LUMIGO_SWITCH_OFF", "true")
308+
assert LumigoChalice("myApp") == "myApp"
309+
310+
296311
@pytest.mark.parametrize(
297312
"event, expected_triggered_by, expected_message_id",
298313
[

0 commit comments

Comments
 (0)