Skip to content

Commit d13be18

Browse files
committed
rename
1 parent 1c08f24 commit d13be18

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

azure_functions_worker/dispatcher.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def __init__(self, loop: BaseEventLoop, host: str, port: int,
102102
self._function_metadata_exception = None
103103

104104
# Used for checking if open telemetry is enabled
105-
self._otel_libs_available = False
105+
self._azure_monitor_available = False
106106
self._context_api = None
107107
self._trace_context_propagator = None
108108

@@ -291,7 +291,7 @@ async def _dispatch_grpc_request(self, request):
291291
resp = await request_handler(request)
292292
self._grpc_resp_queue.put_nowait(resp)
293293

294-
def initialize_opentelemetry(self):
294+
def initialize_azure_monitor(self):
295295
"""Initializes OpenTelemetry and Azure monitor distro
296296
"""
297297
self.update_opentelemetry_status()
@@ -317,19 +317,19 @@ def initialize_opentelemetry(self):
317317
default_value=PYTHON_AZURE_MONITOR_LOGGER_NAME_DEFAULT
318318
),
319319
)
320-
self._otel_libs_available = True
320+
self._azure_monitor_available = True
321321

322322
logger.info("Successfully configured Azure monitor distro.")
323323
except ImportError:
324324
logger.exception(
325325
"Cannot import Azure Monitor distro."
326326
)
327-
self._otel_libs_available = False
327+
self._azure_monitor_available = False
328328
except Exception:
329329
logger.exception(
330330
"Error initializing Azure monitor distro."
331331
)
332-
self._otel_libs_available = False
332+
self._azure_monitor_available = False
333333

