feat(exporter/prometheus): add default_aggregation parameter to PrometheusMetricReader#5117
Open
Manvi2402 wants to merge 3 commits intoopen-telemetry:mainfrom
Open
feat(exporter/prometheus): add default_aggregation parameter to PrometheusMetricReader#5117Manvi2402 wants to merge 3 commits intoopen-telemetry:mainfrom
Manvi2402 wants to merge 3 commits intoopen-telemetry:mainfrom
Conversation
…theusMetricReader
herin049
reviewed
Apr 17, 2026
MikeGoldsmith
requested changes
Apr 17, 2026
Member
MikeGoldsmith
left a comment
There was a problem hiding this comment.
This looks good, thanks @Manvi2402. I've left some things to tweak.
I think it's gonna conflict with @herin049's PR (#5118). Whoever's PR merges later will likely have a conflict to resolve.
Comment on lines
+725
to
+741
| def test_default_aggregation(self): | ||
| """Test that default_aggregation parameter is passed to MetricReader.""" | ||
| custom_aggregation = { | ||
| HistogramInstrument: ExplicitBucketHistogramAggregation( | ||
| boundaries=[1.0, 5.0, 10.0] | ||
| ) | ||
| } | ||
| reader = PrometheusMetricReader( | ||
| default_aggregation=custom_aggregation | ||
| ) | ||
| self.assertEqual( | ||
| reader._instrument_class_aggregation[ | ||
| HistogramInstrument | ||
| ].__class__, | ||
| ExplicitBucketHistogramAggregation, | ||
| ) | ||
| reader.shutdown() |
Member
There was a problem hiding this comment.
Indentation is wrong, this won't get run.
Suggested change
| def test_default_aggregation(self): | |
| """Test that default_aggregation parameter is passed to MetricReader.""" | |
| custom_aggregation = { | |
| HistogramInstrument: ExplicitBucketHistogramAggregation( | |
| boundaries=[1.0, 5.0, 10.0] | |
| ) | |
| } | |
| reader = PrometheusMetricReader( | |
| default_aggregation=custom_aggregation | |
| ) | |
| self.assertEqual( | |
| reader._instrument_class_aggregation[ | |
| HistogramInstrument | |
| ].__class__, | |
| ExplicitBucketHistogramAggregation, | |
| ) | |
| reader.shutdown() | |
| def test_default_aggregation(self): | |
| """Test that default_aggregation parameter is passed to MetricReader.""" | |
| custom_aggregation = { | |
| HistogramInstrument: ExplicitBucketHistogramAggregation( | |
| boundaries=[1.0, 5.0, 10.0] | |
| ) | |
| reader = PrometheusMetricReader( | |
| default_aggregation=custom_aggregation | |
| ) | |
| self.assertEqual( | |
| reader._instrument_class_aggregation[ | |
| HistogramInstrument | |
| ].__class__, | |
| ExplicitBucketHistogramAggregation, | |
| ) | |
| reader.shutdown() |
| ObservableUpDownCounter: AggregationTemporality.CUMULATIVE, | ||
| ObservableGauge: AggregationTemporality.CUMULATIVE, | ||
| }, | ||
| preferred_aggregation=default_aggregation, |
Member
There was a problem hiding this comment.
Why call this default_aggregation here? Would be nice to keep consistent as preferred_aggregation.
| ## Unreleased | ||
|
|
||
| - `opentelemetry-exporter-prometheus`: Add `default_aggregation` parameter to `PrometheusMetricReader` to allow configuring default aggregation per instrument kind | ||
| ([#5109](https://github.com/open-telemetry/opentelemetry-python/issues/5109)) |
Member
There was a problem hiding this comment.
Suggested change
| ([#5109](https://github.com/open-telemetry/opentelemetry-python/issues/5109)) | |
| ([#5117](https://github.com/open-telemetry/opentelemetry-python/issues/5117)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add
default_aggregationparameter toPrometheusMetricReaderto allow configuring default aggregation per instrument kind, aligning with the Prometheus Exporter spec.Fixes #5109
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
test_default_aggregationin test_prometheus_exporter.pythat verifies custom aggregation is correctly passed to the MetricReader.
Does This PR Require a Contrib Repo Change?
Checklist: