Skip to content

Commit

Permalink
fix #3522 OTLPMetricExporter ignores preferred_aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dudssource authored and ocelotl committed Feb 13, 2024
1 parent 6e6590c commit 704b4d8
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
)
from opentelemetry.sdk.metrics.export import (
AggregationTemporality,
DefaultAggregation,
)
from opentelemetry.proto.collector.metrics.v1.metrics_service_pb2 import (
ExportMetricsServiceRequest,
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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",
Expand All @@ -128,7 +132,9 @@ def _common_configuration(
"base2_exponential_bucket_histogram"
):

histogram_aggregation_type = ExponentialBucketHistogramAggregation
instrument_class_aggregation = {
Histogram: ExponentialBucketHistogramAggregation(),
}

else:

Expand All @@ -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,
)


Expand Down

0 comments on commit 704b4d8

Please sign in to comment.