diff --git a/CHANGELOG.md b/CHANGELOG.md index 004e3598add..412ff0f845b 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)) +- Deprecate InstrumentationLibraryInfo and Add InstrumentationScope + ([#2583](https://github.com/open-telemetry/opentelemetry-python/pull/2583)) ## [1.11.0-0.30b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.11.0-0.30b0) - 2022-04-18 diff --git a/exporter/opentelemetry-exporter-jaeger-proto-grpc/src/opentelemetry/exporter/jaeger/proto/grpc/translate/__init__.py b/exporter/opentelemetry-exporter-jaeger-proto-grpc/src/opentelemetry/exporter/jaeger/proto/grpc/translate/__init__.py index 3eb59755c96..ea1f17c00f6 100644 --- a/exporter/opentelemetry-exporter-jaeger-proto-grpc/src/opentelemetry/exporter/jaeger/proto/grpc/translate/__init__.py +++ b/exporter/opentelemetry-exporter-jaeger-proto-grpc/src/opentelemetry/exporter/jaeger/proto/grpc/translate/__init__.py @@ -35,6 +35,8 @@ NAME_KEY = "otel.library.name" VERSION_KEY = "otel.library.version" +_SCOPE_NAME_KEY = "otel.scope.name" +_SCOPE_VERSION_KEY = "otel.scope.version" def _nsec_to_usec_round(nsec: int) -> int: @@ -299,15 +301,22 @@ def _extract_tags( ) ) - # Instrumentation info KeyValues - if span.instrumentation_info: + # Instrumentation scope KeyValues + if span.instrumentation_scope: name = _get_string_key_value( - NAME_KEY, span.instrumentation_info.name + NAME_KEY, span.instrumentation_scope.name ) version = _get_string_key_value( - VERSION_KEY, span.instrumentation_info.version + VERSION_KEY, span.instrumentation_scope.version + ) + scope_name = _get_string_key_value( + _SCOPE_NAME_KEY, span.instrumentation_scope.name + ) + scope_version = _get_string_key_value( + _SCOPE_VERSION_KEY, span.instrumentation_scope.version ) translated.extend([name, version]) + translated.extend([scope_name, scope_version]) # Make sure to add "error" tag if span status is not OK if not span.status.is_ok: diff --git a/exporter/opentelemetry-exporter-jaeger-proto-grpc/tests/test_jaeger_exporter_protobuf.py b/exporter/opentelemetry-exporter-jaeger-proto-grpc/tests/test_jaeger_exporter_protobuf.py index 926bbff085e..6cc44195265 100644 --- a/exporter/opentelemetry-exporter-jaeger-proto-grpc/tests/test_jaeger_exporter_protobuf.py +++ b/exporter/opentelemetry-exporter-jaeger-proto-grpc/tests/test_jaeger_exporter_protobuf.py @@ -25,6 +25,8 @@ # pylint:disable=import-error from opentelemetry.exporter.jaeger.proto.grpc.gen import model_pb2 from opentelemetry.exporter.jaeger.proto.grpc.translate import ( + _SCOPE_NAME_KEY, + _SCOPE_VERSION_KEY, NAME_KEY, VERSION_KEY, Translate, @@ -39,7 +41,7 @@ from opentelemetry.sdk.resources import SERVICE_NAME, Resource from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import SpanExportResult -from opentelemetry.sdk.util.instrumentation import InstrumentationInfo +from opentelemetry.sdk.util.instrumentation import InstrumentationScope from opentelemetry.test.spantestutil import ( get_span_with_dropped_attributes_events_links, ) @@ -188,7 +190,7 @@ def test_translate_to_jaeger(self): context=other_context, parent=None, resource=Resource({}), - instrumentation_info=InstrumentationInfo( + instrumentation_scope=InstrumentationScope( name="name", version="version" ), ), @@ -391,6 +393,16 @@ def test_translate_to_jaeger(self): v_type=model_pb2.ValueType.STRING, v_str="version", ), + model_pb2.KeyValue( + key=_SCOPE_NAME_KEY, + v_type=model_pb2.ValueType.STRING, + v_str="name", + ), + model_pb2.KeyValue( + key=_SCOPE_VERSION_KEY, + v_type=model_pb2.ValueType.STRING, + v_str="version", + ), ], process=model_pb2.Process( service_name="svc", diff --git a/exporter/opentelemetry-exporter-jaeger-thrift/src/opentelemetry/exporter/jaeger/thrift/translate/__init__.py b/exporter/opentelemetry-exporter-jaeger-thrift/src/opentelemetry/exporter/jaeger/thrift/translate/__init__.py index 1649b000e91..922833fccaf 100644 --- a/exporter/opentelemetry-exporter-jaeger-thrift/src/opentelemetry/exporter/jaeger/thrift/translate/__init__.py +++ b/exporter/opentelemetry-exporter-jaeger-thrift/src/opentelemetry/exporter/jaeger/thrift/translate/__init__.py @@ -32,6 +32,8 @@ NAME_KEY = "otel.library.name" VERSION_KEY = "otel.library.version" +_SCOPE_NAME_KEY = "otel.scope.name" +_SCOPE_VERSION_KEY = "otel.scope.version" def _nsec_to_usec_round(nsec: int) -> int: @@ -220,12 +222,20 @@ def _extract_tags(self, span: ReadableSpan) -> Sequence[TCollector.Tag]: ) # Instrumentation info tags - if span.instrumentation_info: - name = _get_string_tag(NAME_KEY, span.instrumentation_info.name) + if span.instrumentation_scope: + name = _get_string_tag(NAME_KEY, span.instrumentation_scope.name) version = _get_string_tag( - VERSION_KEY, span.instrumentation_info.version + VERSION_KEY, span.instrumentation_scope.version ) + scope_name = _get_string_tag( + _SCOPE_NAME_KEY, span.instrumentation_scope.name + ) + scope_version = _get_string_tag( + _SCOPE_VERSION_KEY, span.instrumentation_scope.version + ) + translated.extend([name, version]) + translated.extend([scope_name, scope_version]) # Make sure to add "error" tag if span status is not OK if not span.status.is_ok: diff --git a/exporter/opentelemetry-exporter-jaeger-thrift/tests/test_jaeger_exporter_thrift.py b/exporter/opentelemetry-exporter-jaeger-thrift/tests/test_jaeger_exporter_thrift.py index 8bd3e3e359d..8d9f2a42472 100644 --- a/exporter/opentelemetry-exporter-jaeger-thrift/tests/test_jaeger_exporter_thrift.py +++ b/exporter/opentelemetry-exporter-jaeger-thrift/tests/test_jaeger_exporter_thrift.py @@ -36,7 +36,7 @@ ) from opentelemetry.sdk.resources import SERVICE_NAME from opentelemetry.sdk.trace import Resource, TracerProvider -from opentelemetry.sdk.util.instrumentation import InstrumentationInfo +from opentelemetry.sdk.util.instrumentation import InstrumentationScope from opentelemetry.test.globals_test import TraceGlobalsTest from opentelemetry.test.spantestutil import ( get_span_with_dropped_attributes_events_links, @@ -303,7 +303,7 @@ def test_translate_to_jaeger(self): context=other_context, parent=None, resource=Resource({}), - instrumentation_info=InstrumentationInfo( + instrumentation_scope=InstrumentationScope( name="name", version="version" ), ), @@ -461,6 +461,16 @@ def test_translate_to_jaeger(self): vType=jaeger.TagType.STRING, vStr="version", ), + jaeger.Tag( + key=jaeger_exporter.translate._SCOPE_NAME_KEY, + vType=jaeger.TagType.STRING, + vStr="name", + ), + jaeger.Tag( + key=jaeger_exporter.translate._SCOPE_VERSION_KEY, + vType=jaeger.TagType.STRING, + vStr="version", + ), ], ), ] diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py index 522d2de8b50..51433d57409 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py @@ -24,9 +24,9 @@ from opentelemetry.proto.collector.logs.v1.logs_service_pb2_grpc import ( LogsServiceStub, ) -from opentelemetry.proto.common.v1.common_pb2 import InstrumentationLibrary +from opentelemetry.proto.common.v1.common_pb2 import InstrumentationScope from opentelemetry.proto.logs.v1.logs_pb2 import ( - InstrumentationLibraryLogs, + ScopeLogs, ResourceLogs, ) from opentelemetry.proto.logs.v1.logs_pb2 import LogRecord as PB2LogRecord @@ -96,44 +96,30 @@ def _translate_data( ) -> ExportLogsServiceRequest: # pylint: disable=attribute-defined-outside-init - sdk_resource_instrumentation_library_logs = {} + sdk_resource_scope_logs = {} for log_data in data: resource = log_data.log_record.resource - instrumentation_library_logs_map = ( - sdk_resource_instrumentation_library_logs.get(resource, {}) - ) - if not instrumentation_library_logs_map: - sdk_resource_instrumentation_library_logs[ - resource - ] = instrumentation_library_logs_map - - instrumentation_library_logs = ( - instrumentation_library_logs_map.get( - log_data.instrumentation_info - ) - ) - if not instrumentation_library_logs: - if log_data.instrumentation_info is not None: - instrumentation_library_logs_map[ - log_data.instrumentation_info - ] = InstrumentationLibraryLogs( - instrumentation_library=InstrumentationLibrary( - name=log_data.instrumentation_info.name, - version=log_data.instrumentation_info.version, + scope_logs_map = sdk_resource_scope_logs.get(resource, {}) + if not scope_logs_map: + sdk_resource_scope_logs[resource] = scope_logs_map + + scope_logs = scope_logs_map.get(log_data.instrumentation_scope) + if not scope_logs: + if log_data.instrumentation_scope is not None: + scope_logs_map[log_data.instrumentation_scope] = ScopeLogs( + scope=InstrumentationScope( + name=log_data.instrumentation_scope.name, + version=log_data.instrumentation_scope.version, ) ) else: - instrumentation_library_logs_map[ - log_data.instrumentation_info - ] = InstrumentationLibraryLogs() - - instrumentation_library_logs = ( - instrumentation_library_logs_map.get( - log_data.instrumentation_info - ) - ) + scope_logs_map[ + log_data.instrumentation_scope + ] = ScopeLogs() + + scope_logs = scope_logs_map.get(log_data.instrumentation_scope) self._collector_kwargs = {} @@ -151,13 +137,13 @@ def _translate_data( "severity_number" ] = log_data.log_record.severity_number.value - instrumentation_library_logs.log_records.append( + scope_logs.log_records.append( PB2LogRecord(**self._collector_kwargs) ) return ExportLogsServiceRequest( resource_logs=get_resource_data( - sdk_resource_instrumentation_library_logs, + sdk_resource_scope_logs, ResourceLogs, "logs", ) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_metric_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_metric_exporter/__init__.py index 92aba2958c2..1ad5cc4d808 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_metric_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_metric_exporter/__init__.py @@ -25,7 +25,7 @@ from opentelemetry.proto.collector.metrics.v1.metrics_service_pb2_grpc import ( MetricsServiceStub, ) -from opentelemetry.proto.common.v1.common_pb2 import InstrumentationLibrary +from opentelemetry.proto.common.v1.common_pb2 import InstrumentationScope from opentelemetry.proto.metrics.v1 import metrics_pb2 as pb2 from opentelemetry.sdk.environment_variables import ( OTEL_EXPORTER_OTLP_METRICS_INSECURE, @@ -81,40 +81,30 @@ def __init__( def _translate_data( self, data: Sequence[Metric] ) -> ExportMetricsServiceRequest: - sdk_resource_instrumentation_library_metrics = {} + sdk_resource_scope_metrics = {} for metric in data: resource = metric.resource - instrumentation_library_map = ( - sdk_resource_instrumentation_library_metrics.get(resource, {}) - ) - if not instrumentation_library_map: - sdk_resource_instrumentation_library_metrics[ - resource - ] = instrumentation_library_map - - instrumentation_library_metrics = instrumentation_library_map.get( - metric.instrumentation_info - ) - - if not instrumentation_library_metrics: - if metric.instrumentation_info is not None: - instrumentation_library_map[ - metric.instrumentation_info - ] = pb2.InstrumentationLibraryMetrics( - instrumentation_library=InstrumentationLibrary( - name=metric.instrumentation_info.name, - version=metric.instrumentation_info.version, + scope_map = sdk_resource_scope_metrics.get(resource, {}) + if not scope_map: + sdk_resource_scope_metrics[resource] = scope_map + + scope_metrics = scope_map.get(metric.instrumentation_scope) + + if not scope_metrics: + if metric.instrumentation_scope is not None: + scope_map[metric.instrumentation_scope] = pb2.ScopeMetrics( + scope=InstrumentationScope( + name=metric.instrumentation_scope.name, + version=metric.instrumentation_scope.version, ) ) else: - instrumentation_library_map[ - metric.instrumentation_info - ] = pb2.InstrumentationLibraryMetrics() + scope_map[ + metric.instrumentation_scope + ] = pb2.ScopeMetrics() - instrumentation_library_metrics = instrumentation_library_map.get( - metric.instrumentation_info - ) + scope_metrics = scope_map.get(metric.instrumentation_scope) pbmetric = pb2.Metric( name=metric.name, @@ -167,12 +157,12 @@ def _translate_data( logger.warn("unsupported datapoint type %s", metric.point) continue - instrumentation_library_metrics.metrics.append( + scope_metrics.metrics.append( pbmetric, ) return ExportMetricsServiceRequest( resource_metrics=get_resource_data( - sdk_resource_instrumentation_library_metrics, + sdk_resource_scope_metrics, pb2.ResourceMetrics, "metrics", ) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py index 5c098e8fe04..b965061c5cb 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py @@ -126,9 +126,7 @@ def _translate_key_values(key: str, value: Any) -> KeyValue: def get_resource_data( - sdk_resource_instrumentation_library_data: Dict[ - SDKResource, ResourceDataT - ], + sdk_resource_scope_data: Dict[SDKResource, ResourceDataT], resource_class: Callable[..., TypingResourceT], name: str, ) -> List[TypingResourceT]: @@ -137,8 +135,8 @@ def get_resource_data( for ( sdk_resource, - instrumentation_library_data, - ) in sdk_resource_instrumentation_library_data.items(): + scope_data, + ) in sdk_resource_scope_data.items(): collector_resource = Resource() @@ -156,9 +154,7 @@ def get_resource_data( resource_class( **{ "resource": collector_resource, - "instrumentation_library_{}".format( - name - ): instrumentation_library_data.values(), + "scope_{}".format(name): scope_data.values(), } ) ) 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..084a5d93b14 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,45 +217,33 @@ 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( - sdk_span.resource, {} - ) + 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[ - sdk_span.resource - ] = instrumentation_library_spans_map - instrumentation_library_spans = ( - instrumentation_library_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 sdk_span.instrumentation_info is not None: - instrumentation_library_spans_map[ - sdk_span.instrumentation_info - ] = InstrumentationLibrarySpans( - instrumentation_library=InstrumentationLibrary( - name=sdk_span.instrumentation_info.name, - version=sdk_span.instrumentation_info.version, + if not scope_spans_map: + sdk_resource_scope_spans[sdk_span.resource] = scope_spans_map + scope_spans = scope_spans_map.get(sdk_span.instrumentation_scope) + # If we haven't seen the InstrumentationScope for this Resource yet, add it to the map + if not scope_spans: + if sdk_span.instrumentation_scope is not None: + scope_spans_map[ + sdk_span.instrumentation_scope + ] = ScopeSpans( + scope=InstrumentationScope( + name=sdk_span.instrumentation_scope.name, + version=sdk_span.instrumentation_scope.version, ) ) else: - # If no InstrumentationInfo, store in None key - instrumentation_library_spans_map[ - sdk_span.instrumentation_info - ] = InstrumentationLibrarySpans() - instrumentation_library_spans = ( - instrumentation_library_spans_map.get( - sdk_span.instrumentation_info - ) - ) + # If no InstrumentationScope, store in None key + scope_spans_map[ + sdk_span.instrumentation_scope + ] = ScopeSpans() + scope_spans = scope_spans_map.get(sdk_span.instrumentation_scope) self._collector_kwargs = {} self._translate_name(sdk_span) @@ -289,13 +277,11 @@ def _translate_data( f"SPAN_KIND_{sdk_span.kind.name}", ) - instrumentation_library_spans.spans.append( - CollectorSpan(**self._collector_kwargs) - ) + 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/logs/test_otlp_logs_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/logs/test_otlp_logs_exporter.py index 5e3a54fbcb0..4ee8f6a0b37 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/logs/test_otlp_logs_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/logs/test_otlp_logs_exporter.py @@ -33,14 +33,13 @@ LogsServiceServicer, add_LogsServiceServicer_to_server, ) +from opentelemetry.proto.common.v1.common_pb2 import AnyValue from opentelemetry.proto.common.v1.common_pb2 import ( - AnyValue, - InstrumentationLibrary, - KeyValue, + InstrumentationScope as PB2InstrumentationScope, ) -from opentelemetry.proto.logs.v1.logs_pb2 import InstrumentationLibraryLogs +from opentelemetry.proto.common.v1.common_pb2 import KeyValue from opentelemetry.proto.logs.v1.logs_pb2 import LogRecord as PB2LogRecord -from opentelemetry.proto.logs.v1.logs_pb2 import ResourceLogs +from opentelemetry.proto.logs.v1.logs_pb2 import ResourceLogs, ScopeLogs from opentelemetry.proto.resource.v1.resource_pb2 import ( Resource as OTLPResource, ) @@ -50,7 +49,7 @@ SeverityNumber as SDKSeverityNumber, ) from opentelemetry.sdk.resources import Resource as SDKResource -from opentelemetry.sdk.util.instrumentation import InstrumentationInfo +from opentelemetry.sdk.util.instrumentation import InstrumentationScope from opentelemetry.trace import TraceFlags @@ -123,7 +122,7 @@ def setUp(self): resource=SDKResource({"key": "value"}), attributes={"a": 1, "b": "c"}, ), - instrumentation_info=InstrumentationInfo( + instrumentation_scope=InstrumentationScope( "first_name", "first_version" ), ) @@ -139,7 +138,7 @@ def setUp(self): resource=SDKResource({"key": "value"}), attributes={"custom_attr": [1, 2, 3]}, ), - instrumentation_info=InstrumentationInfo( + instrumentation_scope=InstrumentationScope( "second_name", "second_version" ), ) @@ -154,7 +153,7 @@ def setUp(self): body="Mumbai, Boil water before drinking", resource=SDKResource({"service": "myapp"}), ), - instrumentation_info=InstrumentationInfo( + instrumentation_scope=InstrumentationScope( "third_name", "third_version" ), ) @@ -304,9 +303,9 @@ def test_translate_log_data(self): ), ] ), - instrumentation_library_logs=[ - InstrumentationLibraryLogs( - instrumentation_library=InstrumentationLibrary( + scope_logs=[ + ScopeLogs( + scope=PB2InstrumentationScope( name="first_name", version="first_version" ), log_records=[ @@ -363,9 +362,9 @@ def test_translate_multiple_logs(self): ), ] ), - instrumentation_library_logs=[ - InstrumentationLibraryLogs( - instrumentation_library=InstrumentationLibrary( + scope_logs=[ + ScopeLogs( + scope=PB2InstrumentationScope( name="first_name", version="first_version" ), log_records=[ @@ -401,8 +400,8 @@ def test_translate_multiple_logs(self): ) ], ), - InstrumentationLibraryLogs( - instrumentation_library=InstrumentationLibrary( + ScopeLogs( + scope=PB2InstrumentationScope( name="second_name", version="second_version" ), log_records=[ @@ -445,9 +444,9 @@ def test_translate_multiple_logs(self): ), ] ), - instrumentation_library_logs=[ - InstrumentationLibraryLogs( - instrumentation_library=InstrumentationLibrary( + scope_logs=[ + ScopeLogs( + scope=PB2InstrumentationScope( name="third_name", version="third_version" ), log_records=[ diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/metrics/test_otlp_metrics_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/metrics/test_otlp_metrics_exporter.py index 4a171b79867..af5d39ff597 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/metrics/test_otlp_metrics_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/metrics/test_otlp_metrics_exporter.py @@ -33,7 +33,7 @@ ) from opentelemetry.proto.common.v1.common_pb2 import ( AnyValue, - InstrumentationLibrary, + InstrumentationScope, KeyValue, ) from opentelemetry.proto.metrics.v1 import metrics_pb2 as pb2 @@ -293,9 +293,9 @@ def test_translate_sum_int(self): ), ] ), - instrumentation_library_metrics=[ - pb2.InstrumentationLibraryMetrics( - instrumentation_library=InstrumentationLibrary( + scope_metrics=[ + pb2.ScopeMetrics( + scope=InstrumentationScope( name="first_name", version="first_version" ), metrics=[ @@ -351,9 +351,9 @@ def test_translate_sum_double(self): ), ] ), - instrumentation_library_metrics=[ - pb2.InstrumentationLibraryMetrics( - instrumentation_library=InstrumentationLibrary( + scope_metrics=[ + pb2.ScopeMetrics( + scope=InstrumentationScope( name="first_name", version="first_version" ), metrics=[ @@ -409,9 +409,9 @@ def test_translate_gauge_int(self): ), ] ), - instrumentation_library_metrics=[ - pb2.InstrumentationLibraryMetrics( - instrumentation_library=InstrumentationLibrary( + scope_metrics=[ + pb2.ScopeMetrics( + scope=InstrumentationScope( name="first_name", version="first_version" ), metrics=[ @@ -464,9 +464,9 @@ def test_translate_gauge_double(self): ), ] ), - instrumentation_library_metrics=[ - pb2.InstrumentationLibraryMetrics( - instrumentation_library=InstrumentationLibrary( + scope_metrics=[ + pb2.ScopeMetrics( + scope=InstrumentationScope( name="first_name", version="first_version" ), metrics=[ @@ -519,9 +519,9 @@ def test_translate_histogram(self): ), ] ), - instrumentation_library_metrics=[ - pb2.InstrumentationLibraryMetrics( - instrumentation_library=InstrumentationLibrary( + scope_metrics=[ + pb2.ScopeMetrics( + scope=InstrumentationScope( name="first_name", version="first_version" ), metrics=[ 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..3d836729011 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 @@ -37,19 +37,15 @@ TraceServiceServicer, add_TraceServiceServicer_to_server, ) +from opentelemetry.proto.common.v1.common_pb2 import AnyValue, ArrayValue from opentelemetry.proto.common.v1.common_pb2 import ( - AnyValue, - ArrayValue, - InstrumentationLibrary, - KeyValue, + InstrumentationScope as PB2InstrumentationScope, ) +from opentelemetry.proto.common.v1.common_pb2 import KeyValue from opentelemetry.proto.resource.v1.resource_pb2 import ( Resource as OTLPResource, ) -from opentelemetry.proto.trace.v1.trace_pb2 import ( - InstrumentationLibrarySpans, - ResourceSpans, -) +from opentelemetry.proto.trace.v1.trace_pb2 import ResourceSpans, ScopeSpans from opentelemetry.proto.trace.v1.trace_pb2 import Span as OTLPSpan from opentelemetry.proto.trace.v1.trace_pb2 import Status from opentelemetry.sdk.environment_variables import ( @@ -69,7 +65,7 @@ SimpleSpanProcessor, SpanExportResult, ) -from opentelemetry.sdk.util.instrumentation import InstrumentationInfo +from opentelemetry.sdk.util.instrumentation import InstrumentationScope from opentelemetry.test.spantestutil import ( get_span_with_dropped_attributes_events_links, ) @@ -174,7 +170,7 @@ def setUp(self): } ) ], - instrumentation_info=InstrumentationInfo( + instrumentation_scope=InstrumentationScope( name="name", version="version" ), ) @@ -190,7 +186,7 @@ def setUp(self): ), resource=SDKResource(OrderedDict([("a", 2), ("b", False)])), parent=Mock(**{"span_id": 12345}), - instrumentation_info=InstrumentationInfo( + instrumentation_scope=InstrumentationScope( name="name", version="version" ), ) @@ -206,7 +202,7 @@ def setUp(self): ), resource=SDKResource(OrderedDict([("a", 1), ("b", False)])), parent=Mock(**{"span_id": 12345}), - instrumentation_info=InstrumentationInfo( + instrumentation_scope=InstrumentationScope( name="name2", version="version2" ), ) @@ -493,9 +489,9 @@ def test_translate_spans(self): ), ] ), - instrumentation_library_spans=[ - InstrumentationLibrarySpans( - instrumentation_library=InstrumentationLibrary( + scope_spans=[ + ScopeSpans( + scope=PB2InstrumentationScope( name="name", version="version" ), spans=[ @@ -595,9 +591,9 @@ def test_translate_spans_multi(self): ), ] ), - instrumentation_library_spans=[ - InstrumentationLibrarySpans( - instrumentation_library=InstrumentationLibrary( + scope_spans=[ + ScopeSpans( + scope=PB2InstrumentationScope( name="name", version="version" ), spans=[ @@ -677,8 +673,8 @@ def test_translate_spans_multi(self): ) ], ), - InstrumentationLibrarySpans( - instrumentation_library=InstrumentationLibrary( + ScopeSpans( + scope=PB2InstrumentationScope( name="name2", version="version2" ), spans=[ @@ -717,9 +713,9 @@ def test_translate_spans_multi(self): ), ] ), - instrumentation_library_spans=[ - InstrumentationLibrarySpans( - instrumentation_library=InstrumentationLibrary( + scope_spans=[ + ScopeSpans( + scope=PB2InstrumentationScope( name="name", version="version" ), spans=[ @@ -763,12 +759,7 @@ def _check_translated_status( translated: ExportTraceServiceRequest, code_expected: Status, ): - status = ( - translated.resource_spans[0] - .instrumentation_library_spans[0] - .spans[0] - .status - ) + status = translated.resource_spans[0].scope_spans[0].spans[0].status self.assertEqual( status.code, @@ -861,28 +852,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 +881,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, @@ -908,7 +899,7 @@ def _create_span_with_status(status: SDKStatus): } ), parent=Mock(**{"span_id": 12345}), - instrumentation_info=InstrumentationInfo( + instrumentation_scope=InstrumentationScope( name="name", version="version" ), ) 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..fc0d9608ef2 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, @@ -39,7 +39,7 @@ from opentelemetry.proto.trace.v1.trace_pb2 import Span as PB2SPan from opentelemetry.proto.trace.v1.trace_pb2 import Status as PB2Status from opentelemetry.sdk.trace import Event -from opentelemetry.sdk.util.instrumentation import InstrumentationInfo +from opentelemetry.sdk.util.instrumentation import InstrumentationScope from opentelemetry.sdk.trace import Resource from opentelemetry.sdk.trace import Span as SDKSpan from opentelemetry.trace import Link @@ -91,7 +91,7 @@ def _encode_resource_spans( for sdk_span in sdk_spans: sdk_resource = sdk_span.resource - sdk_instrumentation = sdk_span.instrumentation_info or None + sdk_instrumentation = sdk_span.instrumentation_scope or None pb2_span = _encode_span(sdk_span) if sdk_resource not in sdk_resource_spans.keys(): @@ -110,20 +110,18 @@ 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, ) ) pb2_resource_spans.append( PB2ResourceSpans( resource=_encode_resource(sdk_resource), - instrumentation_library_spans=instrumentation_library_spans, + scope_spans=scope_spans, ) ) @@ -245,17 +243,17 @@ def _encode_resource(resource: Resource) -> PB2Resource: return pb2_resource -def _encode_instrumentation_library( - instrumentation_info: InstrumentationInfo, -) -> PB2InstrumentationLibrary: - if instrumentation_info is None: - pb2_instrumentation_library = PB2InstrumentationLibrary() +def _encode_instrumentation_scope( + instrumentation_scope: InstrumentationScope, +) -> PB2InstrumentationScope: + if instrumentation_scope is None: + pb2_instrumentation_scope = PB2InstrumentationScope() else: - pb2_instrumentation_library = PB2InstrumentationLibrary( - name=instrumentation_info.name, - version=instrumentation_info.version, + pb2_instrumentation_scope = PB2InstrumentationScope( + name=instrumentation_scope.name, + version=instrumentation_scope.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..b3718623c18 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,18 +29,16 @@ ) 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, -) from opentelemetry.proto.trace.v1.trace_pb2 import ( ResourceSpans as PB2ResourceSpans, ) +from opentelemetry.proto.trace.v1.trace_pb2 import ScopeSpans as PB2ScopeSpans from opentelemetry.proto.trace.v1.trace_pb2 import Span as PB2SPan from opentelemetry.proto.trace.v1.trace_pb2 import Status as PB2Status from opentelemetry.sdk.trace import Event as SDKEvent @@ -48,7 +46,7 @@ from opentelemetry.sdk.trace import SpanContext as SDKSpanContext from opentelemetry.sdk.trace import _Span as SDKSpan from opentelemetry.sdk.util.instrumentation import ( - InstrumentationInfo as SDKInstrumentationInfo, + InstrumentationScope as SDKInstrumentationScope, ) from opentelemetry.trace import Link as SDKLink from opentelemetry.trace import SpanKind as SDKSpanKind @@ -158,7 +156,7 @@ def get_exhaustive_otel_span_list() -> List[SDKSpan]: context=other_context, parent=None, resource=SDKResource({}), - instrumentation_info=SDKInstrumentationInfo( + instrumentation_scope=SDKInstrumentationScope( name="name", version="version" ), ) @@ -178,9 +176,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 +272,8 @@ def get_exhaustive_test_spans( ) ], ), - PB2InstrumentationLibrarySpans( - instrumentation_library=PB2InstrumentationLibrary( + PB2ScopeSpans( + scope=PB2InstrumentationScope( name="name", version="version", ), @@ -313,9 +311,9 @@ def get_exhaustive_test_spans( ) ] ), - instrumentation_library_spans=[ - PB2InstrumentationLibrarySpans( - instrumentation_library=PB2InstrumentationLibrary(), + scope_spans=[ + PB2ScopeSpans( + scope=PB2InstrumentationScope(), spans=[ PB2SPan( trace_id=trace_id, diff --git a/exporter/opentelemetry-exporter-zipkin-json/src/opentelemetry/exporter/zipkin/encoder/__init__.py b/exporter/opentelemetry-exporter-zipkin-json/src/opentelemetry/exporter/zipkin/encoder/__init__.py index 5353a896cf8..bb90daa37c2 100644 --- a/exporter/opentelemetry-exporter-zipkin-json/src/opentelemetry/exporter/zipkin/encoder/__init__.py +++ b/exporter/opentelemetry-exporter-zipkin-json/src/opentelemetry/exporter/zipkin/encoder/__init__.py @@ -38,6 +38,8 @@ DEFAULT_MAX_TAG_VALUE_LENGTH = 128 NAME_KEY = "otel.library.name" VERSION_KEY = "otel.library.version" +_SCOPE_NAME_KEY = "otel.scope.name" +_SCOPE_VERSION_KEY = "otel.scope.version" logger = logging.getLogger(__name__) @@ -196,11 +198,13 @@ def _extract_tags_from_span(self, span: Span) -> Dict[str, str]: tags = self._extract_tags_from_dict(span.attributes) if span.resource: tags.update(self._extract_tags_from_dict(span.resource.attributes)) - if span.instrumentation_info is not None: + if span.instrumentation_scope is not None: tags.update( { - NAME_KEY: span.instrumentation_info.name, - VERSION_KEY: span.instrumentation_info.version, + NAME_KEY: span.instrumentation_scope.name, + VERSION_KEY: span.instrumentation_scope.version, + _SCOPE_NAME_KEY: span.instrumentation_scope.name, + _SCOPE_VERSION_KEY: span.instrumentation_scope.version, } ) if span.status.status_code is not StatusCode.UNSET: diff --git a/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/common_tests.py b/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/common_tests.py index 8eaa5b1563b..aae4b3bb236 100644 --- a/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/common_tests.py +++ b/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/common_tests.py @@ -24,7 +24,7 @@ ) from opentelemetry.exporter.zipkin.node_endpoint import NodeEndpoint from opentelemetry.sdk import trace -from opentelemetry.sdk.util.instrumentation import InstrumentationInfo +from opentelemetry.sdk.util.instrumentation import InstrumentationScope from opentelemetry.trace import TraceFlags from opentelemetry.trace.status import Status, StatusCode @@ -417,7 +417,7 @@ def get_exhaustive_otel_span_list() -> List[trace._Span]: context=other_context, parent=None, resource=trace.Resource({}), - instrumentation_info=InstrumentationInfo( + instrumentation_scope=InstrumentationScope( name="name", version="version" ), ) diff --git a/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/test_v1_json.py b/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/test_v1_json.py index b099040acc9..59a750eb51f 100644 --- a/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/test_v1_json.py +++ b/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/test_v1_json.py @@ -14,7 +14,12 @@ import json from opentelemetry import trace as trace_api -from opentelemetry.exporter.zipkin.encoder import NAME_KEY, VERSION_KEY +from opentelemetry.exporter.zipkin.encoder import ( + _SCOPE_NAME_KEY, + _SCOPE_VERSION_KEY, + NAME_KEY, + VERSION_KEY, +) from opentelemetry.exporter.zipkin.json.v1 import JsonV1Encoder from opentelemetry.exporter.zipkin.node_endpoint import NodeEndpoint from opentelemetry.sdk import trace @@ -164,6 +169,16 @@ def test_encode(self): "value": "version", "endpoint": local_endpoint, }, + { + "key": _SCOPE_NAME_KEY, + "value": "name", + "endpoint": local_endpoint, + }, + { + "key": _SCOPE_VERSION_KEY, + "value": "version", + "endpoint": local_endpoint, + }, ], }, ] diff --git a/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/test_v2_json.py b/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/test_v2_json.py index 9ceb9383fd6..85cc91a0d9d 100644 --- a/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/test_v2_json.py +++ b/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/test_v2_json.py @@ -14,7 +14,12 @@ import json from opentelemetry import trace as trace_api -from opentelemetry.exporter.zipkin.encoder import NAME_KEY, VERSION_KEY +from opentelemetry.exporter.zipkin.encoder import ( + _SCOPE_NAME_KEY, + _SCOPE_VERSION_KEY, + NAME_KEY, + VERSION_KEY, +) from opentelemetry.exporter.zipkin.json.v2 import JsonV2Encoder from opentelemetry.exporter.zipkin.node_endpoint import NodeEndpoint from opentelemetry.sdk import trace @@ -124,7 +129,12 @@ def test_encode(self): - (otel_spans[3].start_time // 10**3), "localEndpoint": local_endpoint, "kind": span_kind, - "tags": {NAME_KEY: "name", VERSION_KEY: "version"}, + "tags": { + NAME_KEY: "name", + VERSION_KEY: "version", + _SCOPE_NAME_KEY: "name", + _SCOPE_VERSION_KEY: "version", + }, }, ] diff --git a/exporter/opentelemetry-exporter-zipkin-proto-http/tests/encoder/common_tests.py b/exporter/opentelemetry-exporter-zipkin-proto-http/tests/encoder/common_tests.py index 8eaa5b1563b..aae4b3bb236 100644 --- a/exporter/opentelemetry-exporter-zipkin-proto-http/tests/encoder/common_tests.py +++ b/exporter/opentelemetry-exporter-zipkin-proto-http/tests/encoder/common_tests.py @@ -24,7 +24,7 @@ ) from opentelemetry.exporter.zipkin.node_endpoint import NodeEndpoint from opentelemetry.sdk import trace -from opentelemetry.sdk.util.instrumentation import InstrumentationInfo +from opentelemetry.sdk.util.instrumentation import InstrumentationScope from opentelemetry.trace import TraceFlags from opentelemetry.trace.status import Status, StatusCode @@ -417,7 +417,7 @@ def get_exhaustive_otel_span_list() -> List[trace._Span]: context=other_context, parent=None, resource=trace.Resource({}), - instrumentation_info=InstrumentationInfo( + instrumentation_scope=InstrumentationScope( name="name", version="version" ), ) diff --git a/exporter/opentelemetry-exporter-zipkin-proto-http/tests/encoder/test_v2_protobuf.py b/exporter/opentelemetry-exporter-zipkin-proto-http/tests/encoder/test_v2_protobuf.py index 4ba1ea220a2..8ce61a92a1d 100644 --- a/exporter/opentelemetry-exporter-zipkin-proto-http/tests/encoder/test_v2_protobuf.py +++ b/exporter/opentelemetry-exporter-zipkin-proto-http/tests/encoder/test_v2_protobuf.py @@ -14,7 +14,12 @@ import ipaddress import json -from opentelemetry.exporter.zipkin.encoder import NAME_KEY, VERSION_KEY +from opentelemetry.exporter.zipkin.encoder import ( + _SCOPE_NAME_KEY, + _SCOPE_VERSION_KEY, + NAME_KEY, + VERSION_KEY, +) from opentelemetry.exporter.zipkin.node_endpoint import NodeEndpoint from opentelemetry.exporter.zipkin.proto.http.v2 import ProtobufEncoder from opentelemetry.exporter.zipkin.proto.http.v2.gen import zipkin_pb2 @@ -183,7 +188,12 @@ def test_encode(self): ), local_endpoint=local_endpoint, kind=span_kind, - tags={NAME_KEY: "name", VERSION_KEY: "version"}, + tags={ + NAME_KEY: "name", + VERSION_KEY: "version", + _SCOPE_NAME_KEY: "name", + _SCOPE_VERSION_KEY: "version", + }, debug=False, ), ], diff --git a/opentelemetry-api/src/opentelemetry/trace/__init__.py b/opentelemetry-api/src/opentelemetry/trace/__init__.py index cc5152ce831..53eb0e96db4 100644 --- a/opentelemetry-api/src/opentelemetry/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/trace/__init__.py @@ -202,7 +202,8 @@ def get_tracer( vs. a functional tracer). Args: - instrumenting_module_name: The name of the instrumenting module. + instrumenting_module_name: The uniquely identifiable name for instrumentaion + scope, such as instrumentation library, package, module or class name. ``__name__`` may not be used as this can result in different tracer names if the tracers are in different files. It is better to use a fixed string that can be imported where diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py index c6887a67189..ae75df1d021 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py @@ -28,7 +28,7 @@ ) from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.util import ns_to_iso_str -from opentelemetry.sdk.util.instrumentation import InstrumentationInfo +from opentelemetry.sdk.util.instrumentation import InstrumentationScope from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.trace import ( format_span_id, @@ -107,10 +107,10 @@ class LogData: def __init__( self, log_record: LogRecord, - instrumentation_info: InstrumentationInfo, + instrumentation_scope: InstrumentationScope, ): self.log_record = log_record - self.instrumentation_info = instrumentation_info + self.instrumentation_scope = instrumentation_scope class LogProcessor(abc.ABC): @@ -379,11 +379,11 @@ def __init__( multi_log_processor: Union[ SynchronousMultiLogProcessor, ConcurrentMultiLogProcessor ], - instrumentation_info: InstrumentationInfo, + instrumentation_scope: InstrumentationScope, ): self._resource = resource self._multi_log_processor = multi_log_processor - self._instrumentation_info = instrumentation_info + self._instrumentation_scope = instrumentation_scope @property def resource(self): @@ -393,7 +393,7 @@ def emit(self, record: LogRecord): """Emits the :class:`LogData` by associating :class:`LogRecord` and instrumentation info. """ - log_data = LogData(record, self._instrumentation_info) + log_data = LogData(record, self._instrumentation_scope) self._multi_log_processor.emit(log_data) # TODO: Should this flush everything in pipeline? @@ -432,7 +432,7 @@ def get_log_emitter( return LogEmitter( self._resource, self._multi_log_processor, - InstrumentationInfo( + InstrumentationScope( instrumenting_module_name, instrumenting_module_verison ), ) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py index 29e4972d803..afa445b3590 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py @@ -48,7 +48,7 @@ from opentelemetry.sdk._metrics.sdk_configuration import SdkConfiguration from opentelemetry.sdk._metrics.view import View from opentelemetry.sdk.resources import Resource -from opentelemetry.sdk.util.instrumentation import InstrumentationInfo +from opentelemetry.sdk.util.instrumentation import InstrumentationScope from opentelemetry.util._once import Once _logger = getLogger(__name__) @@ -57,11 +57,11 @@ class Meter(APIMeter): def __init__( self, - instrumentation_info: InstrumentationInfo, + instrumentation_scope: InstrumentationScope, measurement_consumer: MeasurementConsumer, ): - super().__init__(instrumentation_info) - self._instrumentation_info = instrumentation_info + super().__init__(instrumentation_scope) + self._instrumentation_scope = instrumentation_scope self._measurement_consumer = measurement_consumer def create_counter(self, name, unit="", description="") -> APICounter: @@ -80,7 +80,7 @@ def create_counter(self, name, unit="", description="") -> APICounter: return Counter( name, - self._instrumentation_info, + self._instrumentation_scope, self._measurement_consumer, unit, description, @@ -104,7 +104,7 @@ def create_up_down_counter( return UpDownCounter( name, - self._instrumentation_info, + self._instrumentation_scope, self._measurement_consumer, unit, description, @@ -129,7 +129,7 @@ def create_observable_counter( ) instrument = ObservableCounter( name, - self._instrumentation_info, + self._instrumentation_scope, self._measurement_consumer, callbacks, unit, @@ -155,7 +155,7 @@ def create_histogram(self, name, unit="", description="") -> APIHistogram: ) return Histogram( name, - self._instrumentation_info, + self._instrumentation_scope, self._measurement_consumer, unit, description, @@ -179,7 +179,7 @@ def create_observable_gauge( instrument = ObservableGauge( name, - self._instrumentation_info, + self._instrumentation_scope, self._measurement_consumer, callbacks, unit, @@ -210,7 +210,7 @@ def create_observable_up_down_counter( instrument = ObservableUpDownCounter( name, - self._instrumentation_info, + self._instrumentation_scope, self._measurement_consumer, callbacks, unit, @@ -366,7 +366,7 @@ def get_meter( _logger.warning("Meter name cannot be None or empty.") return NoOpMeter(name, version=version, schema_url=schema_url) - info = InstrumentationInfo(name, version, schema_url) + info = InstrumentationScope(name, version, schema_url) with self._meter_lock: if not self._meters.get(info): # FIXME #2558 pass SDKConfig object to meter so that the meter diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_view_instrument_match.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_view_instrument_match.py index b124f773183..af1d9eb3513 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_view_instrument_match.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_view_instrument_match.py @@ -106,7 +106,7 @@ def collect(self, temporality: int) -> Iterable[Metric]: self._view._description or self._instrument.description ), - instrumentation_info=self._instrument.instrumentation_info, + instrumentation_scope=self._instrument.instrumentation_scope, name=self._view._name or self._instrument.name, resource=self._sdk_config.resource, unit=self._instrument.unit, diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/instrument.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/instrument.py index 260a9a77670..b637bba9f08 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/instrument.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/instrument.py @@ -32,7 +32,7 @@ from opentelemetry._metrics.instrument import UpDownCounter as APIUpDownCounter from opentelemetry.sdk._metrics.measurement import Measurement from opentelemetry.sdk._metrics.measurement_consumer import MeasurementConsumer -from opentelemetry.sdk.util.instrumentation import InstrumentationInfo +from opentelemetry.sdk.util.instrumentation import InstrumentationScope _logger = logging.getLogger(__name__) @@ -41,7 +41,7 @@ class _Synchronous: def __init__( self, name: str, - instrumentation_info: InstrumentationInfo, + instrumentation_scope: InstrumentationScope, measurement_consumer: MeasurementConsumer, unit: str = "", description: str = "", @@ -49,7 +49,7 @@ def __init__( self.name = name self.unit = unit self.description = description - self.instrumentation_info = instrumentation_info + self.instrumentation_scope = instrumentation_scope self._measurement_consumer = measurement_consumer super().__init__(name, unit=unit, description=description) @@ -58,7 +58,7 @@ class _Asynchronous: def __init__( self, name: str, - instrumentation_info: InstrumentationInfo, + instrumentation_scope: InstrumentationScope, measurement_consumer: MeasurementConsumer, callbacks: Optional[Iterable[CallbackT]] = None, unit: str = "", @@ -67,7 +67,7 @@ def __init__( self.name = name self.unit = unit self.description = description - self.instrumentation_info = instrumentation_info + self.instrumentation_scope = instrumentation_scope self._measurement_consumer = measurement_consumer super().__init__(name, callbacks, unit=unit, description=description) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/point.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/point.py index fcc127e949b..3417c197e67 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/point.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/point.py @@ -18,7 +18,7 @@ from typing import Sequence, Union from opentelemetry.sdk.resources import Resource -from opentelemetry.sdk.util.instrumentation import InstrumentationInfo +from opentelemetry.sdk.util.instrumentation import InstrumentationScope from opentelemetry.util.types import Attributes @@ -69,7 +69,7 @@ class Metric: # common fields to all metric kinds attributes: Attributes description: str - instrumentation_info: InstrumentationInfo + instrumentation_scope: InstrumentationScope name: str resource: Resource unit: str @@ -81,8 +81,8 @@ def to_json(self) -> str: { "attributes": self.attributes if self.attributes else "", "description": self.description if self.description else "", - "instrumentation_info": repr(self.instrumentation_info) - if self.instrumentation_info + "instrumentation_scope": repr(self.instrumentation_scope) + if self.instrumentation_scope else "", "name": self.name, "resource": repr(self.resource.attributes) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/view.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/view.py index d83ce47cf67..28adebe643d 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/view.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/view.py @@ -144,16 +144,16 @@ def _match(self, instrument: Instrument) -> bool: return False if self._meter_name is not None: - if instrument.instrumentation_info.name != self._meter_name: + if instrument.instrumentation_scope.name != self._meter_name: return False if self._meter_version is not None: - if instrument.instrumentation_info.version != self._meter_version: + if instrument.instrumentation_scope.version != self._meter_version: return False if self._meter_schema_url is not None: if ( - instrument.instrumentation_info.schema_url + instrument.instrumentation_scope.schema_url != self._meter_schema_url ): return False diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index 6a4c132ee76..f5279673781 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -37,6 +37,8 @@ Union, ) +from deprecated import deprecated + from opentelemetry import context as context_api from opentelemetry import trace as trace_api from opentelemetry.attributes import BoundedAttributes @@ -55,7 +57,10 @@ from opentelemetry.sdk.trace import sampling from opentelemetry.sdk.trace.id_generator import IdGenerator, RandomIdGenerator from opentelemetry.sdk.util import BoundedList -from opentelemetry.sdk.util.instrumentation import InstrumentationInfo +from opentelemetry.sdk.util.instrumentation import ( + InstrumentationInfo, + InstrumentationScope, +) from opentelemetry.trace import SpanContext from opentelemetry.trace.status import Status, StatusCode from opentelemetry.util import types @@ -357,11 +362,13 @@ def __init__( status: Status = Status(StatusCode.UNSET), start_time: Optional[int] = None, end_time: Optional[int] = None, + instrumentation_scope: InstrumentationScope = None, ) -> None: self._name = name self._context = context self._kind = kind self._instrumentation_info = instrumentation_info + self._instrumentation_scope = instrumentation_scope self._parent = parent self._start_time = start_time self._end_time = end_time @@ -437,9 +444,16 @@ def resource(self) -> Resource: return self._resource @property + @deprecated( + version="1.11.1", reason="You should use instrumentation_scope" + ) def instrumentation_info(self) -> InstrumentationInfo: return self._instrumentation_info + @property + def instrumentation_scope(self) -> InstrumentationScope: + return self._instrumentation_scope + def to_json(self, indent=4): parent_id = None if self.parent is not None: @@ -729,6 +743,7 @@ def __init__( record_exception: bool = True, set_status_on_exception: bool = True, limits=_UnsetLimits, + instrumentation_scope: InstrumentationScope = None, ) -> None: super().__init__( name=name, @@ -737,6 +752,7 @@ def __init__( kind=kind, resource=resource, instrumentation_info=instrumentation_info, + instrumentation_scope=instrumentation_scope, ) self._sampler = sampler self._trace_config = trace_config @@ -835,6 +851,7 @@ def _readable_span(self) -> ReadableSpan: start_time=self._start_time, end_time=self._end_time, instrumentation_info=self._instrumentation_info, + instrumentation_scope=self._instrumentation_scope, ) def start( @@ -956,6 +973,7 @@ def __init__( id_generator: IdGenerator, instrumentation_info: InstrumentationInfo, span_limits: SpanLimits, + instrumentation_scope: InstrumentationScope, ) -> None: self.sampler = sampler self.resource = resource @@ -963,6 +981,7 @@ def __init__( self.id_generator = id_generator self.instrumentation_info = instrumentation_info self._span_limits = span_limits + self._instrumentation_scope = instrumentation_scope @contextmanager def start_as_current_span( @@ -1065,6 +1084,7 @@ def start_span( # pylint: disable=too-many-locals record_exception=record_exception, set_status_on_exception=set_status_on_exception, limits=self._span_limits, + instrumentation_scope=self._instrumentation_scope, ) span.start(start_time=start_time, parent_context=context) else: @@ -1127,6 +1147,11 @@ def get_tracer( schema_url, ), self._span_limits, + InstrumentationScope( + instrumenting_module_name, + instrumenting_library_version, + schema_url, + ), ) def add_span_processor(self, span_processor: SpanProcessor) -> None: diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py b/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py index d634e1b8330..1b2c1c74a7d 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py @@ -13,6 +13,8 @@ # limitations under the License. import typing +from deprecated import deprecated + class InstrumentationInfo: """Immutable information about an instrumentation library module. @@ -23,6 +25,62 @@ class InstrumentationInfo: __slots__ = ("_name", "_version", "_schema_url") + @deprecated(version="1.11.1", reason="You should use InstrumentationScope") + def __init__( + self, + name: str, + version: typing.Optional[str] = None, + schema_url: typing.Optional[str] = None, + ): + self._name = name + self._version = version + self._schema_url = schema_url + + def __repr__(self): + return f"{type(self).__name__}({self._name}, {self._version}, {self._schema_url})" + + def __hash__(self): + return hash((self._name, self._version, self._schema_url)) + + def __eq__(self, value): + return type(value) is type(self) and ( + self._name, + self._version, + self._schema_url, + ) == (value._name, value._version, value._schema_url) + + def __lt__(self, value): + if type(value) is not type(self): + return NotImplemented + return (self._name, self._version, self._schema_url) < ( + value._name, + value._version, + value._schema_url, + ) + + @property + def schema_url(self) -> typing.Optional[str]: + return self._schema_url + + @property + def version(self) -> typing.Optional[str]: + return self._version + + @property + def name(self) -> str: + return self._name + + +class InstrumentationScope: + """A logical unit of the application code with which the emitted telemetry can be + associated. + + See `opentelemetry.trace.TracerProvider.get_tracer` for the meaning of these + properties. + """ + + __slots__ = ("_name", "_version", "_schema_url") + def __init__( self, name: str, diff --git a/opentelemetry-sdk/tests/logs/test_export.py b/opentelemetry-sdk/tests/logs/test_export.py index 42d66176fd0..a1c39d6df2b 100644 --- a/opentelemetry-sdk/tests/logs/test_export.py +++ b/opentelemetry-sdk/tests/logs/test_export.py @@ -39,7 +39,7 @@ ) from opentelemetry.sdk._logs.severity import SeverityNumber from opentelemetry.sdk.resources import Resource as SDKResource -from opentelemetry.sdk.util.instrumentation import InstrumentationInfo +from opentelemetry.sdk.util.instrumentation import InstrumentationScope from opentelemetry.test.concurrency_test import ConcurrencyTestBase from opentelemetry.trace import TraceFlags from opentelemetry.trace.span import INVALID_SPAN_CONTEXT @@ -338,7 +338,7 @@ def test_export(self): # pylint: disable=no-self-use resource=SDKResource({"key": "value"}), attributes={"a": 1, "b": "c"}, ), - instrumentation_info=InstrumentationInfo( + instrumentation_scope=InstrumentationScope( "first_name", "first_version" ), ) @@ -366,7 +366,7 @@ def formatter(record): # pylint: disable=unused-argument exporter = ConsoleLogExporter(out=mock_stdout, formatter=formatter) log_data = LogData( log_record=LogRecord(), - instrumentation_info=InstrumentationInfo( + instrumentation_scope=InstrumentationScope( "first_name", "first_version" ), ) diff --git a/opentelemetry-sdk/tests/metrics/test_in_memory_metric_reader.py b/opentelemetry-sdk/tests/metrics/test_in_memory_metric_reader.py index 89d39b5e2d4..3da776191a6 100644 --- a/opentelemetry-sdk/tests/metrics/test_in_memory_metric_reader.py +++ b/opentelemetry-sdk/tests/metrics/test_in_memory_metric_reader.py @@ -24,7 +24,7 @@ Sum, ) from opentelemetry.sdk.resources import Resource -from opentelemetry.sdk.util.instrumentation import InstrumentationInfo +from opentelemetry.sdk.util.instrumentation import InstrumentationScope class TestInMemoryMetricReader(TestCase): @@ -39,7 +39,7 @@ def test_converts_metrics_to_list(self): metric = Metric( attributes={"myattr": "baz"}, description="", - instrumentation_info=InstrumentationInfo("testmetrics"), + instrumentation_scope=InstrumentationScope("testmetrics"), name="foo", resource=Resource.create(), unit="", diff --git a/opentelemetry-sdk/tests/metrics/test_metrics.py b/opentelemetry-sdk/tests/metrics/test_metrics.py index 2c2d48a7930..f4f31a6294b 100644 --- a/opentelemetry-sdk/tests/metrics/test_metrics.py +++ b/opentelemetry-sdk/tests/metrics/test_metrics.py @@ -88,7 +88,7 @@ def test_resource(self): def test_get_meter(self): """ `MeterProvider.get_meter` arguments are used to create an - `InstrumentationInfo` object on the created `Meter`. + `InstrumentationScope` object on the created `Meter`. """ meter = MeterProvider().get_meter( @@ -97,9 +97,9 @@ def test_get_meter(self): schema_url="schema_url", ) - self.assertEqual(meter._instrumentation_info.name, "name") - self.assertEqual(meter._instrumentation_info.version, "version") - self.assertEqual(meter._instrumentation_info.schema_url, "schema_url") + self.assertEqual(meter._instrumentation_scope.name, "name") + self.assertEqual(meter._instrumentation_scope.version, "version") + self.assertEqual(meter._instrumentation_scope.schema_url, "schema_url") def test_get_meter_empty(self): """ diff --git a/opentelemetry-sdk/tests/metrics/test_periodic_exporting_metric_reader.py b/opentelemetry-sdk/tests/metrics/test_periodic_exporting_metric_reader.py index 4552a69063f..728e2911800 100644 --- a/opentelemetry-sdk/tests/metrics/test_periodic_exporting_metric_reader.py +++ b/opentelemetry-sdk/tests/metrics/test_periodic_exporting_metric_reader.py @@ -47,7 +47,7 @@ def shutdown(self): name="sum_name", attributes={}, description="", - instrumentation_info=None, + instrumentation_scope=None, resource=Resource.create(), unit="", point=Sum( @@ -62,7 +62,7 @@ def shutdown(self): name="gauge_name", attributes={}, description="", - instrumentation_info=None, + instrumentation_scope=None, resource=Resource.create(), unit="", point=Gauge( diff --git a/opentelemetry-sdk/tests/metrics/test_point.py b/opentelemetry-sdk/tests/metrics/test_point.py index 0e5d99a7269..1748fb7ba4a 100644 --- a/opentelemetry-sdk/tests/metrics/test_point.py +++ b/opentelemetry-sdk/tests/metrics/test_point.py @@ -16,14 +16,14 @@ from opentelemetry.sdk._metrics.point import Gauge, Histogram, Metric, Sum from opentelemetry.sdk.resources import Resource -from opentelemetry.sdk.util.instrumentation import InstrumentationInfo +from opentelemetry.sdk.util.instrumentation import InstrumentationScope def _create_metric(value): return Metric( attributes={"attr-key": "test-val"}, description="test-description", - instrumentation_info=InstrumentationInfo( + instrumentation_scope=InstrumentationScope( name="name", version="version" ), name="test-name", @@ -35,6 +35,7 @@ def _create_metric(value): class TestDatapointToJSON(TestCase): def test_sum(self): + self.maxDiff = None point = _create_metric( Sum( aggregation_temporality=2, @@ -45,14 +46,14 @@ def test_sum(self): ) ) self.assertEqual( - '{"attributes": {"attr-key": "test-val"}, "description": "test-description", "instrumentation_info": "InstrumentationInfo(name, version, None)", "name": "test-name", "resource": "BoundedAttributes({\'resource-key\': \'resource-val\'}, maxlen=None)", "unit": "test-unit", "point": {"aggregation_temporality": 2, "is_monotonic": true, "start_time_unix_nano": 10, "time_unix_nano": 20, "value": 9}}', + '{"attributes": {"attr-key": "test-val"}, "description": "test-description", "instrumentation_scope": "InstrumentationScope(name, version, None)", "name": "test-name", "resource": "BoundedAttributes({\'resource-key\': \'resource-val\'}, maxlen=None)", "unit": "test-unit", "point": {"aggregation_temporality": 2, "is_monotonic": true, "start_time_unix_nano": 10, "time_unix_nano": 20, "value": 9}}', point.to_json(), ) def test_gauge(self): point = _create_metric(Gauge(time_unix_nano=40, value=20)) self.assertEqual( - '{"attributes": {"attr-key": "test-val"}, "description": "test-description", "instrumentation_info": "InstrumentationInfo(name, version, None)", "name": "test-name", "resource": "BoundedAttributes({\'resource-key\': \'resource-val\'}, maxlen=None)", "unit": "test-unit", "point": {"time_unix_nano": 40, "value": 20}}', + '{"attributes": {"attr-key": "test-val"}, "description": "test-description", "instrumentation_scope": "InstrumentationScope(name, version, None)", "name": "test-name", "resource": "BoundedAttributes({\'resource-key\': \'resource-val\'}, maxlen=None)", "unit": "test-unit", "point": {"time_unix_nano": 40, "value": 20}}', point.to_json(), ) @@ -71,6 +72,6 @@ def test_histogram(self): ) self.maxDiff = None self.assertEqual( - '{"attributes": {"attr-key": "test-val"}, "description": "test-description", "instrumentation_info": "InstrumentationInfo(name, version, None)", "name": "test-name", "resource": "BoundedAttributes({\'resource-key\': \'resource-val\'}, maxlen=None)", "unit": "test-unit", "point": {"aggregation_temporality": 1, "bucket_counts": [0, 0, 1, 0], "explicit_bounds": [0.1, 0.5, 0.9, 1], "max": 0.8, "min": 0.8, "start_time_unix_nano": 50, "sum": 0.8, "time_unix_nano": 60}}', + '{"attributes": {"attr-key": "test-val"}, "description": "test-description", "instrumentation_scope": "InstrumentationScope(name, version, None)", "name": "test-name", "resource": "BoundedAttributes({\'resource-key\': \'resource-val\'}, maxlen=None)", "unit": "test-unit", "point": {"aggregation_temporality": 1, "bucket_counts": [0, 0, 1, 0], "explicit_bounds": [0.1, 0.5, 0.9, 1], "max": 0.8, "min": 0.8, "start_time_unix_nano": 50, "sum": 0.8, "time_unix_nano": 60}}', point.to_json(), ) diff --git a/opentelemetry-sdk/tests/metrics/test_view.py b/opentelemetry-sdk/tests/metrics/test_view.py index 80f5884c8d2..a78e282244d 100644 --- a/opentelemetry-sdk/tests/metrics/test_view.py +++ b/opentelemetry-sdk/tests/metrics/test_view.py @@ -41,7 +41,7 @@ def test_meter_name(self): self.assertTrue( View(meter_name="meter_name")._match( - Mock(**{"instrumentation_info.name": "meter_name"}) + Mock(**{"instrumentation_scope.name": "meter_name"}) ) ) @@ -49,7 +49,7 @@ def test_meter_version(self): self.assertTrue( View(meter_version="meter_version")._match( - Mock(**{"instrumentation_info.version": "meter_version"}) + Mock(**{"instrumentation_scope.version": "meter_version"}) ) ) @@ -57,21 +57,25 @@ def test_meter_schema_url(self): self.assertTrue( View(meter_schema_url="meter_schema_url")._match( - Mock(**{"instrumentation_info.schema_url": "meter_schema_url"}) + Mock( + **{"instrumentation_scope.schema_url": "meter_schema_url"} + ) ) ) self.assertFalse( View(meter_schema_url="meter_schema_url")._match( Mock( **{ - "instrumentation_info.schema_url": "meter_schema_urlabc" + "instrumentation_scope.schema_url": "meter_schema_urlabc" } ) ) ) self.assertTrue( View(meter_schema_url="meter_schema_url")._match( - Mock(**{"instrumentation_info.schema_url": "meter_schema_url"}) + Mock( + **{"instrumentation_scope.schema_url": "meter_schema_url"} + ) ) ) @@ -87,9 +91,9 @@ def test_additive_criteria(self): view._match( Mock( **{ - "instrumentation_info.name": "meter_name", - "instrumentation_info.version": "meter_version", - "instrumentation_info.schema_url": "meter_schema_url", + "instrumentation_scope.name": "meter_name", + "instrumentation_scope.version": "meter_version", + "instrumentation_scope.schema_url": "meter_schema_url", } ) ) @@ -98,9 +102,9 @@ def test_additive_criteria(self): view._match( Mock( **{ - "instrumentation_info.name": "meter_name", - "instrumentation_info.version": "meter_version", - "instrumentation_info.schema_url": "meter_schema_vrl", + "instrumentation_scope.name": "meter_name", + "instrumentation_scope.version": "meter_version", + "instrumentation_scope.schema_url": "meter_schema_vrl", } ) ) diff --git a/opentelemetry-sdk/tests/metrics/test_view_instrument_match.py b/opentelemetry-sdk/tests/metrics/test_view_instrument_match.py index 6edba9b4eb4..20b1a041698 100644 --- a/opentelemetry-sdk/tests/metrics/test_view_instrument_match.py +++ b/opentelemetry-sdk/tests/metrics/test_view_instrument_match.py @@ -37,11 +37,11 @@ def setUpClass(cls): cls.mock_aggregation_factory._create_aggregation() ) cls.mock_resource = Mock() - cls.mock_instrumentation_info = Mock() + cls.mock_instrumentation_scope = Mock() def test_consume_measurement(self): instrument1 = Mock(name="instrument1") - instrument1.instrumentation_info = self.mock_instrumentation_info + instrument1.instrumentation_scope = self.mock_instrumentation_scope sdk_config = SdkConfiguration( resource=self.mock_resource, metric_readers=[], @@ -158,7 +158,7 @@ def test_collect(self): instrument1 = Mock( name="instrument1", description="description", unit="unit" ) - instrument1.instrumentation_info = self.mock_instrumentation_info + instrument1.instrumentation_scope = self.mock_instrumentation_scope sdk_config = SdkConfiguration( resource=self.mock_resource, metric_readers=[], @@ -191,7 +191,7 @@ def test_collect(self): Metric( attributes={"c": "d"}, description="description", - instrumentation_info=self.mock_instrumentation_info, + instrumentation_scope=self.mock_instrumentation_scope, name="name", resource=self.mock_resource, unit="unit", diff --git a/tests/opentelemetry-test-utils/src/opentelemetry/test/metrictestutil.py b/tests/opentelemetry-test-utils/src/opentelemetry/test/metrictestutil.py index 4bf45f357d8..97b411ac4b6 100644 --- a/tests/opentelemetry-test-utils/src/opentelemetry/test/metrictestutil.py +++ b/tests/opentelemetry-test-utils/src/opentelemetry/test/metrictestutil.py @@ -23,7 +23,7 @@ Sum, ) from opentelemetry.sdk.resources import Resource as SDKResource -from opentelemetry.sdk.util.instrumentation import InstrumentationInfo +from opentelemetry.sdk.util.instrumentation import InstrumentationScope def _generate_metric( @@ -37,7 +37,7 @@ def _generate_metric( unit = "s" return Metric( resource=SDKResource(OrderedDict([("a", 1), ("b", False)])), - instrumentation_info=InstrumentationInfo( + instrumentation_scope=InstrumentationScope( "first_name", "first_version" ), attributes=attributes,