diff --git a/azure_functions_worker/constants.py b/azure_functions_worker/constants.py index fcb39ff74..69c59ad0b 100644 --- a/azure_functions_worker/constants.py +++ b/azure_functions_worker/constants.py @@ -80,3 +80,6 @@ # Base extension supported Python minor version BASE_EXT_SUPPORTED_PY_MINOR_VERSION = 8 + +PYTHON_ENABLE_OPENTELEMETRY = "PYTHON_ENABLE_OPENTELEMETRY" +PYTHON_ENABLE_OPENTELEMETRY_DEFAULT = True diff --git a/azure_functions_worker/dispatcher.py b/azure_functions_worker/dispatcher.py index 3fb5f1818..902e9d86e 100644 --- a/azure_functions_worker/dispatcher.py +++ b/azure_functions_worker/dispatcher.py @@ -30,7 +30,9 @@ PYTHON_SCRIPT_FILE_NAME, PYTHON_SCRIPT_FILE_NAME_DEFAULT, PYTHON_LANGUAGE_RUNTIME, PYTHON_ENABLE_INIT_INDEXING, - METADATA_PROPERTIES_WORKER_INDEXED) + METADATA_PROPERTIES_WORKER_INDEXED, + PYTHON_ENABLE_OPENTELEMETRY, + PYTHON_ENABLE_OPENTELEMETRY_DEFAULT) from .extension import ExtensionManager from .http_v2 import http_coordinator, initialize_http_server, HttpV2Registry, \ sync_http_request, HttpServerInitError @@ -318,10 +320,12 @@ async def _handle__worker_init_request(self, request): constants.SHARED_MEMORY_DATA_TRANSFER: _TRUE, } - self.update_opentelemetry_status() + if get_app_setting(setting=PYTHON_ENABLE_OPENTELEMETRY, + default_value=PYTHON_ENABLE_OPENTELEMETRY_DEFAULT): + self.update_opentelemetry_status() - if self._otel_libs_available: - capabilities[constants.WORKER_OPEN_TELEMETRY_ENABLED] = _TRUE + if self._otel_libs_available: + capabilities[constants.WORKER_OPEN_TELEMETRY_ENABLED] = _TRUE if DependencyManager.should_load_cx_dependencies(): DependencyManager.prioritize_customer_dependencies() @@ -383,8 +387,10 @@ def load_function_metadata(self, function_app_directory, caller_info): function_path = os.path.join(function_app_directory, script_file_name) + # For V1, the function path will not exist and + # return None. self._function_metadata_result = ( - self.index_functions(function_path)) \ + self.index_functions(function_path, function_app_directory)) \ if os.path.exists(function_path) else None async def _handle__functions_metadata_request(self, request): @@ -439,8 +445,9 @@ async def _handle__function_load_request(self, request): logger.info( 'Received WorkerLoadRequest, request ID %s, function_id: %s,' - 'function_name: %s', - self.request_id, function_id, function_name) + 'function_name: %s, function_app_directory : %s', + self.request_id, function_id, function_name, + function_app_directory) programming_model = "V2" try: @@ -705,9 +712,14 @@ async def _handle__function_environment_reload_request(self, request): bindings.load_binding_registry() capabilities = {} - self.update_opentelemetry_status() - if self._otel_libs_available: - capabilities[constants.WORKER_OPEN_TELEMETRY_ENABLED] = _TRUE + if get_app_setting( + setting=PYTHON_ENABLE_OPENTELEMETRY, + default_value=PYTHON_ENABLE_OPENTELEMETRY_DEFAULT): + self.update_opentelemetry_status() + + if self._otel_libs_available: + capabilities[constants.WORKER_OPEN_TELEMETRY_ENABLED] = ( + _TRUE) if is_envvar_true(PYTHON_ENABLE_INIT_INDEXING): try: @@ -749,7 +761,7 @@ async def _handle__function_environment_reload_request(self, request): request_id=self.request_id, function_environment_reload_response=failure_response) - def index_functions(self, function_path: str): + def index_functions(self, function_path: str, function_dir: str): indexed_functions = loader.index_function_app(function_path) logger.info( "Indexed function app and found %s functions", @@ -760,7 +772,8 @@ def index_functions(self, function_path: str): fx_metadata_results, fx_bindings_logs = ( loader.process_indexed_function( self._functions, - indexed_functions)) + indexed_functions, + function_dir)) indexed_function_logs: List[str] = [] indexed_function_bindings_logs = [] diff --git a/azure_functions_worker/loader.py b/azure_functions_worker/loader.py index 9bfa8ccb9..76c2472e1 100644 --- a/azure_functions_worker/loader.py +++ b/azure_functions_worker/loader.py @@ -121,7 +121,7 @@ def build_variable_interval_retry(retry, max_retry_count, retry_strategy): def process_indexed_function(functions_registry: functions.Registry, - indexed_functions): + indexed_functions, function_dir): """ fx_metadata_results is a list of the RpcFunctionMetadata for all the functions in the particular app. @@ -150,7 +150,7 @@ def process_indexed_function(functions_registry: functions.Registry, name=function_info.name, function_id=function_info.function_id, managed_dependency_enabled=False, # only enabled for PowerShell - directory=function_info.directory, + directory=function_dir, script_file=indexed_function.function_script_file, entry_point=function_info.name, is_proxy=False, # not supported in V4 diff --git a/tests/endtoend/blueprint_functions/functions_in_blueprint_only/blueprint.py b/tests/endtoend/blueprint_functions/functions_in_blueprint_only/blueprint.py index 785049396..d232dcead 100644 --- a/tests/endtoend/blueprint_functions/functions_in_blueprint_only/blueprint.py +++ b/tests/endtoend/blueprint_functions/functions_in_blueprint_only/blueprint.py @@ -1,4 +1,6 @@ import logging +import time +from datetime import datetime import azure.functions as func @@ -29,3 +31,11 @@ def default_template(req: func.HttpRequest) -> func.HttpResponse: " personalized response.", status_code=200 ) + + +@bp.route(route="http_func") +def http_func(req: func.HttpRequest) -> func.HttpResponse: + time.sleep(1) + + current_time = datetime.now().strftime("%H:%M:%S") + return func.HttpResponse(f"{current_time}") diff --git a/tests/endtoend/test_worker_process_count_functions.py b/tests/endtoend/test_worker_process_count_functions.py index 519d8982e..c89df2e63 100644 --- a/tests/endtoend/test_worker_process_count_functions.py +++ b/tests/endtoend/test_worker_process_count_functions.py @@ -68,3 +68,11 @@ class TestWorkerProcessCountStein(TestWorkerProcessCount): def get_script_dir(cls): return testutils.E2E_TESTS_FOLDER / 'http_functions' /\ 'http_functions_stein' + + +class TestWorkerProcessCountWithBlueprintStein(TestWorkerProcessCount): + + @classmethod + def get_script_dir(cls): + return testutils.E2E_TESTS_FOLDER / 'blueprint_functions' /\ + 'functions_in_blueprint_only' diff --git a/tests/unittests/test_dispatcher.py b/tests/unittests/test_dispatcher.py index dc62acb8e..84d72e95b 100644 --- a/tests/unittests/test_dispatcher.py +++ b/tests/unittests/test_dispatcher.py @@ -21,7 +21,6 @@ from tests.utils import testutils from tests.utils.testutils import UNIT_TESTS_ROOT - SysVersionInfo = col.namedtuple("VersionInfo", ["major", "minor", "micro", "releaselevel", "serial"]) DISPATCHER_FUNCTIONS_DIR = testutils.UNIT_TESTS_FOLDER / 'dispatcher_functions'