@@ -33,6 +33,7 @@ class TestLoad(TestCase):
3333 "opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
3434 )
3535 def test_load_configurators (self , iter_mock ):
36+ # Add multiple entry points but only specify the 2nd in the environment variable.
3637 ep_mock1 = Mock ()
3738 ep_mock1 .name = "custom_configurator1"
3839 configurator_mock1 = Mock ()
@@ -65,6 +66,7 @@ def test_load_configurators_no_ep(
6566 iter_mock ,
6667 ):
6768 iter_mock .return_value = ()
69+ # Confirm method does not crash if not entry points exist.
6870 _load ._load_configurators ()
6971
7072 @patch .dict (
@@ -74,6 +76,7 @@ def test_load_configurators_no_ep(
7476 "opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
7577 )
7678 def test_load_configurators_error (self , iter_mock ):
79+ # Add multiple entry points but only specify the 2nd in the environment variable.
7780 ep_mock1 = Mock ()
7881 ep_mock1 .name = "custom_configurator1"
7982 configurator_mock1 = Mock ()
@@ -89,6 +92,7 @@ def test_load_configurators_error(self, iter_mock):
8992 ep_mock3 .load .return_value = configurator_mock3
9093
9194 iter_mock .return_value = (ep_mock1 , ep_mock2 , ep_mock3 )
95+ # Confirm failed configuration raises exception.
9296 self .assertRaises (Exception , _load ._load_configurators )
9397
9498 @patch .dict ("os.environ" , {OTEL_PYTHON_DISTRO : "custom_distro2" })
@@ -99,6 +103,7 @@ def test_load_configurators_error(self, iter_mock):
99103 "opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
100104 )
101105 def test_load_distros (self , iter_mock , isinstance_mock ):
106+ # Add multiple entry points but only specify the 2nd in the environment variable.
102107 ep_mock1 = Mock ()
103108 ep_mock1 .name = "custom_distro1"
104109 distro_mock1 = Mock ()
@@ -113,6 +118,7 @@ def test_load_distros(self, iter_mock, isinstance_mock):
113118 ep_mock3 .load .return_value = distro_mock3
114119
115120 iter_mock .return_value = (ep_mock1 , ep_mock2 , ep_mock3 )
121+ # Mock entry points to be instances of BaseDistro.
116122 isinstance_mock .return_value = True
117123 self .assertEqual (
118124 _load ._load_distros (),
@@ -132,6 +138,7 @@ def test_load_distros(self, iter_mock, isinstance_mock):
132138 def test_load_distros_not_distro (
133139 self , iter_mock , default_distro_mock , isinstance_mock
134140 ):
141+ # Add multiple entry points but only specify the 2nd in the environment variable.
135142 ep_mock1 = Mock ()
136143 ep_mock1 .name = "custom_distro1"
137144 distro_mock1 = Mock ()
@@ -146,6 +153,7 @@ def test_load_distros_not_distro(
146153 ep_mock3 .load .return_value = distro_mock3
147154
148155 iter_mock .return_value = (ep_mock1 , ep_mock2 , ep_mock3 )
156+ # Confirm default distro is used if specified entry point is not a BaseDistro
149157 isinstance_mock .return_value = False
150158 self .assertEqual (
151159 _load ._load_distros (),
@@ -161,6 +169,7 @@ def test_load_distros_not_distro(
161169 )
162170 def test_load_distros_no_ep (self , iter_mock , default_distro_mock ):
163171 iter_mock .return_value = ()
172+ # Confirm default distro is used if there are no entry points.
164173 self .assertEqual (
165174 _load ._load_distros (),
166175 default_distro_mock (),
@@ -190,6 +199,7 @@ def test_load_distros_error(self, iter_mock, isinstance_mock):
190199
191200 iter_mock .return_value = (ep_mock1 , ep_mock2 , ep_mock3 )
192201 isinstance_mock .return_value = True
202+ # Confirm method raises exception if it fails to load a distro.
193203 self .assertRaises (Exception , _load ._load_distros )
194204
195205 @patch .dict (
@@ -203,6 +213,7 @@ def test_load_distros_error(self, iter_mock, isinstance_mock):
203213 "opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
204214 )
205215 def test_load_instrumentors (self , iter_mock , dep_mock ):
216+ # Mock opentelemetry_pre_instrument entry points
206217 pre_ep_mock1 = Mock ()
207218 pre_ep_mock1 .name = "pre1"
208219 pre_mock1 = Mock ()
@@ -213,12 +224,7 @@ def test_load_instrumentors(self, iter_mock, dep_mock):
213224 pre_mock2 = Mock ()
214225 pre_ep_mock2 .load .return_value = pre_mock2
215226
216- ep_mock3 = Mock ()
217- ep_mock3 .name = "instr3"
218-
219- ep_mock4 = Mock ()
220- ep_mock4 .name = "instr4"
221-
227+ # Mock opentelemetry_instrumentor entry points
222228 ep_mock1 = Mock ()
223229 ep_mock1 .name = "instr1"
224230
@@ -231,6 +237,7 @@ def test_load_instrumentors(self, iter_mock, dep_mock):
231237 ep_mock4 = Mock ()
232238 ep_mock4 .name = "instr4"
233239
240+ # Mock opentelemetry_instrumentor entry points
234241 post_ep_mock1 = Mock ()
235242 post_ep_mock1 .name = "post1"
236243 post_mock1 = Mock ()
@@ -243,23 +250,28 @@ def test_load_instrumentors(self, iter_mock, dep_mock):
243250
244251 distro_mock = Mock ()
245252
253+ # Mock entry points in order
246254 iter_mock .side_effect = [
247255 (pre_ep_mock1 , pre_ep_mock2 ),
248256 (ep_mock1 , ep_mock2 , ep_mock3 , ep_mock4 ),
249257 (post_ep_mock1 , post_ep_mock2 ),
250258 ]
259+ # No dependency conflict
251260 dep_mock .return_value = None
252261 _load ._load_instrumentors (distro_mock )
262+ # All opentelemetry_pre_instrument entry points should be loaded
253263 pre_mock1 .assert_called_once ()
254264 pre_mock2 .assert_called_once ()
255265 self .assertEqual (iter_mock .call_count , 3 )
266+ # Only non-disabled instrumentations should be loaded
256267 distro_mock .load_instrumentor .assert_has_calls (
257268 [
258269 call (ep_mock2 , skip_dep_check = True ),
259270 call (ep_mock4 , skip_dep_check = True ),
260271 ]
261272 )
262273 self .assertEqual (distro_mock .load_instrumentor .call_count , 2 )
274+ # All opentelemetry_post_instrument entry points should be loaded
263275 post_mock1 .assert_called_once ()
264276 post_mock2 .assert_called_once ()
265277
@@ -289,6 +301,7 @@ def test_load_instrumentors_dep_conflict(self, iter_mock, dep_mock):
289301 distro_mock = Mock ()
290302
291303 iter_mock .return_value = (ep_mock1 , ep_mock2 , ep_mock3 , ep_mock4 )
304+ # If a dependency conflict is raised, that instrumentation should not be loaded, but others still should.
292305 dep_mock .side_effect = [None , "DependencyConflict" ]
293306 _load ._load_instrumentors (distro_mock )
294307 distro_mock .load_instrumentor .assert_has_calls (
0 commit comments