Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e004986

Browse files
authoredJan 10, 2024
Merge branch 'main' into feature/asyncio-instrumentation
2 parents 1d536a5 + 588d5d7 commit e004986

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed
 

‎CHANGELOG.md

+3
Original file line numberDiff line numberDiff 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

‎resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/vm.py

+2-2
Original file line numberDiff line numberDiff 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

‎resource/opentelemetry-resource-detector-azure/tests/test_vm.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -363,18 +363,18 @@
363363
class 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)

0 commit comments

Comments
 (0)
Please sign in to comment.