@@ -46,7 +46,7 @@ def test_user_function_can_retrieve_execution_id_from_header():
4646
4747
4848def test_uncaught_exception_in_user_function_sets_execution_id (capsys , monkeypatch ):
49- monkeypatch .setenv ("LOG_EXECUTION_ID" , "True " )
49+ monkeypatch .setenv ("LOG_EXECUTION_ID" , "true " )
5050 source = TEST_FUNCTIONS_DIR / "execution_id" / "main.py"
5151 target = "error"
5252 app = create_app (target , source )
@@ -64,7 +64,7 @@ def test_uncaught_exception_in_user_function_sets_execution_id(capsys, monkeypat
6464
6565
6666def test_print_from_user_function_sets_execution_id (capsys , monkeypatch ):
67- monkeypatch .setenv ("LOG_EXECUTION_ID" , "True " )
67+ monkeypatch .setenv ("LOG_EXECUTION_ID" , "true " )
6868 source = TEST_FUNCTIONS_DIR / "execution_id" / "main.py"
6969 target = "print_message"
7070 app = create_app (target , source )
@@ -83,7 +83,7 @@ def test_print_from_user_function_sets_execution_id(capsys, monkeypatch):
8383
8484
8585def test_log_from_user_function_sets_execution_id (capsys , monkeypatch ):
86- monkeypatch .setenv ("LOG_EXECUTION_ID" , "True " )
86+ monkeypatch .setenv ("LOG_EXECUTION_ID" , "true " )
8787 source = TEST_FUNCTIONS_DIR / "execution_id" / "main.py"
8888 target = "log_message"
8989 app = create_app (target , source )
@@ -136,6 +136,44 @@ def test_does_not_set_execution_id_when_not_enabled(capsys):
136136 assert "some-message" in record .out
137137
138138
139+ def test_does_not_set_execution_id_when_env_var_is_false (capsys , monkeypatch ):
140+ monkeypatch .setenv ("LOG_EXECUTION_ID" , "false" )
141+ source = TEST_FUNCTIONS_DIR / "execution_id" / "main.py"
142+ target = "print_message"
143+ app = create_app (target , source )
144+ client = app .test_client ()
145+ client .post (
146+ "/" ,
147+ headers = {
148+ "Function-Execution-Id" : TEST_EXECUTION_ID ,
149+ "Content-Type" : "application/json" ,
150+ },
151+ json = {"message" : "some-message" },
152+ )
153+ record = capsys .readouterr ()
154+ assert f'"execution_id": "{ TEST_EXECUTION_ID } "' not in record .out
155+ assert "some-message" in record .out
156+
157+
158+ def test_does_not_set_execution_id_when_env_var_is_not_bool_like (capsys , monkeypatch ):
159+ monkeypatch .setenv ("LOG_EXECUTION_ID" , "maybe" )
160+ source = TEST_FUNCTIONS_DIR / "execution_id" / "main.py"
161+ target = "print_message"
162+ app = create_app (target , source )
163+ client = app .test_client ()
164+ client .post (
165+ "/" ,
166+ headers = {
167+ "Function-Execution-Id" : TEST_EXECUTION_ID ,
168+ "Content-Type" : "application/json" ,
169+ },
170+ json = {"message" : "some-message" },
171+ )
172+ record = capsys .readouterr ()
173+ assert f'"execution_id": "{ TEST_EXECUTION_ID } "' not in record .out
174+ assert "some-message" in record .out
175+
176+
139177def test_generate_execution_id ():
140178 expected_matching_regex = "^[0-9a-zA-Z]{12}$"
141179 actual_execution_id = execution_id ._generate_execution_id ()
@@ -283,7 +321,7 @@ def test_log_handler_omits_empty_execution_context(monkeypatch, capsys):
283321
284322@pytest .mark .asyncio
285323async def test_maintains_execution_id_for_concurrent_requests (monkeypatch , capsys ):
286- monkeypatch .setenv ("LOG_EXECUTION_ID" , "True " )
324+ monkeypatch .setenv ("LOG_EXECUTION_ID" , "true " )
287325 monkeypatch .setattr (
288326 execution_id ,
289327 "_generate_execution_id" ,
0 commit comments