-
Notifications
You must be signed in to change notification settings - Fork 629
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
Enforce one distro is installed #571
Enforce one distro is installed #571
Conversation
@owais Here is a PR to enforce only 1 distro be installed on the system! Would appreciate your feedback 😄 |
b653174
to
228061f
Compare
228061f
to
6f057bd
Compare
...etry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py
Outdated
Show resolved
Hide resolved
@@ -96,7 +113,14 @@ def _load_configurators(): | |||
) | |||
continue | |||
try: | |||
entry_point.load()().configure() # type: ignore | |||
configurator: BaseConfigurator = entry_point.load()() | |||
if not isinstance(configurator, BaseConfigurator): |
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.
Do we want to enforce nominal typing at runtime here? I don't see this adding a ton of benefit but these things keep adding up to the "startup" cost of the SDK which can be critical in environments like AWS Lambda with really low resources.
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 we consider startup costs should we remove the type check for BaseDistro
?
Lines 38 to 42 in 753e228
if not isinstance(distro, BaseDistro): | |
logger.debug( | |
"%s is not an OpenTelemetry Distro. Skipping", | |
entry_point.name, | |
) |
I guess it has the benefit of checking a Distro and we know that Distro's have Configurators. I'll remove this but let me know if you think we should remove the BaseDistro
check too.
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'm not sure. What benefit do we get from this message? it's also logging on debug level but we are paying the cost of isinstance always. i personally feel we should remove this. This isn't something that is going to be very helpful to end users IMO. If anyone publishes a package with a distro entrypoint that doesn't satisfy the interface, an attribute/type error would probably be good enough 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.
Okay I agree with you! I will remove it since I'm changing those lines anyways.
raise RuntimeError("Cannot Auto Instrument with multiple distros installed.") | ||
|
||
return first_distro.load()() | ||
except IndexError: |
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.
this would be StopIteration
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.
Right, thank you! I changed it and configured that's what we wanted in my tests 😄
opentelemetry-instrument python3 auto-instrumentation/flask/application.py
Initializing Auto Instrumentation without using a distro.
* Serving Flask app "create_flask_app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
Hm, not sure if this is the approach we previously discussed. I don't think we should enforce only one distro being installed, but we should have a default one and let the user select one with an environment variable. |
Ah, yes. Sorry, I forgot to vote. Also, detecting the error when running |
Hm I'm not familiar with how to make packages exclusive from each other at install time... I don't know if you can do that at |
Also, this approach is very inconvenient for someone who may want to switch between more than one distro repeatedly (for testing purposes, for example). |
I have a dumb question, why do we limit to only one distro? |
return first_distro.load()() | ||
except StopIteration: | ||
logger.warning( | ||
"Initializing Auto Instrumentation without using a distro." |
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.
A description of the error would be good.
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.
Added the following description:
logger.warning(
"Failed to find even one installed distro. Initializing Auto Instrumentation without using a distro."
)
...etry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py
Outdated
Show resolved
Hide resolved
@NathanielRN |
@lonewolf3739
It's not a dumb questions 😄 The goal is just to make it easier for the user, because if multiple distros are installed they probably will set conflicting values and produce confusing bugs. i.e.
We mentioned this comment in #551 that this would be confusing. But like @ocelotl said there are cases like testing multiple distros where this setup would be inconvenient. It probably warrants a SIG discussion at this point. |
Enforcing 1 Lines 91 to 97 in 2ee2cf3
What I meant in this PR is that we enforce one Distro which means we enforce one Configurator. However I can see why that's confusing, I'll update the title. |
The way I imagined this is each distro would add to existing values or creates one if it doesn't exist, for example, the propagator is initially set to |
We decided to go in a different direction for distro, follow the results here: open-telemetry/opentelemetry-python#2005 |
Description
Small PR to enforce that only one distro be installed when trying to run auto instrumentation.
Additionally, checks that the
Configurator
that is loaded automatically is a derived class ofBaseConfigurator
. The idea is thatConfigurator
s should come from distros and every distro should provide one. (Even if they just subclass theopentelemetry-sdk
package Configurator which does a pretty good configuration).Follow up to: #551
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Unfortunately I can't add unit tests because if you import functions from
sitecustomize.py
it will try to run the whole file and auto instrument which we can't do in a testing environment for now...But I did confirm locally that an error is thrown only if multiple distros are installed:
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.
- [ ] Unit tests have been addedSee comment about testing above.