diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/ecs.py b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/ecs.py index b780633b69..07d4553350 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/ecs.py +++ b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/ecs.py @@ -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: diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/tests/resource/test_ecs.py b/sdk-extension/opentelemetry-sdk-extension-aws/tests/resource/test_ecs.py index 4f892cc1bb..b116ae8229 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/tests/resource/test_ecs.py +++ b/sdk-extension/opentelemetry-sdk-extension-aws/tests/resource/test_ecs.py @@ -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"},