Skip to content

Commit 1462091

Browse files
committed
Keep a debug log in case we are not able to get the token
1 parent 0eba358 commit 1462091

File tree

2 files changed

+16
-2
lines changed
  • sdk-extension/opentelemetry-sdk-extension-aws

2 files changed

+16
-2
lines changed

Diff for: sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/ec2.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ def detect(self) -> "Resource":
8484
# If can't get a token quick assume we are not on ec2
8585
try:
8686
token = _get_token(timeout=1)
87-
except URLError:
87+
except URLError as exception:
88+
logger.debug(
89+
"%s failed to get token: %s",
90+
self.__class__.__name__,
91+
exception,
92+
)
8893
return Resource.get_empty()
8994

9095
identity_dict = json.loads(_get_identity(token))

Diff for: sdk-extension/opentelemetry-sdk-extension-aws/tests/resource/test_ec2.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,14 @@ def test_simple_create(
8282
def test_empty_resource_if_token_returns_an_url_error(
8383
self, mock_get_token
8484
):
85-
actual = AwsEc2ResourceDetector().detect()
85+
with self.assertLogs(
86+
"opentelemetry.sdk.extension.aws.resource.ec2", level="DEBUG"
87+
) as logger:
88+
actual = AwsEc2ResourceDetector().detect()
89+
self.assertEqual(
90+
logger.output,
91+
[
92+
"DEBUG:opentelemetry.sdk.extension.aws.resource.ec2:AwsEc2ResourceDetector failed to get token: <urlopen error Something went wrong>"
93+
],
94+
)
8695
self.assertDictEqual(actual.attributes.copy(), OrderedDict())

0 commit comments

Comments
 (0)