opentelemetry-python icon indicating copy to clipboard operation
opentelemetry-python copied to clipboard

Better version checking for backoff package in OTLP exporters

Open srikanthccv opened this issue 3 years ago • 8 comments

    > Okay @srikanthccv this is updated and there are testcases for all three exporters (gRPC, HTTP trace, HTTP log) which fail if the new code is removed, or you manually set `_is_backoff_v2` to be `False`.

I've kept the behaviour sniffing rather than looking for explicit versions because the latter gets tricky quickly. backoff ~= 1.0.0 doesn't have a __version__ module field, and backoff ~= 2.0.0 has a string __version__ field (e.g. '2.2.1') which we'd then have to parse... but defensively because it might not always be a string... the whole thing gets really messy, and just looking for the behaviour we need to know about is not just easier but also less fragile.

This is a better way to check for a package version number:

In [7]: import pkg_resources

In [8]: pkg_resources.get_distribution("backoff").version
Out[8]: '1.0'
In [1]: import pkg_resources

In [2]: pkg_resources.get_distribution("backoff").version
Out[2]: '2.0.0'

Originally posted by @ocelotl in https://github.com/open-telemetry/opentelemetry-python/issues/2980#issuecomment-1297529699

srikanthccv avatar Oct 31 '22 18:10 srikanthccv

Hi @srikanthccv I am picking this issue #outreachy

Buduzz avatar Nov 01 '22 11:11 Buduzz

@Buduzz Looking at the pull request changes, I don't think you understood the issue. What is needed is the removal of this logic (in all other places), which tries to infer the version by checking the code behavior and introduce the conditional logic by checking the backoff version using pkg_resources.

srikanthccv avatar Nov 03 '22 19:11 srikanthccv

@srikanthccv thank you, I'll make the adjustments and revert

Buduzz avatar Nov 03 '22 22:11 Buduzz

I'll just note here that pkg_resources is deprecated. If you want to look up and parse versions explicitly, this should be done with importlib.metadata:

In [1]: from importlib.metadata import version

In [2]: version('backoff')
Out[2]: '1.0'
In [1]: from importlib.metadata import version

In [2]: version('backoff')
Out[2]: '2.2.1'

You will likely still need apkg_resources fallback so long as you are still supporting Python 3.7.

nickstenning avatar Nov 04 '22 11:11 nickstenning

Is this issue resolved? I am looking for a "good first issue" as I have never contributed to open source before.

Emmaka9 avatar Nov 12 '22 07:11 Emmaka9

This is not resolved yet, but there is already one PR attempting to address it, so I suggest you pick another good-first-issue.

srikanthccv avatar Nov 12 '22 13:11 srikanthccv

@nickstenning

You will likely still need apkg_resources fallback so long as you are still supporting Python 3.7.

Is this not why the backport of importlib_metadata and importlib_resources exists?

Side note: This seems to be linked to #2927

GDegrove avatar Nov 18 '22 08:11 GDegrove

@srikanthccv if this issue is still open I would like to work on it?

Annosha avatar Oct 07 '24 21:10 Annosha

@Annosha

I don't believe this issue is relevant anymore since this pr.

lzchen avatar Oct 30 '24 17:10 lzchen