Skip to content

Commit

Permalink
opentelemetry-sdk-extension-aws: make ecs detector less chatty
Browse files Browse the repository at this point in the history
Don't print warnings if we are not running inside an ecs instance so we can load the
resource detector more generally and avoid warnings in stderr.
  • Loading branch information
xrmx committed Dec 6, 2024
1 parent 6c92f38 commit ae3a3f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ def detect(self) -> "Resource":
if not os.environ.get(
"ECS_CONTAINER_METADATA_URI"
) and not os.environ.get("ECS_CONTAINER_METADATA_URI_V4"):
raise RuntimeError(
"Missing ECS_CONTAINER_METADATA_URI therefore process is not on ECS."
)
return Resource.get_empty()

container_id = ""
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def _http_get_function_fargate(url: str, *args, **kwargs) -> str:


class AwsEcsResourceDetectorTest(unittest.TestCase):
@patch.dict("os.environ", {}, clear=True)
def test_not_on_ecs(self):
actual = AwsEcsResourceDetector().detect()
self.assertDictEqual(actual.attributes.copy(), {})

@patch.dict(
"os.environ",
{"ECS_CONTAINER_METADATA_URI": "mock-uri"},
Expand Down

0 comments on commit ae3a3f9

Please sign in to comment.