Skip to content

Commit 98c82b9

Browse files
gavin-aguiargavin-aguiarhallvictoria
authored
Added console logging to show errors during function load & indexing (#1396)
* Added error logger * Removed log * fixed unit test --------- Co-authored-by: gavin-aguiar <root@GavinPC> Co-authored-by: hallvictoria <[email protected]>
1 parent 0b21dc0 commit 98c82b9

File tree

5 files changed

+42
-27
lines changed

5 files changed

+42
-27
lines changed

azure_functions_worker/dispatcher.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
PYTHON_ENABLE_DEBUG_LOGGING,
3131
PYTHON_SCRIPT_FILE_NAME,
3232
PYTHON_SCRIPT_FILE_NAME_DEFAULT,
33-
PYTHON_LANGUAGE_RUNTIME, CUSTOMER_PACKAGES_PATH)
33+
PYTHON_LANGUAGE_RUNTIME)
3434
from .extension import ExtensionManager
3535
from .logging import disable_console_logging, enable_console_logging
3636
from .logging import (logger, error_logger, is_system_log_category,
@@ -299,13 +299,8 @@ async def _handle__worker_init_request(self, request):
299299
DependencyManager.prioritize_customer_dependencies()
300300

301301
if DependencyManager.is_in_linux_consumption():
302-
logger.info(
303-
"Importing azure functions in WorkerInitRequest")
304302
import azure.functions # NoQA
305303

306-
if CUSTOMER_PACKAGES_PATH not in sys.path:
307-
logger.warning("Customer packages not in sys path.")
308-
309304
# loading bindings registry and saving results to a static
310305
# dictionary which will be later used in the invocation request
311306
bindings.load_binding_registry()
@@ -343,8 +338,6 @@ async def _handle__functions_metadata_request(self, request):
343338

344339
if not os.path.exists(function_path):
345340
# Fallback to legacy model
346-
logger.info("%s does not exist. "
347-
"Switching to host indexing.", script_file_name)
348341
return protos.StreamingMessage(
349342
request_id=request.request_id,
350343
function_metadata_response=protos.FunctionMetadataResponse(
@@ -379,7 +372,7 @@ async def _handle__function_load_request(self, request):
379372
'Received WorkerLoadRequest, request ID %s, function_id: %s,'
380373
'function_name: %s,', self.request_id, function_id, function_name)
381374

382-
programming_model = "V1"
375+
programming_model = "V2"
383376
try:
384377
if not self._functions.get_function(function_id):
385378
script_file_name = get_app_setting(
@@ -396,10 +389,11 @@ async def _handle__function_load_request(self, request):
396389
# indexing is enabled and load request is called without
397390
# calling the metadata request. In this case we index the
398391
# function and update the workers registry
399-
programming_model = "V2"
400392
_ = self.index_functions(function_path)
401393
else:
402394
# legacy function
395+
programming_model = "V1"
396+
403397
func = loader.load_function(
404398
func_request.metadata.name,
405399
func_request.metadata.directory,

azure_functions_worker/loader.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,11 @@ def process_indexed_function(functions_registry: functions.Registry,
152152

153153
@attach_message_to_exception(
154154
expt_type=ImportError,
155-
message=f'Please check the requirements.txt file for the missing module. '
156-
f'For more info, please refer the troubleshooting'
157-
f' guide: {MODULE_NOT_FOUND_TS_URL} ',
155+
message='Cannot find module. Please check the requirements.txt '
156+
'file for the missing module. For more info, '
157+
'please refer the troubleshooting '
158+
f'guide: {MODULE_NOT_FOUND_TS_URL}. '
159+
f'Current sys.path: {sys.path}',
158160
debug_logs='Error in load_function. '
159161
f'Sys Path: {sys.path}, Sys Module: {sys.modules},'
160162
'python-packages Path exists: '
@@ -206,7 +208,11 @@ def load_function(name: str, directory: str, script_file: str,
206208

207209
@attach_message_to_exception(
208210
expt_type=ImportError,
209-
message=f'Troubleshooting Guide: {MODULE_NOT_FOUND_TS_URL}',
211+
message='Cannot find module. Please check the requirements.txt '
212+
'file for the missing module. For more info, '
213+
'please refer the troubleshooting '
214+
f'guide: {MODULE_NOT_FOUND_TS_URL}. '
215+
f'Current sys.path: {sys.path}',
210216
debug_logs='Error in index_function_app. '
211217
f'Sys Path: {sys.path}, Sys Module: {sys.modules},'
212218
'python-packages Path exists: '

azure_functions_worker/utils/wrappers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from .common import is_envvar_true, is_envvar_false
77
from .tracing import extend_exception_message
8-
from ..logging import logger
8+
from ..logging import error_logger, logger
99

1010

1111
def enable_feature_by(flag: str,
@@ -45,6 +45,7 @@ def call(*args, **kwargs):
4545
except expt_type as e:
4646
if debug_logs is not None:
4747
logger.error(debug_logs)
48+
error_logger.exception("Error: %s, %s", e, message)
4849
raise extend_exception_message(e, message)
4950
return call
5051
return decorate

tests/unittests/test_http_functions.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,19 @@ def check_log_user_event_loop_error(self, host_out: typing.List[str]):
315315

316316
def check_log_import_module_troubleshooting_url(self,
317317
host_out: typing.List[str]):
318-
self.assertIn("Exception: ModuleNotFoundError: "
319-
"No module named 'does_not_exist'. "
320-
"Please check the requirements.txt file for the "
321-
"missing module. For more info, please refer the "
322-
"troubleshooting guide: "
323-
"https://aka.ms/functions-modulenotfound", host_out)
318+
passed = False
319+
exception_message = "Exception: ModuleNotFoundError: "\
320+
"No module named 'does_not_exist'. "\
321+
"Cannot find module. "\
322+
"Please check the requirements.txt file for the "\
323+
"missing module. For more info, please refer the "\
324+
"troubleshooting guide: "\
325+
"https://aka.ms/functions-modulenotfound. "\
326+
"Current sys.path: "
327+
for log in host_out:
328+
if exception_message in log:
329+
passed = True
330+
self.assertTrue(passed)
324331

325332
def test_print_logging_no_flush(self):
326333
r = self.webhost.request('GET', 'print_logging?message=Secret42')

tests/unittests/test_loader.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,19 @@ def test_loader_outside_main_package_should_be_loaded_from_package(self):
188188
self.assertEqual(r.text, 'OK')
189189

190190
def check_log_loader_module_not_found(self, host_out):
191-
self.assertIn("Exception: ModuleNotFoundError: "
192-
"No module named 'notfound'. "
193-
"Please check the requirements.txt file for the "
194-
"missing module. For more info, please refer the "
195-
"troubleshooting guide: "
196-
"https://aka.ms/functions-modulenotfound", host_out)
191+
passed = False
192+
exception_message = "Exception: ModuleNotFoundError: "\
193+
"No module named 'notfound'. "\
194+
"Cannot find module. "\
195+
"Please check the requirements.txt file for the "\
196+
"missing module. For more info, please refer the "\
197+
"troubleshooting guide: "\
198+
"https://aka.ms/functions-modulenotfound. "\
199+
"Current sys.path: "
200+
for log in host_out:
201+
if exception_message in log:
202+
passed = True
203+
self.assertTrue(passed)
197204

198205

199206
class TestPluginLoader(testutils.AsyncTestCase):

0 commit comments

Comments
 (0)