Repository: open-telemetry/opentelemetry-python

Issue:
OTLP Exporter should report instrumentation info
Currently the Python OTLP exporter does not export instrumentation information, other implementations do.


Discussion:

Resolving patch:
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
@@ -27,6 +27,7 @@
 from opentelemetry.proto.collector.trace.v1.trace_service_pb2_grpc import (
     TraceServiceStub,
 )
+from opentelemetry.proto.common.v1.common_pb2 import InstrumentationLibrary
 from opentelemetry.proto.trace.v1.trace_pb2 import (
     InstrumentationLibrarySpans,
     ResourceSpans,
@@ -168,9 +169,22 @@ def _translate_data(self, data) -> ExportTraceServiceRequest:
             if sdk_span.resource not in (
                 sdk_resource_instrumentation_library_spans.keys()
             ):
+                if sdk_span.instrumentation_info is not None:
+                    instrumentation_library_spans = InstrumentationLibrarySpans(
+                        instrumentation_library=InstrumentationLibrary(
+                            name=sdk_span.instrumentation_info.name,
+                            version=sdk_span.instrumentation_info.version,
+                        )
+                    )
+
+                else:
+                    instrumentation_library_spans = (
+                        InstrumentationLibrarySpans()
+                    )
+
                 sdk_resource_instrumentation_library_spans[
                     sdk_span.resource
-                ] = InstrumentationLibrarySpans()
+                ] = instrumentation_library_spans
 
             self._collector_span_kwargs = {}
 


Test patch:
diff --git a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_trace_exporter.py b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_trace_exporter.py
--- a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_trace_exporter.py
+++ b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_trace_exporter.py
@@ -30,7 +30,11 @@
     TraceServiceServicer,
     add_TraceServiceServicer_to_server,
 )
-from opentelemetry.proto.common.v1.common_pb2 import AnyValue, KeyValue
+from opentelemetry.proto.common.v1.common_pb2 import (
+    AnyValue,
+    InstrumentationLibrary,
+    KeyValue,
+)
 from opentelemetry.proto.resource.v1.resource_pb2 import (
     Resource as CollectorResource,
 )
@@ -46,6 +50,7 @@
     SimpleExportSpanProcessor,
     SpanExportResult,
 )
+from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
 from opentelemetry.trace import SpanKind
 
 
@@ -142,6 +147,9 @@ def setUp(self):
                     }
                 )
             ],
+            instrumentation_info=InstrumentationInfo(
+                name="name", version="version"
+            ),
         )
 
         self.span.start()
@@ -209,6 +217,9 @@ def test_translate_spans(self):
                     ),
                     instrumentation_library_spans=[
                         InstrumentationLibrarySpans(
+                            instrumentation_library=InstrumentationLibrary(
+                                name="name", version="version"
+                            ),
                             spans=[
                                 CollectorSpan(
                                     # pylint: disable=no-member
@@ -282,7 +293,7 @@ def test_translate_spans(self):
                                         )
                                     ],
                                 )
-                            ]
+                            ],
                         )
                     ],
                 ),