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 a36b8e329a8..1c78cae1a3e 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 @@ -13,7 +13,7 @@ from logging import getLogger from os import environ -from typing import Optional, Sequence, Dict, Iterable +from typing import Optional, Sequence, Dict from grpc import ChannelCredentials, Compression from opentelemetry.exporter.otlp.proto.grpc.exporter import ( OTLPExporterMixin, @@ -40,14 +40,12 @@ from opentelemetry.sdk._metrics.export import ( MetricExporter, MetricExportResult, + MappingMetricT, ) from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.util.instrumentation import ( InstrumentationScope as SDKInstrumentationScope, ) -from opentelemetry.sdk._metrics.metric_reader import ( - Metric as MetricReaderMetric, -) _logger = getLogger(__name__) @@ -86,11 +84,7 @@ def __init__( ) def _translate_data( - self, - data: Dict[ - Resource, - Dict[SDKInstrumentationScope, Iterable[MetricReaderMetric]], - ], + self, data: MappingMetricT ) -> ExportMetricsServiceRequest: sdk_resource_scope_metrics: Dict[ @@ -203,9 +197,7 @@ def _translate_data( def export( self, - metrics: Dict[ - Resource, Dict[InstrumentationScope, Iterable[MetricReaderMetric]] - ], + metrics: MappingMetricT, *args, **kwargs ) -> MetricExportResult: diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_internal/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_internal/export/__init__.py index e41305a4ff8..5bd990e637c 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_internal/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_internal/export/__init__.py @@ -19,7 +19,7 @@ from os import environ, linesep from sys import stdout from threading import Event, RLock, Thread -from typing import IO, Callable, Dict, Iterable, List, Optional, Sequence +from typing import IO, Callable, Dict, Iterable, List, Mapping, Optional from opentelemetry.context import ( _SUPPRESS_INSTRUMENTATION_KEY, @@ -39,6 +39,10 @@ _logger = logging.getLogger(__name__) +MappingMetricT = Mapping[ + Resource, Mapping[InstrumentationScope, Iterable[MetricReaderMetric]] +] + class MetricExportResult(Enum): """Result of exporting a metric @@ -58,7 +62,7 @@ class MetricExporter(ABC): @abstractmethod def export( - self, metrics: Sequence[Metric], *args, **kwargs + self, metrics: MappingMetricT, *args, **kwargs ) -> "MetricExportResult": """Exports a batch of telemetry data. @@ -95,7 +99,7 @@ def __init__( self.formatter = formatter def export( - self, metrics: Sequence[Metric], *args, **kwargs + self, metrics: MappingMetricT, *args, **kwargs ) -> MetricExportResult: for metric in metrics: self.out.write(self.formatter(metric)) @@ -136,9 +140,7 @@ def get_metrics(self) -> List[Metric]: def _receive_metrics( self, - metrics: Dict[ - Resource, Dict[InstrumentationScope, Iterable[MetricReaderMetric]] - ], + metrics: MappingMetricT, *args, **kwargs ) -> None: @@ -213,9 +215,7 @@ def _ticker(self) -> None: def _receive_metrics( self, - metrics: Dict[ - Resource, Dict[InstrumentationScope, Iterable[MetricReaderMetric]] - ], + metrics: MappingMetricT, *args, **kwargs ) -> None: