diff --git a/exporter/opentelemetry-exporter-otlp/CHANGELOG.md b/exporter/opentelemetry-exporter-otlp/CHANGELOG.md index ed6aee3b4c6..49e6d8c9410 100644 --- a/exporter/opentelemetry-exporter-otlp/CHANGELOG.md +++ b/exporter/opentelemetry-exporter-otlp/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Add instrumentation info to exported spans + ([#1095](https://github.com/open-telemetry/opentelemetry-python/pull/1095)) - Add metric OTLP exporter ([#835](https://github.com/open-telemetry/opentelemetry-python/pull/835)) 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 index 5a9a74a304f..fd1d8e235e4 100644 --- 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 = {} diff --git a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_trace_exporter.py b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_trace_exporter.py index a7f572323e0..06a3877b926 100644 --- 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): ) ], ) - ] + ], ) ], ),