File tree 3 files changed +11
-8
lines changed
resource/opentelemetry-resource-detector-azure
src/opentelemetry/resource/detector/azure
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
7
7
8
8
## Unreleased
9
9
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
+
10
13
## Version 1.22.0/0.43b0 (2023-12-14)
11
14
12
15
### 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
68
68
request = Request (_AZURE_VM_METADATA_ENDPOINT )
69
69
request .add_header ("Metadata" , "True" )
70
70
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 () )
73
73
except URLError :
74
74
# Not on Azure VM
75
75
return None
Original file line number Diff line number Diff line change 363
363
class TestAzureVMResourceDetector (unittest .TestCase ):
364
364
@patch ("opentelemetry.resource.detector.azure.vm.urlopen" )
365
365
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
369
369
attributes = AzureVMResourceDetector ().detect ().attributes
370
370
for attribute_key , attribute_value in LINUX_ATTRIBUTES .items ():
371
371
self .assertEqual (attributes [attribute_key ], attribute_value )
372
372
373
373
@patch ("opentelemetry.resource.detector.azure.vm.urlopen" )
374
374
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
378
378
attributes = AzureVMResourceDetector ().detect ().attributes
379
379
for attribute_key , attribute_value in LINUX_ATTRIBUTES .items ():
380
380
self .assertEqual (attributes [attribute_key ], attribute_value )
You can’t perform that action at this time.
0 commit comments