Repository: open-telemetry/opentelemetry-python

Issue:
DeprecationWarning with opentelemetry-python api + sdk both at 1.11.1
When calling `TracerProvicer.get_tracer()`, I see a deprecationwarning even though both libraries are at the same version.

The issue seems to be that the sdk instantiates an `InstrumentationInfo` object here:

https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py#L1162-L1166

which seems to be deprecated here:

https://github.com/open-telemetry/opentelemetry-python/blob/a3346ae9cf76d7f6b49ff4d3b9c358bb60f3c6ed/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py#L29-L40


Unless I'm misreading the coce, this means there is no way to get rid of this deprecation warning, because the library deprecated something but continues to use it, which seems unusual.

environment:

python 3.7.10

(relevant part of) requirements.txt
```
opentelemetry-api==1.11.1
opentelemetry-exporter-otlp-proto-grpc==1.11.1
opentelemetry-instrumentation==0.30b1
opentelemetry-instrumentation-asgi==0.30b1
opentelemetry-instrumentation-flask==0.30b1
opentelemetry-instrumentation-pymongo==0.30b1
opentelemetry-instrumentation-requests==0.30b1
opentelemetry-instrumentation-sqlalchemy==0.30b1
opentelemetry-instrumentation-wsgi==0.30b1
opentelemetry-proto==1.11.1
opentelemetry-sdk==1.11.1
opentelemetry-semantic-conventions==0.30b1
opentelemetry-util-http==0.30b1
```

Steps to reproduce:

We're seeing it when doing something like:

```python
from [our own central lbrary that re-exports some opentelemetry functions] import get_tracer
tracer = get_tracer(__name__)

with tracer.start_as_current_span(name=span_name, kind=SpanKind.CLIENT):
    [make a request to an external service] 
```

The only things that I can think of that are slightly unusual here is that we're importing get_tracer from a different place, and that we're starting a CLIENT span.


Discussion:
Hi team, just wanted to provide minimal snippet which reproduces this warning - we have faced it when checking output of our integration tests which spawn real app (with cloud tracing enabled) and call app endpoints as part of testing. In the example below it's all oversimplified, and only provides an ability to see warning in console when executing:

```python
import pytest
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.trace import get_tracer, set_tracer_provider

class App:
    # Oversimplified: in real world it has to configure span exporters, etc.
    @staticmethod
    def init_cloud_tracing():
        provider = TracerProvider()
        set_tracer_provider(provider)

    # Oversimplified: in real this is Web endpoint handler and tests calling it via HTTP
    @staticmethod
    def get_sum(a: int, b: int):
        # Add span which covers specific step of app logic (oversimplified)
        tracer = get_tracer(__name__)
        with tracer.start_as_current_span("Adding numbers"): 
            return a + b


def test_integration():
    App.init_cloud_tracing()
    assert App.get_sum(1, 2) == 3


# Run tests:
pytest.main()
```

Expected output: `no warnings`

Actual output:
```
...
test_trace.py .                                                          [100%]

=============================== warnings summary ===============================
test_trace.py::test_integration
  .venv/lib/python3.10/site-packages/opentelemetry/sdk/trace/__init__.py:1162: DeprecationWarning: Call to deprecated method __init__. (You should use InstrumentationScope) -- Deprecated since version 1.11.1.
    InstrumentationInfo(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================= 1 passed, 1 warning in 0.14s =========================

Process finished with exit code 0
```

Resolving patch:
diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
--- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
+++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
@@ -37,6 +37,7 @@
     Type,
     Union,
 )
+from warnings import filterwarnings, resetwarnings
 
 from deprecated import deprecated
 
@@ -1167,16 +1168,20 @@ def get_tracer(
             logger.error("get_tracer called with missing module name.")
         if instrumenting_library_version is None:
             instrumenting_library_version = ""
+
+        filterwarnings("ignore", category=DeprecationWarning)
+        instrumentation_info = InstrumentationInfo(
+            instrumenting_module_name,
+            instrumenting_library_version,
+            schema_url,
+        )
+        resetwarnings()
         return Tracer(
             self.sampler,
             self.resource,
             self._active_span_processor,
             self.id_generator,
-            InstrumentationInfo(
-                instrumenting_module_name,
-                instrumenting_library_version,
-                schema_url,
-            ),
+            instrumentation_info,
             self._span_limits,
             InstrumentationScope(
                 instrumenting_module_name,


Test patch:
diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py
--- a/opentelemetry-sdk/tests/trace/test_trace.py
+++ b/opentelemetry-sdk/tests/trace/test_trace.py
@@ -23,6 +23,7 @@
 from time import time_ns
 from typing import Optional
 from unittest import mock
+from unittest.mock import Mock
 
 from opentelemetry import trace as trace_api
 from opentelemetry.context import Context
@@ -39,7 +40,7 @@
     OTEL_TRACES_SAMPLER,
     OTEL_TRACES_SAMPLER_ARG,
 )
-from opentelemetry.sdk.trace import Resource
+from opentelemetry.sdk.trace import Resource, TracerProvider
 from opentelemetry.sdk.trace.id_generator import RandomIdGenerator
 from opentelemetry.sdk.trace.sampling import (
     ALWAYS_OFF,
@@ -58,6 +59,11 @@
 
 
 class TestTracer(unittest.TestCase):
+    def test_no_deprecated_warning(self):
+        with self.assertRaises(AssertionError):
+            with self.assertWarns(DeprecationWarning):
+                TracerProvider(Mock(), Mock()).get_tracer(Mock(), Mock())
+
     def test_extends_api(self):
         tracer = new_tracer()
         self.assertIsInstance(tracer, trace.Tracer)