@@ -46,7 +46,7 @@ def test_user_function_can_retrieve_execution_id_from_header():
46
46
47
47
48
48
def 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 " )
50
50
source = TEST_FUNCTIONS_DIR / "execution_id" / "main.py"
51
51
target = "error"
52
52
app = create_app (target , source )
@@ -64,7 +64,7 @@ def test_uncaught_exception_in_user_function_sets_execution_id(capsys, monkeypat
64
64
65
65
66
66
def test_print_from_user_function_sets_execution_id (capsys , monkeypatch ):
67
- monkeypatch .setenv ("LOG_EXECUTION_ID" , "True " )
67
+ monkeypatch .setenv ("LOG_EXECUTION_ID" , "true " )
68
68
source = TEST_FUNCTIONS_DIR / "execution_id" / "main.py"
69
69
target = "print_message"
70
70
app = create_app (target , source )
@@ -83,7 +83,7 @@ def test_print_from_user_function_sets_execution_id(capsys, monkeypatch):
83
83
84
84
85
85
def test_log_from_user_function_sets_execution_id (capsys , monkeypatch ):
86
- monkeypatch .setenv ("LOG_EXECUTION_ID" , "True " )
86
+ monkeypatch .setenv ("LOG_EXECUTION_ID" , "true " )
87
87
source = TEST_FUNCTIONS_DIR / "execution_id" / "main.py"
88
88
target = "log_message"
89
89
app = create_app (target , source )
@@ -136,6 +136,44 @@ def test_does_not_set_execution_id_when_not_enabled(capsys):
136
136
assert "some-message" in record .out
137
137
138
138
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
+
139
177
def test_generate_execution_id ():
140
178
expected_matching_regex = "^[0-9a-zA-Z]{12}$"
141
179
actual_execution_id = execution_id ._generate_execution_id ()
@@ -283,7 +321,7 @@ def test_log_handler_omits_empty_execution_context(monkeypatch, capsys):
283
321
284
322
@pytest .mark .asyncio
285
323
async def test_maintains_execution_id_for_concurrent_requests (monkeypatch , capsys ):
286
- monkeypatch .setenv ("LOG_EXECUTION_ID" , "True " )
324
+ monkeypatch .setenv ("LOG_EXECUTION_ID" , "true " )
287
325
monkeypatch .setattr (
288
326
execution_id ,
289
327
"_generate_execution_id" ,
0 commit comments