@@ -326,11 +326,12 @@ def test_load_instrumentors_dep_conflict(self, iter_mock, mock_logger): # pylin
326
326
]
327
327
)
328
328
329
+ @patch ("opentelemetry.instrumentation.auto_instrumentation._load._logger" )
329
330
@patch (
330
331
"opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
331
332
)
332
333
def test_load_instrumentors_import_error_does_not_stop_everything (
333
- self , iter_mock
334
+ self , iter_mock , mock_logger
334
335
):
335
336
ep_mock1 = Mock (name = "instr1" )
336
337
ep_mock2 = Mock (name = "instr2" )
@@ -354,6 +355,12 @@ def test_load_instrumentors_import_error_does_not_stop_everything(
354
355
]
355
356
)
356
357
self .assertEqual (distro_mock .load_instrumentor .call_count , 2 )
358
+ mock_logger .exception .assert_any_call (
359
+ "Importing of %s failed, skipping it" ,
360
+ ep_mock1 .name ,
361
+ )
362
+
363
+ mock_logger .debug .assert_any_call ("Instrumented %s" , ep_mock2 .name )
357
364
358
365
@patch (
359
366
"opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
@@ -382,6 +389,46 @@ def test_load_instrumentors_raises_exception(self, iter_mock):
382
389
)
383
390
self .assertEqual (distro_mock .load_instrumentor .call_count , 1 )
384
391
392
+ @patch ("opentelemetry.instrumentation.auto_instrumentation._load._logger" )
393
+ @patch (
394
+ "opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
395
+ )
396
+ def test_load_instrumentors_module_not_found_error (
397
+ self , iter_mock , mock_logger
398
+ ):
399
+ ep_mock1 = Mock ()
400
+ ep_mock1 .name = "instr1"
401
+
402
+ ep_mock2 = Mock ()
403
+ ep_mock2 .name = "instr2"
404
+
405
+ distro_mock = Mock ()
406
+
407
+ distro_mock .load_instrumentor .side_effect = [
408
+ ModuleNotFoundError ("No module named 'fake_module'" ),
409
+ None ,
410
+ ]
411
+
412
+ iter_mock .side_effect = [(), (ep_mock1 , ep_mock2 ), ()]
413
+
414
+ _load ._load_instrumentors (distro_mock )
415
+
416
+ distro_mock .load_instrumentor .assert_has_calls (
417
+ [
418
+ call (ep_mock1 , raise_exception_on_conflict = True ),
419
+ call (ep_mock2 , raise_exception_on_conflict = True ),
420
+ ]
421
+ )
422
+ self .assertEqual (distro_mock .load_instrumentor .call_count , 2 )
423
+
424
+ mock_logger .debug .assert_any_call (
425
+ "Skipping instrumentation %s: %s" ,
426
+ "instr1" ,
427
+ "No module named 'fake_module'" ,
428
+ )
429
+
430
+ mock_logger .debug .assert_any_call ("Instrumented %s" , ep_mock2 .name )
431
+
385
432
def test_load_instrumentors_no_entry_point_mocks (self ):
386
433
distro_mock = Mock ()
387
434
_load ._load_instrumentors (distro_mock )
0 commit comments