-
Notifications
You must be signed in to change notification settings - Fork 651
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
Default configurators do more for distros #1937
Default configurators do more for distros #1937
Conversation
@owais Would appreciate your input on this PR! Specifically what you think about moving it under the Hopefully this makes it easier to create more distros :) Thank you! |
Converting to draft while I fix the unit tests. |
"opentelemetry.sdk.instrumentation.TracerProvider", Provider | ||
) | ||
self.get_processor_patcher = patch( | ||
"opentelemetry.distro.BatchSpanProcessor", Processor | ||
"opentelemetry.sdk.instrumentation.BatchSpanProcessor", Processor |
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.
These tests only really check these helpful Configurator
methods so I thought they made sense to move completely to the opentelemetry-sdk
package. There's nothing "opentelemetry-distro
" related about them really...
Since distro already depends on opentelemetry-instrumentation which is still not stable, can we move the resuable code to that package instead of SDK? We can let it mature there and move to SDK later if we want. It'd be impossible or very hard to change these interfaces later if we add them to SDK. |
opentelemetry-distro/setup.cfg
Outdated
@@ -50,9 +50,9 @@ where = src | |||
|
|||
[options.entry_points] | |||
opentelemetry_distro = | |||
distro = opentelemetry.distro:OpenTelemetryDistro | |||
otel-distro = opentelemetry.distro:OpenTelemetryDistro |
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.
Wonder if we really need OpenTelemetry in the name if it is already in the path. opentelemetry.distro.Distro
sounds nicer to me but may be that's just me.
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.
same thing about the plugin name. Why opentelemetry_distro.otel-distro
instead of opentelemetry_distro.distro
. I know neither is perfect but is there a reason to repeat otel?
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 see what you're saying, I actually wouldn't have changed except for what I learned in this Contrib PR to Enforce 1 Distro/Configurator: open-telemetry/opentelemetry-python-contrib#571
In that PR, I want to log a useful error message if the user has multiple distros installed, but when it was just distro
I didn't know where that distro was combing from. I thought have a message like Multiple distros were found: (otel-distro,aws-distro,splunk-distro)
would be better because you know where they are coming from?
I guess the user knows what they installed though so we can keep just 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.
Sorry if I misunderstand, but is "plugin name" the same as "entry_point"? Actually you gave me a good idea :]
I print out the attributes available on the entry_point and say this:
otel-distro = opentelemetry.distro:OpenTelemetryDistro
{'attrs': ('OpenTelemetryDistro',),
'dist': opentelemetry-distro 0.23.dev0 (/usr/local/lib/python3.9/site-packages),
'extras': (),
'module_name': 'opentelemetry.distro',
'name': 'otel-distro'}
So I can use the module_name
for my purpose in that Contrib repo. Will change this back!
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.
Yeah but in that case we don't need to include distro
in it probably. It could just be otel
, aws
, lightstep
etc but doesn't really matter.
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.
Agreed, I'll just use module_name
because it's easiest and we can always change it later (try to delete the "distro" substring) if we want.
opentelemetry-sdk/src/opentelemetry/sdk/instrumentation/__init__.py
Outdated
Show resolved
Hide resolved
I see now that most of the things are private. I think in that case adding to SDK is much more simpler. I'm not sure about |
opentelemetry-sdk/src/opentelemetry/sdk/instrumentation/__init__.py
Outdated
Show resolved
Hide resolved
Just as a follow up to our conversation in here a couple of comments (which I believe everyone involved in this conversation already know but just so that they are written somewhere):
I understand that not bothering the user with setting an environment variable to use a distro is desirable, and I agree with that. I also understand that it is expected that most situations will require only one distro being installed. Considering that, I suggest we do the following:
What are your thoughts? @lzchen, @owais, @NathanielRN, @lonewolf3739, @aabmass, @codeboten |
Since all of the configuration code is private I am fine with it and it even makes sense that there is some mechanism to configure sdk without installing another package. Maybe we can propose an abstract concept of SDK configuration to spec. I am still kind of confused between only install one distro-allow multiple distros install but use one-allow multiple distros usage see my comment from other thread open-telemetry/opentelemetry-python-contrib#571 (comment). |
IMO allowing multiple distros no matter how detailed the heuristics we come up with will end up causing pain to end-users. I think this will be especially true if we go out of our way to make it possible to allow using distros as libraries for code reuse. That'll just encourage people to extend other distros even more resulting in the problem getting even worse. I think it's fine if distros are not reusable as libraries. If we can provide the most useful code as a util/base library then each distro should only contain vendor-specific configuration and it wouldn't make any sense for anyone to extend such distros. To me, distros are more like CLI commands meant to be consumed by the end-user. Sure, with a dynamic language like Python, it is possible to import CLI command (or distro) code and use it as a library but that doesn't mean the command author intended to ship a library or that one should use it as one. In other words, just because the Python import system allows to import of a piece of code does not mean the author intended the code to be a library. IMO we should explicitly call out that distros are not libraries but end-user consumable/runnable products. While I agree with the sentiment that code should be reusable, in practice I don't see why anyone would want to reuse code from an AWS, Google or Lightstep distro to build their own. The only valid use case that comes to mind is if a distro contains a bug and a user temporarily fixes the bug by subclassing the distro. This is the only practical situation I can think of where allowing multiple distros could help. That said, I think it's fine to expect users to use a fork in temporary situations like these. |
If we really wanted to support multiple distros, I'd prefer a method that works deterministically and reliably without any intervention required by the user. For example,
If we had to allow multiple ones, I'd go with 2 but I still strongly prefer to just never allow more than one distros. I think it simplifies the overall design and UX and the price to pay (fork vs import) is a very small one IMO especially if we make useful functions available elsewhere (sdk/instrumentation). |
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 change looks like a step in the right direction to me.
Agreed. More specifically, I doubt people will distribute a
Agreed. I don't think we should over complicate this, besides this seems out of scope for this PR. @ocelotl I understand your concerns, but at the very least the discussion on this PR is running away from its original purpose. Merging this PR does not mean multiple distros can't be installed. It just moves useful methods to the SDK that all distros can use. Design opinions may differ because some may want distros to inherit from others, but like @owais pointed out, distros should really just be setting environment variables to configure the SDK. This PR just makes these useful functions available so it enables developers. The current setup is blocking developers. Would appreciate your reviews @lzchen @owais @ocelotl @lonewolf3739 of this PR independently without thinking about the multiple distros issue which should be apart of open-telemetry/opentelemetry-python-contrib#571 (and now that the instrumentation package is moved this will need a new PR). |
664701f
to
df33ede
Compare
@NathanielRN ok, I understand your point. I'll look into this ASAP |
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.
Couple of comments after reviewing the public api check. I think the change from Configurator -> OpenTelemetryConfigurator is ok, probably best to hide or remove the logger though.
from opentelemetry.sdk.trace.export import BatchSpanProcessor, SpanExporter | ||
from opentelemetry.sdk.trace.id_generator import IdGenerator | ||
|
||
logger = getLogger(__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.
Is logger ever used?
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.
It's not used, you're right! It was actually already there from the distro file previously, but since it's not used I'll remove it and anything else redundant.
Ok, I am ok with this change being merged, because the code being moved into the SDK is private. I actually disagree with having anything distro-related in the SDK because it is outside of the SDK spec. |
@ocelotl If the contention is adding this to SDK, why don't we add it to instrumentation package instead? This should be a non-issue given that the package already hosts distro related code (THE base distro actually) |
That sounds good, but @NathanielRN has mentioned that this PR is blocking developers and I don't want to hold it longer, specially now that it has been approved already. I say we merge it as it is and consider the next step later if necessary. |
We probably wouldn't want to do this, since these methods configure
If that's the concern, one solution I can think of is to make a totally new package called |
CHANGELOG.md
Outdated
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | |||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | |||
|
|||
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.3.0-0.22b0...HEAD) | |||
- `opentelemetry-distro` & `opentelemetry-sdk` Moved Auto Instrumentation Configurator code to SDK | |||
to let distros use its default implementation | |||
([#1934](https://github.com/open-telemetry/opentelemetry-python/pull/1934)) |
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.
([#1934](https://github.com/open-telemetry/opentelemetry-python/pull/1934)) | |
([#1937](https://github.com/open-telemetry/opentelemetry-python/pull/1937)) |
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.
Thank you!
opentelemetry-distro/setup.cfg
Outdated
@@ -41,7 +41,7 @@ packages=find_namespace: | |||
zip_safe = False | |||
include_package_data = True | |||
install_requires = | |||
opentelemetry-api ~= 1.3 | |||
opentelemetry-api == 1.4.0.dev0 |
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.
What's the reason for this change?
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 didn't realize we were pinning version specifically as of #1933 ... I thought this was just missed in a release 😅 . Will revert this change!
Configurators can subclass and slightly alter this initialization. | ||
|
||
NOTE: This class should not be instantiated nor should it become an entry | ||
point on the `opentelemetry-sdk` package. Instead, distros should subclass |
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.
Should distros be subclassing this class or OpenTelemetryConfigurator
?
@NathanielRN please resolve conflicts, @lzchen can you approve if all your comments have been addressed. Thanks! |
ea9e20a
to
47c0755
Compare
@codeboten Conflicts resolved! |
Description
In order to make it easier for users to write distros, we remove the useful code in the
opentelemetry-distro
package and make it available to all distros in theopentelemetry-sdk
package.Important points
Every distro must provide a
Configurator
and aDistro
.The Configurator can simply subclass
_OTelSDKConfigurator
which provides a default initalization ofTracerProvider
among other things. However, this class should never be instantiated itself.Configurators
should belong to distros.No dependencies changed because
opentelemetry-distro
depends onopentelemetry-sdk
opentelemetry-sdk
depends onopentelemetry-instrumentation
opentelemetry-distro
depends onopentelemetry-instrumentation
pip install opentelemetry-distro
to get started with Auto InstrumentationI tried to do something clever to preserve git history when moving
opentelemetry-distro
->opentelemetry-sdk
but I'm worried it will be lost in the Squash & Merge :]Fixes open-telemetry/opentelemetry-python-contrib#551
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
I used editable installs (e.g.
pip install -e ~/my/repo/path/opentelemetry-python/optelemetry-distro
) to verify that I can still use the Auto Instrumentation executableopentelemetry-instrument python3 my_app.py
and the distro still gets asked to configure OTel Python.Does This PR Require a Contrib Repo Change?
Checklist:
- [ ] Unit tests have been added(We didn't ADD any tests but we did move the related Configurator tests to thetest-core-sdk
test suite!)