Skip to content

Commit

Permalink
opentelemetry-sdk-extension-aws: make beanstalk detector less chatty
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xrmx committed Dec 6, 2024
1 parent ae3a3f9 commit 281f6b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def detect(self) -> "Resource":
else:
conf_file_path = "/var/elasticbeanstalk/xray/environment.conf"

if not os.path.exists(conf_file_path):
return Resource.get_empty()

try:
with open(conf_file_path, encoding="utf-8") as conf_file:
parsed_data = json.load(conf_file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,19 @@ class AwsBeanstalkResourceDetectorTest(unittest.TestCase):
new_callable=mock_open,
read_data=f'{{"deployment_id":"{MockBeanstalkResourceAttributes[ResourceAttributes.SERVICE_INSTANCE_ID]}","environment_name":"{MockBeanstalkResourceAttributes[ResourceAttributes.SERVICE_NAMESPACE]}","version_label":"{MockBeanstalkResourceAttributes[ResourceAttributes.SERVICE_VERSION]}"}}',
)
def test_simple_create(self, mock_open_function):
@patch("os.path.exists", return_value=True)
def test_simple_create(self, mock_path_exists, mock_open_function):
actual = AwsBeanstalkResourceDetector().detect()
self.assertDictEqual(
actual.attributes.copy(),
OrderedDict(MockBeanstalkResourceAttributes),
)

@patch("os.name", "posix")
@patch("os.path.exists", return_value=False)
def test_not_on_beanstalk(self, mock_path_exists):
actual = AwsBeanstalkResourceDetector().detect()
self.assertDictEqual(actual.attributes.copy(), {})
mock_path_exists.assert_called_once_with(
"/var/elasticbeanstalk/xray/environment.conf"
)

0 comments on commit 281f6b1

Please sign in to comment.