Skip to content

Commit 281f6b1

Browse files
committed
opentelemetry-sdk-extension-aws: make beanstalk detector less chatty
Don't print warnings if we are not running inside beanstalk so we can load the resource detector more generally and avoid warnings in stderr.
1 parent ae3a3f9 commit 281f6b1

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/beanstalk.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def detect(self) -> "Resource":
4141
else:
4242
conf_file_path = "/var/elasticbeanstalk/xray/environment.conf"
4343

44+
if not os.path.exists(conf_file_path):
45+
return Resource.get_empty()
46+
4447
try:
4548
with open(conf_file_path, encoding="utf-8") as conf_file:
4649
parsed_data = json.load(conf_file)

sdk-extension/opentelemetry-sdk-extension-aws/tests/resource/test_beanstalk.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,19 @@ class AwsBeanstalkResourceDetectorTest(unittest.TestCase):
4141
new_callable=mock_open,
4242
read_data=f'{{"deployment_id":"{MockBeanstalkResourceAttributes[ResourceAttributes.SERVICE_INSTANCE_ID]}","environment_name":"{MockBeanstalkResourceAttributes[ResourceAttributes.SERVICE_NAMESPACE]}","version_label":"{MockBeanstalkResourceAttributes[ResourceAttributes.SERVICE_VERSION]}"}}',
4343
)
44-
def test_simple_create(self, mock_open_function):
44+
@patch("os.path.exists", return_value=True)
45+
def test_simple_create(self, mock_path_exists, mock_open_function):
4546
actual = AwsBeanstalkResourceDetector().detect()
4647
self.assertDictEqual(
4748
actual.attributes.copy(),
4849
OrderedDict(MockBeanstalkResourceAttributes),
4950
)
51+
52+
@patch("os.name", "posix")
53+
@patch("os.path.exists", return_value=False)
54+
def test_not_on_beanstalk(self, mock_path_exists):
55+
actual = AwsBeanstalkResourceDetector().detect()
56+
self.assertDictEqual(actual.attributes.copy(), {})
57+
mock_path_exists.assert_called_once_with(
58+
"/var/elasticbeanstalk/xray/environment.conf"
59+
)

0 commit comments

Comments
 (0)