Repository: open-telemetry/opentelemetry-python-contrib

Issue:
SQLAlchemy instrumentation sets `otel.library.name` as the vendor, not the library name
**Describe your environment** 

* Python 3.9.6
* `opentelemetry.instrumentation.sqlalchemy==0.28b1`

**Steps to reproduce**

Create an application that leverages SQLAlchemy and MySQL (or any vendor; I just used MySQL)
Install `opentelemetry.instrumentation.sqlalchemy==0.28b1`
Make a request to your backend application.
Observe the resulting spans.

**What is the expected behavior?**

The `otel.library.name` should report as `opentelemetry.instrumentation.sqlalchemy`.

**What is the actual behavior?**

The `otel.library.name` is the [DB vendor](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py#L40). In my case, it's `mysql`:

![Screen Shot 2022-02-14 at 4 30 49 PM](https://user-images.githubusercontent.com/33907262/153949771-2d8f3e64-b7c6-4b6e-907a-15c687b8bf8e.png)


This is super confusing when there is a separate [`opentelemetry.instrumentation.mysql`](https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-mysql) package that I'm not using.

**Additional context**

Nope!



SQLAlchemy instrumentation sets `otel.library.name` as the vendor, not the library name
**Describe your environment** 

* Python 3.9.6
* `opentelemetry.instrumentation.sqlalchemy==0.28b1`

**Steps to reproduce**

Create an application that leverages SQLAlchemy and MySQL (or any vendor; I just used MySQL)
Install `opentelemetry.instrumentation.sqlalchemy==0.28b1`
Make a request to your backend application.
Observe the resulting spans.

**What is the expected behavior?**

The `otel.library.name` should report as `opentelemetry.instrumentation.sqlalchemy`.

**What is the actual behavior?**

The `otel.library.name` is the [DB vendor](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py#L40). In my case, it's `mysql`:

![Screen Shot 2022-02-14 at 4 30 49 PM](https://user-images.githubusercontent.com/33907262/153949771-2d8f3e64-b7c6-4b6e-907a-15c687b8bf8e.png)


This is super confusing when there is a separate [`opentelemetry.instrumentation.mysql`](https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-mysql) package that I'm not using.

**Additional context**

Nope!





Discussion:

Resolving patch:
diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/__init__.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/__init__.py
--- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/__init__.py
+++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/__init__.py
@@ -104,7 +104,7 @@ def _instrument(self, **kwargs):
 
         if kwargs.get("engine") is not None:
             return EngineTracer(
-                _get_tracer(kwargs.get("engine"), tracer_provider),
+                _get_tracer(tracer_provider),
                 kwargs.get("engine"),
                 kwargs.get("enable_commenter", False),
             )
diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py
--- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py
+++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py
@@ -16,6 +16,9 @@
 from sqlalchemy.event import listen  # pylint: disable=no-name-in-module
 
 from opentelemetry import trace
+from opentelemetry.instrumentation.sqlalchemy.package import (
+    _instrumenting_module_name,
+)
 from opentelemetry.instrumentation.sqlalchemy.version import __version__
 from opentelemetry.instrumentation.utils import (
     _generate_opentelemetry_traceparent,
@@ -40,9 +43,9 @@ def _normalize_vendor(vendor):
     return vendor
 
 
-def _get_tracer(engine, tracer_provider=None):
+def _get_tracer(tracer_provider=None):
     return trace.get_tracer(
-        _normalize_vendor(engine.name),
+        _instrumenting_module_name,
         __version__,
         tracer_provider=tracer_provider,
     )
@@ -55,7 +58,7 @@ def _wrap_create_async_engine_internal(func, module, args, kwargs):
         object that will listen to SQLAlchemy events.
         """
         engine = func(*args, **kwargs)
-        EngineTracer(_get_tracer(engine, tracer_provider), engine.sync_engine)
+        EngineTracer(_get_tracer(tracer_provider), engine.sync_engine)
         return engine
 
     return _wrap_create_async_engine_internal
@@ -68,7 +71,7 @@ def _wrap_create_engine_internal(func, module, args, kwargs):
         object that will listen to SQLAlchemy events.
         """
         engine = func(*args, **kwargs)
-        EngineTracer(_get_tracer(engine, tracer_provider), engine)
+        EngineTracer(_get_tracer(tracer_provider), engine)
         return engine
 
     return _wrap_create_engine_internal
diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/package.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/package.py
--- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/package.py
+++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/package.py
@@ -12,5 +12,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+_instrumenting_module_name = "opentelemetry.instrumentation.sqlalchemy"
 
 _instruments = ("sqlalchemy",)


Test patch:
diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py
--- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py
+++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py
@@ -70,6 +70,10 @@ async def run():
             self.assertEqual(len(spans), 1)
             self.assertEqual(spans[0].name, "SELECT :memory:")
             self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT)
+            self.assertEqual(
+                spans[0].instrumentation_scope.name,
+                "opentelemetry.instrumentation.sqlalchemy",
+            )
 
         asyncio.get_event_loop().run_until_complete(run())
 
@@ -104,6 +108,10 @@ def test_create_engine_wrapper(self):
         self.assertEqual(len(spans), 1)
         self.assertEqual(spans[0].name, "SELECT :memory:")
         self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT)
+        self.assertEqual(
+            spans[0].instrumentation_scope.name,
+            "opentelemetry.instrumentation.sqlalchemy",
+        )
 
     def test_custom_tracer_provider(self):
         provider = TracerProvider(
@@ -154,6 +162,10 @@ async def run():
             self.assertEqual(len(spans), 1)
             self.assertEqual(spans[0].name, "SELECT :memory:")
             self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT)
+            self.assertEqual(
+                spans[0].instrumentation_scope.name,
+                "opentelemetry.instrumentation.sqlalchemy",
+            )
 
         asyncio.get_event_loop().run_until_complete(run())