From 03473b02fc9b64f13462b132d2ba0562c5365033 Mon Sep 17 00:00:00 2001 From: senw Date: Thu, 21 Apr 2022 04:12:11 +0000 Subject: [PATCH 1/2] fix(otlp): align with upstream pb definition --- .../proto/grpc/trace_exporter/__init__.py | 40 +++++++++---------- .../tests/test_otlp_trace_exporter.py | 38 +++++++++--------- .../http/trace_exporter/encoder/__init__.py | 28 ++++++------- .../tests/test_protobuf_encoder.py | 20 +++++----- 4 files changed, 63 insertions(+), 63 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py index 5cc8c885d7b..a061fa0fa7f 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py @@ -32,9 +32,9 @@ from opentelemetry.proto.collector.trace.v1.trace_service_pb2_grpc import ( TraceServiceStub, ) -from opentelemetry.proto.common.v1.common_pb2 import InstrumentationLibrary +from opentelemetry.proto.common.v1.common_pb2 import InstrumentationScope from opentelemetry.proto.trace.v1.trace_pb2 import ( - InstrumentationLibrarySpans, + ScopeSpans, ResourceSpans, ) from opentelemetry.proto.trace.v1.trace_pb2 import Span as CollectorSpan @@ -217,42 +217,42 @@ def _translate_data( ) -> ExportTraceServiceRequest: # pylint: disable=attribute-defined-outside-init - sdk_resource_instrumentation_library_spans = {} + sdk_resource_scope_spans = {} for sdk_span in data: - instrumentation_library_spans_map = ( - sdk_resource_instrumentation_library_spans.get( + scope_spans_map = ( + sdk_resource_scope_spans.get( sdk_span.resource, {} ) ) # If we haven't seen the Resource yet, add it to the map - if not instrumentation_library_spans_map: - sdk_resource_instrumentation_library_spans[ + if not scope_spans_map: + sdk_resource_scope_spans[ sdk_span.resource - ] = instrumentation_library_spans_map - instrumentation_library_spans = ( - instrumentation_library_spans_map.get( + ] = scope_spans_map + scope_spans = ( + scope_spans_map.get( sdk_span.instrumentation_info ) ) # If we haven't seen the InstrumentationInfo for this Resource yet, add it to the map - if not instrumentation_library_spans: + if not scope_spans: if sdk_span.instrumentation_info is not None: - instrumentation_library_spans_map[ + scope_spans_map[ sdk_span.instrumentation_info - ] = InstrumentationLibrarySpans( - instrumentation_library=InstrumentationLibrary( + ] = ScopeSpans( + scope=InstrumentationScope( name=sdk_span.instrumentation_info.name, version=sdk_span.instrumentation_info.version, ) ) else: # If no InstrumentationInfo, store in None key - instrumentation_library_spans_map[ + scope_spans_map[ sdk_span.instrumentation_info - ] = InstrumentationLibrarySpans() - instrumentation_library_spans = ( - instrumentation_library_spans_map.get( + ] = ScopeSpans() + scope_spans = ( + scope_spans_map.get( sdk_span.instrumentation_info ) ) @@ -289,13 +289,13 @@ def _translate_data( f"SPAN_KIND_{sdk_span.kind.name}", ) - instrumentation_library_spans.spans.append( + scope_spans.spans.append( CollectorSpan(**self._collector_kwargs) ) return ExportTraceServiceRequest( resource_spans=get_resource_data( - sdk_resource_instrumentation_library_spans, + sdk_resource_scope_spans, ResourceSpans, "spans", ) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py index 80011cafb0b..95822108fad 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py @@ -40,14 +40,14 @@ from opentelemetry.proto.common.v1.common_pb2 import ( AnyValue, ArrayValue, - InstrumentationLibrary, + InstrumentationScope, KeyValue, ) from opentelemetry.proto.resource.v1.resource_pb2 import ( Resource as OTLPResource, ) from opentelemetry.proto.trace.v1.trace_pb2 import ( - InstrumentationLibrarySpans, + ScopeSpans, ResourceSpans, ) from opentelemetry.proto.trace.v1.trace_pb2 import Span as OTLPSpan @@ -493,9 +493,9 @@ def test_translate_spans(self): ), ] ), - instrumentation_library_spans=[ - InstrumentationLibrarySpans( - instrumentation_library=InstrumentationLibrary( + scope_spans=[ + ScopeSpans( + scope=InstrumentationScope( name="name", version="version" ), spans=[ @@ -595,9 +595,9 @@ def test_translate_spans_multi(self): ), ] ), - instrumentation_library_spans=[ - InstrumentationLibrarySpans( - instrumentation_library=InstrumentationLibrary( + scope_spans=[ + ScopeSpans( + scope=InstrumentationScope( name="name", version="version" ), spans=[ @@ -677,8 +677,8 @@ def test_translate_spans_multi(self): ) ], ), - InstrumentationLibrarySpans( - instrumentation_library=InstrumentationLibrary( + ScopeSpans( + scope=InstrumentationScope( name="name2", version="version2" ), spans=[ @@ -717,9 +717,9 @@ def test_translate_spans_multi(self): ), ] ), - instrumentation_library_spans=[ - InstrumentationLibrarySpans( - instrumentation_library=InstrumentationLibrary( + scope_spans=[ + ScopeSpans( + scope=InstrumentationScope( name="name", version="version" ), spans=[ @@ -765,7 +765,7 @@ def _check_translated_status( ): status = ( translated.resource_spans[0] - .instrumentation_library_spans[0] + .scope_spans[0] .spans[0] .status ) @@ -861,28 +861,28 @@ def test_dropped_values(self): self.assertEqual( 1, translated.resource_spans[0] - .instrumentation_library_spans[0] + .scope_spans[0] .spans[0] .dropped_links_count, ) self.assertEqual( 2, translated.resource_spans[0] - .instrumentation_library_spans[0] + .scope_spans[0] .spans[0] .dropped_attributes_count, ) self.assertEqual( 3, translated.resource_spans[0] - .instrumentation_library_spans[0] + .scope_spans[0] .spans[0] .dropped_events_count, ) self.assertEqual( 2, translated.resource_spans[0] - .instrumentation_library_spans[0] + .scope_spans[0] .spans[0] .links[0] .dropped_attributes_count, @@ -890,7 +890,7 @@ def test_dropped_values(self): self.assertEqual( 2, translated.resource_spans[0] - .instrumentation_library_spans[0] + .scope_spans[0] .spans[0] .events[0] .dropped_attributes_count, diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/encoder/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/encoder/__init__.py index 24497d204df..e09d3f07486 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/encoder/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/encoder/__init__.py @@ -24,14 +24,14 @@ ArrayValue as PB2ArrayValue, ) from opentelemetry.proto.common.v1.common_pb2 import ( - InstrumentationLibrary as PB2InstrumentationLibrary, + InstrumentationScope as PB2InstrumentationScope, ) from opentelemetry.proto.common.v1.common_pb2 import KeyValue as PB2KeyValue from opentelemetry.proto.resource.v1.resource_pb2 import ( Resource as PB2Resource, ) from opentelemetry.proto.trace.v1.trace_pb2 import ( - InstrumentationLibrarySpans as PB2InstrumentationLibrarySpans, + ScopeSpans as PB2ScopeSpans, ) from opentelemetry.proto.trace.v1.trace_pb2 import ( ResourceSpans as PB2ResourceSpans, @@ -79,7 +79,7 @@ def _encode_resource_spans( # We need to inspect the spans and group + structure them as: # # Resource - # Instrumentation Library + # Scope Spans # Spans # # First loop organizes the SDK spans in this structure. Protobuf messages @@ -110,12 +110,12 @@ def _encode_resource_spans( pb2_resource_spans = [] for sdk_resource, sdk_instrumentations in sdk_resource_spans.items(): - instrumentation_library_spans = [] + scope_spans = [] for sdk_instrumentation, pb2_spans in sdk_instrumentations.items(): - instrumentation_library_spans.append( - PB2InstrumentationLibrarySpans( - instrumentation_library=( - _encode_instrumentation_library(sdk_instrumentation) + scope_spans.append( + PB2ScopeSpans( + scope=( + _encode_instrumentation_scope(sdk_instrumentation) ), spans=pb2_spans, ) @@ -123,7 +123,7 @@ def _encode_resource_spans( pb2_resource_spans.append( PB2ResourceSpans( resource=_encode_resource(sdk_resource), - instrumentation_library_spans=instrumentation_library_spans, + scope_spans=scope_spans, ) ) @@ -245,17 +245,17 @@ def _encode_resource(resource: Resource) -> PB2Resource: return pb2_resource -def _encode_instrumentation_library( +def _encode_instrumentation_scope( instrumentation_info: InstrumentationInfo, -) -> PB2InstrumentationLibrary: +) -> PB2InstrumentationScope: if instrumentation_info is None: - pb2_instrumentation_library = PB2InstrumentationLibrary() + pb2_instrumentation_scope = PB2InstrumentationScope() else: - pb2_instrumentation_library = PB2InstrumentationLibrary( + pb2_instrumentation_scope = PB2InstrumentationScope( name=instrumentation_info.name, version=instrumentation_info.version, ) - return pb2_instrumentation_library + return pb2_instrumentation_scope def _encode_value(value: Any) -> PB2AnyValue: diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_protobuf_encoder.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_protobuf_encoder.py index a6ebc051452..ffcd9ad639a 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_protobuf_encoder.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_protobuf_encoder.py @@ -29,14 +29,14 @@ ) from opentelemetry.proto.common.v1.common_pb2 import AnyValue as PB2AnyValue from opentelemetry.proto.common.v1.common_pb2 import ( - InstrumentationLibrary as PB2InstrumentationLibrary, + InstrumentationScope as PB2InstrumentationScope, ) from opentelemetry.proto.common.v1.common_pb2 import KeyValue as PB2KeyValue from opentelemetry.proto.resource.v1.resource_pb2 import ( Resource as PB2Resource, ) from opentelemetry.proto.trace.v1.trace_pb2 import ( - InstrumentationLibrarySpans as PB2InstrumentationLibrarySpans, + ScopeSpans as PB2ScopeSpans, ) from opentelemetry.proto.trace.v1.trace_pb2 import ( ResourceSpans as PB2ResourceSpans, @@ -178,9 +178,9 @@ def get_exhaustive_test_spans( resource_spans=[ PB2ResourceSpans( resource=PB2Resource(), - instrumentation_library_spans=[ - PB2InstrumentationLibrarySpans( - instrumentation_library=PB2InstrumentationLibrary(), + scope_spans=[ + PB2ScopeSpans( + scope=PB2InstrumentationScope(), spans=[ PB2SPan( trace_id=trace_id, @@ -274,8 +274,8 @@ def get_exhaustive_test_spans( ) ], ), - PB2InstrumentationLibrarySpans( - instrumentation_library=PB2InstrumentationLibrary( + PB2ScopeSpans( + scope=PB2InstrumentationScope( name="name", version="version", ), @@ -313,9 +313,9 @@ def get_exhaustive_test_spans( ) ] ), - instrumentation_library_spans=[ - PB2InstrumentationLibrarySpans( - instrumentation_library=PB2InstrumentationLibrary(), + scope_spans=[ + PB2ScopeSpans( + scope=PB2InstrumentationScope(), spans=[ PB2SPan( trace_id=trace_id, From 5c88ed5bf19fc54c7aeab3819f0575dbd534147e Mon Sep 17 00:00:00 2001 From: senw Date: Thu, 21 Apr 2022 04:18:39 +0000 Subject: [PATCH 2/2] chore(changelog): add CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 004e3598add..5784042e844 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 instruments to `NoOpCounter`, `NoOpHistogram`, `NoOpObservableCounter`, `NoOpObservableGauge`, `NoOpObservableUpDownCounter`, `NoOpUpDownCounter` ([#2616](https://github.com/open-telemetry/opentelemetry-python/pull/2616)) +- Fix `InstrumentationLibrary` naming change + ([#2632](https://github.com/open-telemetry/opentelemetry-python/pull/2632)) ## [1.11.0-0.30b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.11.0-0.30b0) - 2022-04-18