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

BoundedDict was deprecated in opentelemetry-python 1.4.0

Open poolpitako opened this issue 2 years ago • 6 comments

Changelog: https://github.com/open-telemetry/opentelemetry-python/blob/main/CHANGELOG.md#version-140023b0-2021-07-21

Used in in https://github.com/GoogleCloudPlatform/opentelemetry-operations-python/blob/773ee41c867f03c062b3be3a5b8d30a32c394f04/opentelemetry-exporter-gcp-trace/src/opentelemetry/exporter/cloud_trace/init.py#L498

Usage of the library will print:

/Users/user/.pyenv/versions/3.9.9/lib/python3.9/site-packages/opentelemetry/exporter/cloud_trace/__init__.py:498: DeprecationWarning: Call to deprecated class BoundedDict. -- Deprecated since version 1.4.0.
  ] = BoundedDict(num_attrs_limit)

poolpitako avatar Jan 06 '23 05:01 poolpitako

This was just removed from the public API of OTel so should keep warning. I agree we should fix this to stop the log spam, probably just by copying the code for BoundedDict into this repo.

aabmass avatar Jan 11 '23 19:01 aabmass

This produces a lot of log noise which we are billed for. I have not been able to figure out how to suppress the warning as a consumer of this package. Is there any chance the warning could be suppressed until a better solution is implemented?

nnutter avatar Feb 23 '23 20:02 nnutter

Here's a workaround that suppresses the warning:

import warnings

from opentelemetry.exporter import cloud_trace

class CloudTraceSpanExporterWithoutWarnings(cloud_trace.CloudTraceSpanExporter):
    """Suppresses DeprecationWarning raised by CloudTraceSpanExporter.

    See for details:
    https://github.com/GoogleCloudPlatform/opentelemetry-operations-python/issues/226
    """

    def export(self, *args, **kwargs):
        with warnings.catch_warnings():
            warnings.simplefilter("ignore", category=DeprecationWarning)
            super().export(*args, **kwargs)

parabolala avatar Feb 23 '23 21:02 parabolala

opentelemetry-api/opentelemetry-sdk v1.16.0 removes a warnings.resetwarnings() which is what I think was causing these deprecation warnings to have been spamming our logs. As far as I can tell Python does not show these warnings by default and it was that resetwarnings() call that was removing the default filters.

nnutter avatar Mar 18 '23 00:03 nnutter

Glad to see that they resolved the log spam issue but it seems like we should resolve the underlying issue as well.

It looks like opentelemetry.sdk.util.BoundedDict (sdk) was deprecated in favor of the equivalent class opentelemetry.attributes.BoundedAttributes (api) here https://github.com/open-telemetry/opentelemetry-python/pull/1915

Would it make more sense to just switch to the new non-deprecated class rather than pulling a copy of the deprecated class into this repo?

shevisj avatar Apr 21 '23 17:04 shevisj

The linked PR is not working but glad the log spam has stopped. Can I assign this to you @shevisj ?

aabmass avatar Jul 17 '23 18:07 aabmass