-
Notifications
You must be signed in to change notification settings - Fork 599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add AWS resource detectors to extension package #586
Add AWS resource detectors to extension package #586
Conversation
2a2f1e7
to
a7d004a
Compare
Blocked on #585, converting to draft. |
...xtension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/eks.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for doing this.
...ion/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/__init__.py
Show resolved
Hide resolved
...ion/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/__init__.py
Show resolved
Hide resolved
...ion/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/__init__.py
Show resolved
Hide resolved
...sion/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/_lambda.py
Outdated
Show resolved
Hide resolved
...sion/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/_lambda.py
Outdated
Show resolved
Hide resolved
7bbc574
to
2bb89dd
Compare
@@ -0,0 +1,31 @@ | |||
# Copyright The OpenTelemetry Authors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: opentelemetry.sdk.extension.aws.resources
plural to match opentelemetry.sdk.resources
? Not a big deal though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I didn't even notice that, actually I did resource
because that is the folder it is in on the specifications
Also in java we put it under resource
And yet JavaScript, Go and PHP all put it under a folder called detectors/
😅
I guess I'll defer to the SIG here, as GCP and other vendors will probably add their resource Detectors soon... maybe we should even move the SDK import path? 😓 Although I imagine that will be hard after 1.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We aren't at 1.0
yet so nows the time to decide on an import path :D. But again, not a blocker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I meant we should move opentelemetry.sdk.resources
to opentelemetry.sdk.resource
to match the spec 🙂
I actually like .resource
because there is only 1 resource:
namespace in the attributes. Even if you add multiple ResourceDetector
s you're still setting attributes in 1 namespace...
I'll leave it for now and if we need to we'll change it before this package goes 1.0 😄. Shouldn't be a big deal to do "both" if we need to as well later!
...sion/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/_lambda.py
Outdated
Show resolved
Hide resolved
...sion/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/_lambda.py
Show resolved
Hide resolved
...sion/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/_lambda.py
Show resolved
Hide resolved
...xtension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/ecs.py
Outdated
Show resolved
Hide resolved
...xtension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/eks.py
Outdated
Show resolved
Hide resolved
79b9fb6
to
cc84b34
Compare
|
||
container_id = "" | ||
try: | ||
with open( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'll be better to catch this specific type of exception below than to have nested general exceptions caught.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand you correctly, you think it would be better than we catch FileNotFoundError
specifically? That makes sense to me! I'll update it here and in the eks.py
file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
} | ||
) | ||
# pylint: disable=broad-except | ||
except Exception as exception: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm it would have been nice if this was handled in the ResourceDetector
super class so the implementations didn't have to duplicate it every time, but too late now I think 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a really good point, do you mean something like this on opentelemetry-python-core?:
class ResourceDetector(abc.ABC):
def __init__(self, raise_on_error=False):
self.raise_on_error = raise_on_error
@abc.abstractmethod
def _detect(self) -> "Resource":
raise NotImplementedError()
def detect(self) -> "Resource":
try:
self._detect()
except NotImplementedError as exception:
raise exception
# pylint: disable=broad-except
except Exception as exception:
if self.raise_on_error:
raise exception
logger.warning(f"{self.__class__.__name__} failed: {exception}")
return Resource.get_empty()
I think that would definitely be worth it, maybe we can add it in a minor release for now and support (but deprecate) the existing method?
If this sounds like it makes sense I can open a small PR with this change on core! 🙂
except Exception as exception: | ||
e_msg = f"{self.__class__.__name__} failed: {exception}" | ||
if self.raise_on_error: | ||
logger.exception(e_msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is logging this redudant if we a re re-raising?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm that's a good point, I was hoping to add class name to the exception as e_msg = f"{self.__class__.__name__} failed: {exception}"
, but they can see it as been obvious enough from the Traceback.
Thanks! I'll update these exceptions across the detectors 🙂
0f74f17
to
530a91b
Compare
Description
This PR adds Resource Detectors to automatically populate attributes under the
resource
namespace of every span. The included Resource Detectors are for the following AWS Service:This is similar to packages already available on OpenTelemetry JavaScript and OpenTelemetry Java.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
ResourceDetectors
have unit tests to verify file reading/API conformanceResourceDetectors
, I was able to run OTel Python on these services and verify that the spans are populated with the right attributes.Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.