From 704b4d82201fe468be002852982d0165cb2e7c67 Mon Sep 17 00:00:00 2001 From: Dudssource Date: Wed, 27 Dec 2023 01:44:19 -0300 Subject: [PATCH 01/20] fix #3522 OTLPMetricExporter ignores preferred_aggregation --- .../common/_internal/metrics_encoder/__init__.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py index ecd20b8145a..ee982715473 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py @@ -33,6 +33,7 @@ ) from opentelemetry.sdk.metrics.export import ( AggregationTemporality, + DefaultAggregation, ) from opentelemetry.proto.collector.metrics.v1.metrics_service_pb2 import ( ExportMetricsServiceRequest, @@ -65,6 +66,7 @@ class OTLPMetricExporterMixin: def _common_configuration( self, preferred_temporality: Dict[type, AggregationTemporality] = None, + preferred_aggregation: Dict[type, "opentelemetry.sdk.metrics.view.Aggregation"] = None, ) -> None: instrument_class_temporality = {} @@ -119,6 +121,8 @@ def _common_configuration( instrument_class_temporality.update(preferred_temporality or {}) + instrument_class_aggregation = {} + otel_exporter_otlp_metrics_default_histogram_aggregation = environ.get( OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION, "explicit_bucket_histogram", @@ -128,7 +132,9 @@ def _common_configuration( "base2_exponential_bucket_histogram" ): - histogram_aggregation_type = ExponentialBucketHistogramAggregation + instrument_class_aggregation = { + Histogram: ExponentialBucketHistogramAggregation(), + } else: @@ -145,12 +151,16 @@ def _common_configuration( otel_exporter_otlp_metrics_default_histogram_aggregation, ) - histogram_aggregation_type = ExplicitBucketHistogramAggregation + instrument_class_aggregation = { + Histogram: ExplicitBucketHistogramAggregation(), + } + + instrument_class_aggregation.update(preferred_aggregation or {}) MetricExporter.__init__( self, preferred_temporality=instrument_class_temporality, - preferred_aggregation={Histogram: histogram_aggregation_type()}, + preferred_aggregation=instrument_class_aggregation, ) From 1718871187f1bc0b05854e00b3fba0b5423c7f2a Mon Sep 17 00:00:00 2001 From: Dudssource Date: Wed, 27 Dec 2023 01:47:00 -0300 Subject: [PATCH 02/20] make OTLPMetricExporter pass the preferred_aggregation argument to the _common_configuration function --- .../exporter/otlp/proto/http/metric_exporter/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py index becdab257fe..1244eb2b6ea 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py @@ -135,7 +135,7 @@ def __init__( {"Content-Encoding": self._compression.value} ) - self._common_configuration(preferred_temporality) + self._common_configuration(preferred_temporality, preferred_aggregation) def _export(self, serialized_data: str): data = serialized_data From cdded4ae19c9ccd3e7b1801bcebd7e1e1635d7af Mon Sep 17 00:00:00 2001 From: Dudssource Date: Wed, 27 Dec 2023 02:41:39 -0300 Subject: [PATCH 03/20] Remove unnecessary import from metrics encoder --- .../otlp/proto/common/_internal/metrics_encoder/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py index ee982715473..c2efdfa4624 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py @@ -33,7 +33,6 @@ ) from opentelemetry.sdk.metrics.export import ( AggregationTemporality, - DefaultAggregation, ) from opentelemetry.proto.collector.metrics.v1.metrics_service_pb2 import ( ExportMetricsServiceRequest, From be1cfc1216126446367c2b256ebf96492a0b1996 Mon Sep 17 00:00:00 2001 From: Dudssource Date: Mon, 8 Jan 2024 17:20:10 -0300 Subject: [PATCH 04/20] docs: added changelog entry for pr #3603 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index abedcb6f260..c09e5c0a5da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3524](https://github.com/open-telemetry/opentelemetry-python/pull/3524)) - Handle `taskName` `logrecord` attribute ([#3557](https://github.com/open-telemetry/opentelemetry-python/pull/3557)) +- Fix `OTLPMetricExporter` ignores `preferred_aggregation` property ([#3603](https://github.com/open-telemetry/opentelemetry-python/pull/3603)) ## Version 1.21.0/0.42b0 (2023-11-01) From 14af46f9ec0524195520cbe0806fa628e481d202 Mon Sep 17 00:00:00 2001 From: Dudssource Date: Mon, 8 Jan 2024 17:53:53 -0300 Subject: [PATCH 05/20] Added unit test to make sure preferred_aggregation override works --- .../tests/metrics/test_otlp_metrics_exporter.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py index fdefcb714e0..674785056a5 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py @@ -479,3 +479,19 @@ def test_2xx_status_code(self, mock_otlp_metric_exporter): OTLPMetricExporter().export(MagicMock()), MetricExportResult.SUCCESS, ) + + def test_preferred_aggregation_override(self): + + histogram_aggregation = ExplicitBucketHistogramAggregation( + boundaries=[0.05, 0.1, 0.5, 1, 5, 10], + ) + + exporter = OTLPMetricExporter( + preferred_aggregation={ + Histogram: histogram_aggregation, + }, + ) + + self.assertEqual( + exporter._preferred_aggregation[Histogram], histogram_aggregation + ) From 718ea2da0a2b99a63b2a28b1b56e1d5c381790d3 Mon Sep 17 00:00:00 2001 From: Dudssource Date: Fri, 12 Jan 2024 11:07:46 -0300 Subject: [PATCH 06/20] chore: break aggregation and temporality config in two functions --- .../_internal/metrics_encoder/__init__.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py index c2efdfa4624..11f9b348c9d 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py @@ -68,6 +68,14 @@ def _common_configuration( preferred_aggregation: Dict[type, "opentelemetry.sdk.metrics.view.Aggregation"] = None, ) -> None: + MetricExporter.__init__( + self, + preferred_temporality=self.get_temporality(preferred_temporality), + preferred_aggregation=self.get_aggregation(preferred_aggregation), + ) + + def get_temporality(self, preferred_temporality: Dict[type, AggregationTemporality]) -> Dict[type, AggregationTemporality]: + instrument_class_temporality = {} otel_exporter_otlp_metrics_temporality_preference = ( @@ -120,6 +128,10 @@ def _common_configuration( instrument_class_temporality.update(preferred_temporality or {}) + return instrument_class_temporality + + def get_aggregation(self, preferred_aggregation: Dict[type, "opentelemetry.sdk.metrics.view.Aggregation"]) -> Dict[type, "opentelemetry.sdk.metrics.view.Aggregation"]: + instrument_class_aggregation = {} otel_exporter_otlp_metrics_default_histogram_aggregation = environ.get( @@ -156,11 +168,7 @@ def _common_configuration( instrument_class_aggregation.update(preferred_aggregation or {}) - MetricExporter.__init__( - self, - preferred_temporality=instrument_class_temporality, - preferred_aggregation=instrument_class_aggregation, - ) + return instrument_class_aggregation def encode_metrics(data: MetricsData) -> ExportMetricsServiceRequest: From c59c7c93b3315396a6304c0e291eb6b25939d6d5 Mon Sep 17 00:00:00 2001 From: Dudssource Date: Fri, 19 Jan 2024 19:34:37 -0300 Subject: [PATCH 07/20] chore: removed instrument_class_aggregation variable external declaration, to avoid possible problems with linters --- .../otlp/proto/common/_internal/metrics_encoder/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py index 11f9b348c9d..f987142513d 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py @@ -132,8 +132,6 @@ def get_temporality(self, preferred_temporality: Dict[type, AggregationTemporali def get_aggregation(self, preferred_aggregation: Dict[type, "opentelemetry.sdk.metrics.view.Aggregation"]) -> Dict[type, "opentelemetry.sdk.metrics.view.Aggregation"]: - instrument_class_aggregation = {} - otel_exporter_otlp_metrics_default_histogram_aggregation = environ.get( OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION, "explicit_bucket_histogram", From 057273ec7223c4f44976b7c8d45857e89f001a85 Mon Sep 17 00:00:00 2001 From: Dudssource Date: Mon, 22 Jan 2024 11:00:53 -0300 Subject: [PATCH 08/20] chore: removed unnecessary variable declaration --- .../otlp/proto/common/_internal/metrics_encoder/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py index f987142513d..8f4997c2f4e 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py @@ -76,8 +76,6 @@ def _common_configuration( def get_temporality(self, preferred_temporality: Dict[type, AggregationTemporality]) -> Dict[type, AggregationTemporality]: - instrument_class_temporality = {} - otel_exporter_otlp_metrics_temporality_preference = ( environ.get( OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE, From 77fde484f8cca01a89000e6ddf7074a473a00bcf Mon Sep 17 00:00:00 2001 From: Dudssource Date: Mon, 22 Jan 2024 11:02:09 -0300 Subject: [PATCH 09/20] docs: moved changelog entry to unreleased --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c09e5c0a5da..d014b1e578a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- Fix `OTLPMetricExporter` ignores `preferred_aggregation` property + ([#3603](https://github.com/open-telemetry/opentelemetry-python/pull/3603)) - Logs: set `observed_timestamp` field ([#3565](https://github.com/open-telemetry/opentelemetry-python/pull/3565)) - Add missing Resource SchemaURL in OTLP exporters @@ -50,7 +52,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3524](https://github.com/open-telemetry/opentelemetry-python/pull/3524)) - Handle `taskName` `logrecord` attribute ([#3557](https://github.com/open-telemetry/opentelemetry-python/pull/3557)) -- Fix `OTLPMetricExporter` ignores `preferred_aggregation` property ([#3603](https://github.com/open-telemetry/opentelemetry-python/pull/3603)) ## Version 1.21.0/0.42b0 (2023-11-01) From 491482d8fbd9815d4b4a2fc276b633fd52c94c71 Mon Sep 17 00:00:00 2001 From: Dudssource Date: Mon, 22 Jan 2024 11:07:16 -0300 Subject: [PATCH 10/20] chore: added preferred_aggregation argument to _common_configuration call --- .../exporter/otlp/proto/grpc/metric_exporter/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2560c5c3057..a1deb3c893a 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 @@ -127,7 +127,7 @@ def __init__( else compression ) - self._common_configuration(preferred_temporality) + self._common_configuration(preferred_temporality, preferred_aggregation) OTLPExporterMixin.__init__( self, From 489b4c50506fc340b2801d41321c415916a964b6 Mon Sep 17 00:00:00 2001 From: Dudssource Date: Mon, 22 Jan 2024 11:09:17 -0300 Subject: [PATCH 11/20] chore: added unit test for grpc otlp metric exporter --- .../tests/test_otlp_metrics_exporter.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py index 291e9457efd..de164b1cb06 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py @@ -1006,3 +1006,19 @@ def _number_data_point(value: int) -> NumberDataPoint: time_unix_nano=1641946016139533244, value=value, ) + +def test_preferred_aggregation_override(self): + + histogram_aggregation = ExplicitBucketHistogramAggregation( + boundaries=[0.05, 0.1, 0.5, 1, 5, 10], + ) + + exporter = OTLPMetricExporter( + preferred_aggregation={ + Histogram: histogram_aggregation, + }, + ) + + self.assertEqual( + exporter._preferred_aggregation[Histogram], histogram_aggregation + ) From 6b5cf7aa883397c2a0c7893c849e0e30bfc5c251 Mon Sep 17 00:00:00 2001 From: Dudssource Date: Mon, 22 Jan 2024 11:19:51 -0300 Subject: [PATCH 12/20] test: moved preferred_aggregation test to class --- .../tests/test_otlp_metrics_exporter.py | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py index de164b1cb06..a273a6871fb 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py @@ -968,6 +968,22 @@ def test_exponential_explicit_bucket_histogram(self): ExplicitBucketHistogramAggregation, ) + def test_preferred_aggregation_override(self): + + histogram_aggregation = ExplicitBucketHistogramAggregation( + boundaries=[0.05, 0.1, 0.5, 1, 5, 10], + ) + + exporter = OTLPMetricExporter( + preferred_aggregation={ + Histogram: histogram_aggregation, + }, + ) + + self.assertEqual( + exporter._preferred_aggregation[Histogram], histogram_aggregation + ) + def _resource_metrics( index: int, scope_metrics: List[ScopeMetrics] @@ -1006,19 +1022,3 @@ def _number_data_point(value: int) -> NumberDataPoint: time_unix_nano=1641946016139533244, value=value, ) - -def test_preferred_aggregation_override(self): - - histogram_aggregation = ExplicitBucketHistogramAggregation( - boundaries=[0.05, 0.1, 0.5, 1, 5, 10], - ) - - exporter = OTLPMetricExporter( - preferred_aggregation={ - Histogram: histogram_aggregation, - }, - ) - - self.assertEqual( - exporter._preferred_aggregation[Histogram], histogram_aggregation - ) From 4f805cc4cd1535778afb09e9d6d0a3a97b0b5f79 Mon Sep 17 00:00:00 2001 From: Dudssource Date: Tue, 23 Jan 2024 13:06:01 -0300 Subject: [PATCH 13/20] chore: fix linter findings on metrics_encoder/__init__.py --- .../common/_internal/metrics_encoder/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py index 8f4997c2f4e..8cf321be72e 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py @@ -66,6 +66,9 @@ def _common_configuration( self, preferred_temporality: Dict[type, AggregationTemporality] = None, preferred_aggregation: Dict[type, "opentelemetry.sdk.metrics.view.Aggregation"] = None, + preferred_aggregation: Dict[ + type, "opentelemetry.sdk.metrics.view.Aggregation" + ] = None, ) -> None: MetricExporter.__init__( @@ -74,7 +77,9 @@ def _common_configuration( preferred_aggregation=self.get_aggregation(preferred_aggregation), ) - def get_temporality(self, preferred_temporality: Dict[type, AggregationTemporality]) -> Dict[type, AggregationTemporality]: + def get_temporality( + self, preferred_temporality: Dict[type, AggregationTemporality] + ) -> Dict[type, AggregationTemporality]: otel_exporter_otlp_metrics_temporality_preference = ( environ.get( @@ -128,7 +133,12 @@ def get_temporality(self, preferred_temporality: Dict[type, AggregationTemporali return instrument_class_temporality - def get_aggregation(self, preferred_aggregation: Dict[type, "opentelemetry.sdk.metrics.view.Aggregation"]) -> Dict[type, "opentelemetry.sdk.metrics.view.Aggregation"]: + def get_aggregation( + self, + preferred_aggregation: Dict[ + type, "opentelemetry.sdk.metrics.view.Aggregation" + ], + ) -> Dict[type, "opentelemetry.sdk.metrics.view.Aggregation"]: otel_exporter_otlp_metrics_default_histogram_aggregation = environ.get( OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION, From a6343f6f86ed0861ae53d758a613878174738709 Mon Sep 17 00:00:00 2001 From: Dudssource Date: Tue, 23 Jan 2024 13:07:34 -0300 Subject: [PATCH 14/20] chore: fix linter findings on grpc/metrics_exporter/__init__.py --- .../exporter/otlp/proto/grpc/metric_exporter/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 a1deb3c893a..0ceca25c867 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 @@ -127,7 +127,9 @@ def __init__( else compression ) - self._common_configuration(preferred_temporality, preferred_aggregation) + self._common_configuration( + preferred_temporality, preferred_aggregation + ) OTLPExporterMixin.__init__( self, From f8b03e32b42108d6a96ffc8c52d4ed522840dc31 Mon Sep 17 00:00:00 2001 From: Dudssource Date: Tue, 23 Jan 2024 13:08:43 -0300 Subject: [PATCH 15/20] chore: fix linter findings on http/metrics_exporter/__init__.py --- .../exporter/otlp/proto/http/metric_exporter/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py index 1244eb2b6ea..6be74a37a06 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py @@ -135,7 +135,9 @@ def __init__( {"Content-Encoding": self._compression.value} ) - self._common_configuration(preferred_temporality, preferred_aggregation) + self._common_configuration( + preferred_temporality, preferred_aggregation + ) def _export(self, serialized_data: str): data = serialized_data From b5c95ccbea5f29b2d9110bfddcce8df7454cc5c8 Mon Sep 17 00:00:00 2001 From: Dudssource Date: Wed, 24 Jan 2024 17:10:09 -0300 Subject: [PATCH 16/20] fix: removed code duplicate --- .../otlp/proto/common/_internal/metrics_encoder/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py index 8cf321be72e..eb2a1147842 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py @@ -65,7 +65,6 @@ class OTLPMetricExporterMixin: def _common_configuration( self, preferred_temporality: Dict[type, AggregationTemporality] = None, - preferred_aggregation: Dict[type, "opentelemetry.sdk.metrics.view.Aggregation"] = None, preferred_aggregation: Dict[ type, "opentelemetry.sdk.metrics.view.Aggregation" ] = None, From 77869dff7e3b66543b5bbe13c46ad05e48222d1d Mon Sep 17 00:00:00 2001 From: Dudssource Date: Sat, 27 Jan 2024 18:47:39 -0300 Subject: [PATCH 17/20] chore: fixed linter errors --- .../otlp/proto/common/_internal/metrics_encoder/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py index eb2a1147842..675f4db97dd 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py @@ -13,6 +13,8 @@ # limitations under the License. import logging +# This kind of import is needed to avoid Sphinx errors. +import opentelemetry.sdk.metrics._internal from opentelemetry.sdk.metrics.export import ( MetricExporter, ) From cb825d9c193955f49671047f38eba79e3ac348f3 Mon Sep 17 00:00:00 2001 From: Dudssource Date: Mon, 29 Jan 2024 09:54:28 -0300 Subject: [PATCH 18/20] Ignoring pylint for protected access --- .../tests/test_otlp_metrics_exporter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py index a273a6871fb..f88b6d7bcf9 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py @@ -981,6 +981,7 @@ def test_preferred_aggregation_override(self): ) self.assertEqual( + # pylint: disable=protected-access exporter._preferred_aggregation[Histogram], histogram_aggregation ) From 479e28e6f5e7e8fd0d2d9947a4f91e238912e6df Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 13 Feb 2024 17:41:38 -0600 Subject: [PATCH 19/20] Fix Aggregation import --- .../common/_internal/metrics_encoder/__init__.py | 13 ++++--------- .../tests/test_otlp_metrics_exporter.py | 3 ++- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py index 675f4db97dd..49145cb13f5 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py @@ -13,11 +13,10 @@ # limitations under the License. import logging -# This kind of import is needed to avoid Sphinx errors. -import opentelemetry.sdk.metrics._internal from opentelemetry.sdk.metrics.export import ( MetricExporter, ) +from opentelemetry.sdk.metrics.view import Aggregation from os import environ from opentelemetry.sdk.metrics import ( Counter, @@ -67,9 +66,7 @@ class OTLPMetricExporterMixin: def _common_configuration( self, preferred_temporality: Dict[type, AggregationTemporality] = None, - preferred_aggregation: Dict[ - type, "opentelemetry.sdk.metrics.view.Aggregation" - ] = None, + preferred_aggregation: Dict[type, Aggregation] = None, ) -> None: MetricExporter.__init__( @@ -136,10 +133,8 @@ def get_temporality( def get_aggregation( self, - preferred_aggregation: Dict[ - type, "opentelemetry.sdk.metrics.view.Aggregation" - ], - ) -> Dict[type, "opentelemetry.sdk.metrics.view.Aggregation"]: + preferred_aggregation: Dict[type, Aggregation], + ) -> Dict[type, Aggregation]: otel_exporter_otlp_metrics_default_histogram_aggregation = environ.get( OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION, diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py index f88b6d7bcf9..95733b917bf 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py @@ -982,7 +982,8 @@ def test_preferred_aggregation_override(self): self.assertEqual( # pylint: disable=protected-access - exporter._preferred_aggregation[Histogram], histogram_aggregation + exporter._preferred_aggregation[Histogram], + histogram_aggregation, ) From ce20dd0c4413be65a19e0cae7e1a9878cc8cdb1e Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 13 Feb 2024 17:55:13 -0600 Subject: [PATCH 20/20] Rename getter methods to private --- .../proto/common/_internal/metrics_encoder/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py index 49145cb13f5..0d66fd28b70 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py @@ -71,11 +71,11 @@ def _common_configuration( MetricExporter.__init__( self, - preferred_temporality=self.get_temporality(preferred_temporality), - preferred_aggregation=self.get_aggregation(preferred_aggregation), + preferred_temporality=self._get_temporality(preferred_temporality), + preferred_aggregation=self._get_aggregation(preferred_aggregation), ) - def get_temporality( + def _get_temporality( self, preferred_temporality: Dict[type, AggregationTemporality] ) -> Dict[type, AggregationTemporality]: @@ -131,7 +131,7 @@ def get_temporality( return instrument_class_temporality - def get_aggregation( + def _get_aggregation( self, preferred_aggregation: Dict[type, Aggregation], ) -> Dict[type, Aggregation]: