open-telemetry / opentelemetry-python

OpenTelemetry Python API and SDK
https://opentelemetry.io
Apache License 2.0
1.79k stars 622 forks source link

Better version checking for backoff package in OTLP exporters #3006

Open srikanthccv opened 1 year ago

srikanthccv commented 1 year ago
    > 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

Buduzz commented 1 year ago

Hi @srikanthccv I am picking this issue #outreachy

srikanthccv commented 1 year ago

@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.

Buduzz commented 1 year ago

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

nickstenning commented 1 year ago

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.

Emmaka9 commented 1 year ago

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

srikanthccv commented 1 year ago

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

GDegrove commented 1 year ago

@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

Annosha commented 2 weeks ago

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