Skip to content

feat(exporter/prometheus): add default_aggregation parameter to PrometheusMetricReader#5117

Open
Manvi2402 wants to merge 5 commits intoopen-telemetry:mainfrom
Manvi2402:fix/prometheus-default-aggregation
Open

feat(exporter/prometheus): add default_aggregation parameter to PrometheusMetricReader#5117
Manvi2402 wants to merge 5 commits intoopen-telemetry:mainfrom
Manvi2402:fix/prometheus-default-aggregation

Conversation

@Manvi2402
Copy link
Copy Markdown
Contributor

Description

Add default_aggregation parameter to PrometheusMetricReader to 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.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Test A: Added unit test test_default_aggregation in test_prometheus_exporter.py
    that verifies custom aggregation is correctly passed to the MetricReader.

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Copy link
Copy Markdown
Member

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the indentation and updated the test to use public API instead of internal attributes

ObservableUpDownCounter: AggregationTemporality.CUMULATIVE,
ObservableGauge: AggregationTemporality.CUMULATIVE,
},
preferred_aggregation=default_aggregation,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why call this default_aggregation here? Would be nice to keep consistent as preferred_aggregation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to preferred_aggregation for consistency.

Comment thread CHANGELOG.md Outdated
## 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))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
([#5109](https://github.com/open-telemetry/opentelemetry-python/issues/5109))
([#5117](https://github.com/open-telemetry/opentelemetry-python/issues/5117))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think #5109 is the correct issue number here, #5117 is the PR number. Please correct me if I'm wrong.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer the changelog to use the PR number, not the associated issue number. You're welcome to add the issue number to the PR description if it's not there already 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying. Updated the changelog to use the PR number and also renamed default_aggregation to preferred_aggregation in the changelog entry.

@github-project-automation github-project-automation bot moved this to Reviewed PRs that need fixes in Python PR digest Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

Stabilize Prometheus Exporter: Default Aggregation

3 participants