334334
def update_opentelemetry_status(self):
335335
"""Check for OpenTelemetry library availability and
@@ -342,12 +342,11 @@ def update_opentelemetry_status(self):
342342

343343
self._context_api = context_api
344344
self._trace_context_propagator = TraceContextTextMapPropagator()
345-
self._otel_libs_available = True
346345

347346
logger.info("Successfully loaded OpenTelemetry modules. "
348347
"OpenTelemetry is now enabled.")
349348
except ImportError:
350-
self._otel_libs_available = False
349+
self._azure_monitor_available = False
351350

352351
async def _handle__worker_init_request(self, request):
353352
logger.info('Received WorkerInitRequest, '
@@ -379,9 +378,9 @@ async def _handle__worker_init_request(self, request):
379378
}
380379
if get_app_setting(setting=PYTHON_ENABLE_OPENTELEMETRY,
381380
default_value=PYTHON_ENABLE_OPENTELEMETRY_DEFAULT):
382-
self.initialize_opentelemetry()
381+
self.initialize_azure_monitor()
383382

384-
if self._otel_libs_available:
383+
if self._azure_monitor_available:
385384
capabilities[constants.WORKER_OPEN_TELEMETRY_ENABLED] = _TRUE
386385

387386
if DependencyManager.should_load_cx_dependencies():
@@ -653,7 +652,7 @@ async def _handle__invocation_request(self, request):
653652
args[name] = bindings.Out()
654653

655654
if fi.is_async:
656-
if self._otel_libs_available:
655+
if self._azure_monitor_available:
657656
self.configure_opentelemetry(fi_context)
658657

659658
call_result = \
@@ -773,9 +772,9 @@ async def _handle__function_environment_reload_request(self, request):
773772
if get_app_setting(
774773
setting=PYTHON_ENABLE_OPENTELEMETRY,
775774
default_value=PYTHON_ENABLE_OPENTELEMETRY_DEFAULT):
776-
self.update_opentelemetry_status()
775+
self.initialize_azure_monitor()
777776

778-
if self._otel_libs_available:
777+
if self._azure_monitor_available:
779778
capabilities[constants.WORKER_OPEN_TELEMETRY_ENABLED] = (
780779
_TRUE)
781780

@@ -986,7 +985,7 @@ def _run_sync_func(self, invocation_id, context, func, params):
986985
# invocation_id from ThreadPoolExecutor's threads.
987986
context.thread_local_storage.invocation_id = invocation_id
988987
try:
989-
if self._otel_libs_available:
988+
if self._azure_monitor_available:
990989
self.configure_opentelemetry(context)
991990
return ExtensionManager.get_sync_invocation_wrapper(context,
992991
func)(params)

tests/unittests/test_opentelemetry.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,38 @@ def test_update_opentelemetry_status_import_error(self):
2323
with patch('builtins.__import__', side_effect=ImportError):
2424
self.dispatcher.update_opentelemetry_status()
2525
# Verify that otel_libs_available is set to False due to ImportError
26-
self.assertFalse(self.dispatcher._otel_libs_available)
26+
self.assertFalse(self.dispatcher._azure_monitor_available)
2727

2828
@patch('builtins.__import__')
2929
def test_update_opentelemetry_status_success(
3030
self, mock_imports):
3131
mock_imports.return_value = MagicMock()
3232
self.dispatcher.update_opentelemetry_status()
33-
self.assertTrue(self.dispatcher._otel_libs_available)
33+
self.assertIsNotNone(self.dispatcher._context_api)
34+
self.assertIsNotNone(self.dispatcher._trace_context_propagator)
3435

3536
@patch('builtins.__import__')
3637
@patch("azure_functions_worker.dispatcher.Dispatcher.update_opentelemetry_status")
37-
def test_initialize_opentelemetry_success(
38+
def test_initialize_azure_monitor_success(
3839
self,
3940
mock_update_ot,
4041
mock_imports,
4142
):
4243
mock_imports.return_value = MagicMock()
43-
self.dispatcher.initialize_opentelemetry()
44+
self.dispatcher.initialize_azure_monitor()
4445
mock_update_ot.assert_called_once()
45-
self.assertTrue(self.dispatcher._otel_libs_available)
46+
self.assertTrue(self.dispatcher._azure_monitor_available)
4647

4748
@patch("azure_functions_worker.dispatcher.Dispatcher.update_opentelemetry_status")
48-
def test_initialize_opentelemetry_import_error(
49+
def test_initialize_azure_monitor_import_error(
4950
self,
5051
mock_update_ot,
5152
):
5253
with patch('builtins.__import__', side_effect=ImportError):
53-
self.dispatcher.initialize_opentelemetry()
54+
self.dispatcher.initialize_azure_monitor()
5455
mock_update_ot.assert_called_once()
5556
# Verify that otel_libs_available is set to False due to ImportError
56-
self.assertFalse(self.dispatcher._otel_libs_available)
57+
self.assertFalse(self.dispatcher._azure_monitor_available)
5758

5859
@patch("azure_functions_worker.dispatcher.get_app_setting")
5960
@patch('builtins.__import__')
@@ -83,12 +84,12 @@ def test_init_request_otel_capability_enabled_app_setting(
8384
self.assertIn("WorkerOpenTelemetryEnabled", capabilities)
8485
self.assertEqual(capabilities["WorkerOpenTelemetryEnabled"], "true")
8586

86-
@patch("azure_functions_worker.dispatcher.Dispatcher.initialize_opentelemetry")
87+
@patch("azure_functions_worker.dispatcher.Dispatcher.initialize_azure_monitor")
8788
@patch("azure_functions_worker.dispatcher.get_app_setting")
8889
def test_init_request_otel_capability_disabled_app_setting(
8990
self,
9091
mock_app_setting,
91-
mock_initialize_ot,
92+
mock_initialize_azmon,
9293
):
9394
mock_app_setting.return_value = False
9495

@@ -105,8 +106,8 @@ def test_init_request_otel_capability_disabled_app_setting(
105106
self.assertEqual(init_response.worker_init_response.result.status,
106107
protos.StatusResult.Success)
107108

108-
# OpenTelemetry initialized not called
109-
mock_initialize_ot.assert_not_called()
109+
# Azure monitor initialized not called
110+
mock_initialize_azmon.assert_not_called()
110111

111112
# Verify that WorkerOpenTelemetryEnabled capability is not set
112113
capabilities = init_response.worker_init_response.capabilities

0 commit comments

Comments
 (0)