File tree Expand file tree Collapse file tree 3 files changed +11
-8
lines changed
resource/opentelemetry-resource-detector-azure
src/opentelemetry/resource/detector/azure Expand file tree Collapse file tree 3 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
88## Unreleased
99
10+ - ` opentelemetry-resource-detector-azure ` Added 10s timeout to VM Resource Detector
11+ ([ #2119 ] ( https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2119 ) )
12+
1013## Version 1.22.0/0.43b0 (2023-12-14)
1114
1215### Added
Original file line number Diff line number Diff line change @@ -68,8 +68,8 @@ def get_azure_vm_metadata(self): # pylint: disable=no-self-use
6868 request = Request (_AZURE_VM_METADATA_ENDPOINT )
6969 request .add_header ("Metadata" , "True" )
7070 try :
71- with urlopen (request ). read ( ) as response :
72- return loads (response )
71+ with urlopen (request , timeout = 10 ) as response :
72+ return loads (response . read () )
7373 except URLError :
7474 # Not on Azure VM
7575 return None
Original file line number Diff line number Diff line change 363363class TestAzureVMResourceDetector (unittest .TestCase ):
364364 @patch ("opentelemetry.resource.detector.azure.vm.urlopen" )
365365 def test_linux (self , mock_urlopen ):
366- mock_open = Mock ()
367- mock_urlopen .return_value = mock_open
368- mock_open .read .return_value = LINUX_JSON
366+ mock_response = Mock ()
367+ mock_urlopen .return_value = mock_response
368+ mock_response .read .return_value = LINUX_JSON
369369 attributes = AzureVMResourceDetector ().detect ().attributes
370370 for attribute_key , attribute_value in LINUX_ATTRIBUTES .items ():
371371 self .assertEqual (attributes [attribute_key ], attribute_value )
372372
373373 @patch ("opentelemetry.resource.detector.azure.vm.urlopen" )
374374 def test_windows (self , mock_urlopen ):
375- mock_open = Mock ()
376- mock_urlopen .return_value = mock_open
377- mock_open .read .return_value = WINDOWS_JSON
375+ mock_response = Mock ()
376+ mock_urlopen .return_value = mock_response
377+ mock_response .read .return_value = WINDOWS_JSON
378378 attributes = AzureVMResourceDetector ().detect ().attributes
379379 for attribute_key , attribute_value in LINUX_ATTRIBUTES .items ():
380380 self .assertEqual (attributes [attribute_key ], attribute_value )
You can’t perform that action at this time.
0 commit comments