11import time
2+ import pytest
23
34from lumigo_tracer .spans_container import SpansContainer
45from lumigo_tracer .user_utils import (
@@ -103,7 +104,7 @@ def test_basic_info_warn_error(capsys):
103104 assert captured [2 ] == error_msg
104105
105106
106- def test_add_execution_tag ():
107+ def test_add_execution_tag (lambda_traced ):
107108 key = "my_key"
108109 value = "my_value"
109110 assert add_execution_tag (key , value ) is True
@@ -116,31 +117,31 @@ def test_start_manual_trace_simple_flow():
116117 assert SpansContainer .get_span ().function_span [MANUAL_TRACES_KEY ]
117118
118119
119- def test_add_execution_key_tag_empty (capsys ):
120+ def test_add_execution_key_tag_empty (capsys , lambda_traced ):
120121 assert add_execution_tag ("" , "value" ) is False
121122 assert "Unable to add tag: key length" in capsys .readouterr ().out
122123 assert SpansContainer .get_span ().execution_tags == []
123124
124125
125- def test_add_execution_value_tag_empty (capsys ):
126+ def test_add_execution_value_tag_empty (capsys , lambda_traced ):
126127 assert add_execution_tag ("key" , "" ) is False
127128 assert "Unable to add tag: value length" in capsys .readouterr ().out
128129 assert SpansContainer .get_span ().execution_tags == []
129130
130131
131- def test_add_execution_tag_key_pass_max_chars (capsys ):
132+ def test_add_execution_tag_key_pass_max_chars (capsys , lambda_traced ):
132133 assert add_execution_tag ("k" * (MAX_TAG_KEY_LEN + 1 ), "value" ) is False
133134 assert "Unable to add tag: key length" in capsys .readouterr ().out
134135 assert SpansContainer .get_span ().execution_tags == []
135136
136137
137- def test_add_execution_tag_value_pass_max_chars (capsys ):
138+ def test_add_execution_tag_value_pass_max_chars (capsys , lambda_traced ):
138139 assert add_execution_tag ("key" , "v" * (MAX_TAG_VALUE_LEN + 1 )) is False
139140 assert "Unable to add tag: value length" in capsys .readouterr ().out
140141 assert SpansContainer .get_span ().execution_tags == []
141142
142143
143- def test_add_execution_tag_pass_max_tags (capsys ):
144+ def test_add_execution_tag_pass_max_tags (capsys , lambda_traced ):
144145 key = "my_key"
145146 value = "my_value"
146147
@@ -166,3 +167,34 @@ def __str__(self):
166167 assert add_execution_tag ("key" , ExceptionOnStr ()) is False
167168 assert "Unable to add tag" in capsys .readouterr ().out
168169 assert SpansContainer .get_span ().execution_tags == []
170+
171+
172+ @pytest .mark .parametrize (
173+ ["kill_switch_value" , "is_aws_environment_value" , "expected_ret_value" , "expected_tags" ],
174+ [
175+ ( # happy flow - lambda is traced
176+ "false" ,
177+ "true" ,
178+ True ,
179+ [{"key" : "key" , "value" : "my-value" }],
180+ ),
181+ ("true" , "true" , False , []), # kill switch on, is_aws_env true
182+ ("true" , "" , False , []), # kill switch on, is_aws_env false
183+ ("false" , "" , False , []), # kill switch off, is_aws_env false
184+ ],
185+ )
186+ def test_add_execution_tag_lambda_not_traced (
187+ kill_switch_value ,
188+ is_aws_environment_value ,
189+ expected_ret_value ,
190+ expected_tags ,
191+ capsys ,
192+ monkeypatch ,
193+ ):
194+ monkeypatch .setenv ("LUMIGO_SWITCH_OFF" , kill_switch_value )
195+ monkeypatch .setenv ("AWS_LAMBDA_FUNCTION_VERSION" , is_aws_environment_value )
196+
197+ assert add_execution_tag ("key" , "my-value" ) is expected_ret_value
198+ if expected_ret_value is False :
199+ assert "Unable to add tag" in capsys .readouterr ().out
200+ assert SpansContainer .get_span ().execution_tags == expected_tags
0 commit comments