Skip to content

Commit a4b3343

Browse files
committed
hfsadjkfhskdjhfsad
1 parent e9208a4 commit a4b3343

File tree

1 file changed

+25
-29
lines changed
  • opentelemetry-instrumentation/tests/auto_instrumentation

1 file changed

+25
-29
lines changed

opentelemetry-instrumentation/tests/auto_instrumentation/test_load.py

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
OTEL_PYTHON_DISTRO,
2424
)
2525
from opentelemetry.instrumentation.version import __version__
26+
from opentelemetry.instrumentation.dependencies import (
27+
DependencyConflictError,
28+
DependencyConflict,
29+
)
2630

2731

2832
class TestLoad(TestCase):
@@ -199,17 +203,18 @@ def test_load_distro_error(self, iter_mock, isinstance_mock):
199203
# Confirm method raises exception if it fails to load a distro.
200204
self.assertRaises(Exception, _load._load_distro)
201205

206+
@staticmethod
207+
def _instrumentation_failed_to_load_call(entry_point, dependency_conflict):
208+
return call("Skipping instrumentation %s: %s", entry_point, dependency_conflict)
209+
202210
@patch.dict(
203211
"os.environ",
204212
{OTEL_PYTHON_DISABLED_INSTRUMENTATIONS: " instr1 , instr3 "},
205213
)
206-
@patch(
207-
"opentelemetry.instrumentation.auto_instrumentation._load.get_dist_dependency_conflicts"
208-
)
209214
@patch(
210215
"opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
211216
)
212-
def test_load_instrumentors(self, iter_mock, dep_mock):
217+
def test_load_instrumentors(self, iter_mock):
213218
# Mock opentelemetry_pre_instrument entry points
214219
# pylint: disable=too-many-locals
215220
pre_ep_mock1 = Mock()
@@ -254,8 +259,6 @@ def test_load_instrumentors(self, iter_mock, dep_mock):
254259
(ep_mock1, ep_mock2, ep_mock3, ep_mock4),
255260
(post_ep_mock1, post_ep_mock2),
256261
]
257-
# No dependency conflict
258-
dep_mock.return_value = None
259262
_load._load_instrumentors(distro_mock)
260263
# All opentelemetry_pre_instrument entry points should be loaded
261264
pre_mock1.assert_called_once()
@@ -264,8 +267,8 @@ def test_load_instrumentors(self, iter_mock, dep_mock):
264267
# Only non-disabled instrumentations should be loaded
265268
distro_mock.load_instrumentor.assert_has_calls(
266269
[
267-
call(ep_mock2, skip_dep_check=True),
268-
call(ep_mock4, skip_dep_check=True),
270+
call(ep_mock2, raise_exception_on_conflict=True),
271+
call(ep_mock4, raise_exception_on_conflict=True),
269272
]
270273
)
271274
self.assertEqual(distro_mock.load_instrumentor.call_count, 2)
@@ -277,13 +280,11 @@ def test_load_instrumentors(self, iter_mock, dep_mock):
277280
"os.environ",
278281
{OTEL_PYTHON_DISABLED_INSTRUMENTATIONS: " instr1 , instr3 "},
279282
)
280-
@patch(
281-
"opentelemetry.instrumentation.auto_instrumentation._load.get_dist_dependency_conflicts"
282-
)
283+
@patch('opentelemetry.instrumentation.auto_instrumentation._load._logger')
283284
@patch(
284285
"opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
285286
)
286-
def test_load_instrumentors_dep_conflict(self, iter_mock, dep_mock): # pylint: disable=no-self-use
287+
def test_load_instrumentors_dep_conflict(self, iter_mock, mock_logger): # pylint: disable=no-self-use
287288
ep_mock1 = Mock()
288289
ep_mock1.name = "instr1"
289290

@@ -296,27 +297,27 @@ def test_load_instrumentors_dep_conflict(self, iter_mock, dep_mock): # pylint:
296297
ep_mock4 = Mock()
297298
ep_mock4.name = "instr4"
298299

300+
dependency_conflict = DependencyConflict("1.2.3", None)
301+
299302
distro_mock = Mock()
303+
distro_mock.load_instrumentor.side_effect = [None, DependencyConflictError(dependency_conflict)]
300304

301305
iter_mock.return_value = (ep_mock1, ep_mock2, ep_mock3, ep_mock4)
302-
# If a dependency conflict is raised, that instrumentation should not be loaded, but others still should.
303-
dep_mock.side_effect = [None, "DependencyConflict"]
304306
_load._load_instrumentors(distro_mock)
305307
distro_mock.load_instrumentor.assert_has_calls(
306308
[
307-
call(ep_mock2, skip_dep_check=True),
309+
call(ep_mock2, raise_exception_on_conflict=True),
310+
call(ep_mock4, raise_exception_on_conflict=True),
308311
]
309312
)
310-
distro_mock.load_instrumentor.assert_called_once()
313+
assert distro_mock.load_instrumentor.call_count == 2
314+
mock_logger.debug.assert_has_calls([self._instrumentation_failed_to_load_call(ep_mock4.name, dependency_conflict)])
311315

312-
@patch(
313-
"opentelemetry.instrumentation.auto_instrumentation._load.get_dist_dependency_conflicts"
314-
)
315316
@patch(
316317
"opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
317318
)
318319
def test_load_instrumentors_import_error_does_not_stop_everything(
319-
self, iter_mock, dep_mock
320+
self, iter_mock
320321
):
321322
ep_mock1 = Mock(name="instr1")
322323
ep_mock2 = Mock(name="instr2")
@@ -330,25 +331,21 @@ def test_load_instrumentors_import_error_does_not_stop_everything(
330331
(ep_mock1, ep_mock2),
331332
(),
332333
]
333-
dep_mock.return_value = None
334334

335335
_load._load_instrumentors(distro_mock)
336336

337337
distro_mock.load_instrumentor.assert_has_calls(
338338
[
339-
call(ep_mock1, skip_dep_check=True),
340-
call(ep_mock2, skip_dep_check=True),
339+
call(ep_mock1, raise_exception_on_conflict=True),
340+
call(ep_mock2, raise_exception_on_conflict=True),
341341
]
342342
)
343343
self.assertEqual(distro_mock.load_instrumentor.call_count, 2)
344344

345-
@patch(
346-
"opentelemetry.instrumentation.auto_instrumentation._load.get_dist_dependency_conflicts"
347-
)
348345
@patch(
349346
"opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
350347
)
351-
def test_load_instrumentors_raises_exception(self, iter_mock, dep_mock):
348+
def test_load_instrumentors_raises_exception(self, iter_mock):
352349
ep_mock1 = Mock(name="instr1")
353350
ep_mock2 = Mock(name="instr2")
354351

@@ -361,14 +358,13 @@ def test_load_instrumentors_raises_exception(self, iter_mock, dep_mock):
361358
(ep_mock1, ep_mock2),
362359
(),
363360
]
364-
dep_mock.return_value = None
365361

366362
with self.assertRaises(ValueError):
367363
_load._load_instrumentors(distro_mock)
368364

369365
distro_mock.load_instrumentor.assert_has_calls(
370366
[
371-
call(ep_mock1, skip_dep_check=True),
367+
call(ep_mock1, raise_exception_on_conflict=True),
372368
]
373369
)
374370
self.assertEqual(distro_mock.load_instrumentor.call_count, 1)

0 commit comments

Comments
 (0)