Replies: 4 comments 6 replies
-
Relatedly, instead of eagerly loading all the libraries available on the Python path, it would be cool if import hooks (e.g. wrapt's |
Beta Was this translation helpful? Give feedback.
-
Thanks for starting this. I agree with most of what has been said and still consolidating the scattered thoughts. Here is some related issue #1563. |
Beta Was this translation helpful? Give feedback.
-
I think "3. Try to instrument anyway" might lead to unexpected results, like if the patched function's signature changes in a subtle way and we accidentally mix up span attributes. Runtime version checks sound like a good idea. One concern is it becomes difficult for users to tell the actual supported versions of instrumented libraries. It would be great if users could opt-in to the dependency conflict checks. Maybe with
|
Beta Was this translation helpful? Give feedback.
-
Turns out we can use the 2nd option and implement this it centrally in the instrument command instead of changing every single instrumentation. @aabmass suggested we specify the dependencies as extras instead of completely removing them so that users can still enforce compatibility at install time. This also allows the instrument command to inspect instrumentation packages and only load/apply instrumentations whose extra dependencies are installed. This allows us to not specify the instrumented packages as dependencies for instrumentations while allowing users to retain the previous behavior if they want. Also, this does not require any code or interface changes to instrumentations at all. Link to POC: #1741 |
Beta Was this translation helpful? Give feedback.
-
Instrumentation packages patch popular libraries or frameworks at runtime to make them observable. However, it is not practical for instrumentation packages to support all versions of any given library. As a result, instrumentations need a way to specify the supported version ranges for the libraries. Today, we solve this by specifying the libraries as dependencies for instrumentations. For example, if Flask instrumentation works with Flask 1.0, the instrumentation specifies
flask ~= 1.0
as a dependency. This ensures that users installing the instrumentation with an unsupported library version will get a dependency conflict and as a result not let the user install the instrumentation package.This solves the problem but it also forces users to install the libraries when installing the instrumentation packages. This may not be ideal in all situations.
For example, this complicates getting started with OpenTelemetry and requires additional tooling to make things easier (opentelemetry-bootstrap command) as users must only install the exact instrumentation packages that are a perfect fit for their environment.
Proposal
I propose we stop specifying the target libraries as dependencies and use an alternate mechanism to specify supported version ranges.
Pros
pip install opentelemetry-instrumentations-all
.opentelemetry-bootstrap
command and simplify instrumenting Python services.@opentelemetry/plugins-node-core-and-contrib
. In both cases installing additional instrumentations is harmless as they don't pull in additional libraries and are too small to inflate overall size.Alternatives
Runtime version checks
Instrumentations attempt to import the target libraries and monkey patches them. We can simply update the instrumentations to check if the installed target library is a supported version and only patch it in that case. When an unsupported library is found, instrumentation can log a warning and return early without applying any patches.
Identifying versions
1. Use information provided by libraries
Most libraries include their version number in code and make it importable. This should be used by instrumentations to identify the target library version when possible. For example,
2. Use pkg_resources
If a library does not include it's version number in code,
pkg_resources
can be used to load metadata about installed Python packages. This can be used to identify installed versions. For example,3. Identify by structure/traits
If for some reason
pkg_resources
cannot be used, the instrumentation should try to identify the version by looking for well known traits such as presence of certain attributes, classes, modules etc.Beta Was this translation helpful? Give feedback.
All reactions