Repository: open-telemetry/opentelemetry-python

Issue:
Missing instrumentation library name and version from OTLP exported metrics
The instrumentation library name and version are missing from the OTLP exported metrics.


Discussion:

Resolving patch:
diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py
--- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py
+++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py
@@ -304,9 +304,11 @@ def _translate_data(
                 )
                 argument = type_class[value_type]["gauge"]["argument"]
 
-            sdk_resource_instrumentation_library_metrics[
+            instrumentation_library_metrics = sdk_resource_instrumentation_library_metrics[
                 export_record.resource
-            ].metrics.append(
+            ]
+
+            instrumentation_library_metrics.metrics.append(
                 OTLPMetric(
                     **{
                         "name": export_record.instrument.name,
@@ -317,6 +319,19 @@ def _translate_data(
                 )
             )
 
+            instrumentation_library_metrics.instrumentation_library.name = (
+                export_record.instrument.meter.instrumentation_info.name
+            )
+
+            version = (
+                export_record.instrument.meter.instrumentation_info.version
+            )
+
+            if version:
+                (
+                    instrumentation_library_metrics.instrumentation_library.version
+                ) = version
+
         return ExportMetricsServiceRequest(
             resource_metrics=_get_resource_data(
                 sdk_resource_instrumentation_library_metrics,
diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py
--- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py
+++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py
@@ -14,7 +14,6 @@
 """OTLP Span Exporter"""
 
 import logging
-import os
 from typing import Optional, Sequence
 
 from grpc import ChannelCredentials


Test patch:
diff --git a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py
--- a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py
+++ b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py
@@ -26,6 +26,7 @@
 )
 from opentelemetry.proto.common.v1.common_pb2 import (
     AnyValue,
+    InstrumentationLibrary,
     KeyValue,
     StringKeyValue,
 )
@@ -61,7 +62,7 @@ def setUp(self, mock_time_ns):  # pylint: disable=arguments-differ
                 "d",
                 "e",
                 int,
-                MeterProvider(resource=resource,).get_meter(__name__),
+                MeterProvider(resource=resource,).get_meter("name", "version"),
                 ("f",),
             ),
             [("g", "h")],
@@ -121,6 +122,9 @@ def test_translate_metrics(self):
                     ),
                     instrumentation_library_metrics=[
                         InstrumentationLibraryMetrics(
+                            instrumentation_library=InstrumentationLibrary(
+                                name="name", version="version",
+                            ),
                             metrics=[
                                 OTLPMetric(
                                     name="c",
@@ -145,7 +149,7 @@ def test_translate_metrics(self):
                                         is_monotonic=True,
                                     ),
                                 )
-                            ]
+                            ],
                         )
                     ],
                 )