Skip to content

feat(exporter-prometheus): add config option for default aggregation - #6761

Open
ArthurSens wants to merge 2 commits into
open-telemetry:mainfrom
ArthurSens:prom-default-aggregation
Open

feat(exporter-prometheus): add config option for default aggregation#6761
ArthurSens wants to merge 2 commits into
open-telemetry:mainfrom
ArthurSens:prom-default-aggregation

Conversation

@ArthurSens

Copy link
Copy Markdown
Member

Which problem is this PR solving?

Adds support for configuring the Prometheus exporter's MetricReader default aggregation as a function of instrument kind.
This implements the behavior described in the Prometheus exporter spec section being stabilized in open-telemetry/opentelemetry-specification#5113

Fixes # (issue)

Short description of the changes

  • Adds a defaultAggregation option to PrometheusExporter config.
  • Passes the configured aggregation selector through to the underlying MetricReader.
  • Keeps the existing default behavior by using SDK default aggregation when no option is configured.

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?

  • npm run compile --workspace=@opentelemetry/exporter-prometheus
  • npm run lint --workspace=@opentelemetry/exporter-prometheus -- --quiet
  • npm test -- --grep "defaultAggregation|default aggregation|configured defaultAggregation"

Checklist:

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

Disclaimer: This PR was assisted by LLMs

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
@ArthurSens
ArthurSens requested a review from a team as a code owner May 25, 2026 21:11
@codecov

codecov Bot commented May 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.95%. Comparing base (00aed14) to head (5d416ac).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6761   +/-   ##
=======================================
  Coverage   94.95%   94.95%           
=======================================
  Files         377      377           
  Lines       12743    12744    +1     
  Branches     2896     2897    +1     
=======================================
+ Hits        12100    12101    +1     
  Misses        643      643           
Files with missing lines Coverage Δ
...etry-exporter-prometheus/src/PrometheusExporter.ts 93.75% <100.00%> (+0.06%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
@pichlermarc pichlermarc self-assigned this Jul 1, 2026
@pichlermarc pichlermarc changed the title Add config option for Prometheus default aggregation feat(exporter-prometheus): add config option for default aggregation Jul 13, 2026
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Jul 18, 2026

Copy link
Copy Markdown

Pull request dashboard status

Status last refreshed: 2026-07-28 01:10:38 UTC.

  • Waiting on: Author
  • Next step: Address or respond to 1 review feedback item:
    • Top-level feedback: 1
    • For each item, reply to move the discussion forward, e.g. link to the commit that addresses it, explain why no change is needed, or ask a follow-up question.

This automated status or its linked feedback items may be incorrect. If something looks wrong, please report it with the result you expected. If you believe this pull request is incorrectly routed as waiting on the author, comment /dashboard route:reviewers to route it from waiting on the author to waiting on reviewers. If the last refreshed time above predates your latest reply or push, the dashboard hasn't processed it yet.

@pichlermarc pichlermarc left a comment

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.

Sorry for the late review on this PR. I think having AggreagationSelector be a function was a mistake we made, since it implies that changing the returned values after configuring the MetricReader (in this case PrometheusExporter) would re-configure already-created instruments, which is not the case.

Suggestion: let's implement this feature in a why that there's an aggregationPreference option that people can configure like so:

new PrometheusExporter({
  aggregationPreference: {
     gauge: {
       // this here is an AggregationOption
       type: AggregationType.LAST_VALUE
     },
     // non-specified ones fall back to default
  }
})

Internally, the aggregationPreference is converted to an aggregationSelector and published this way. This way it's clearer that nothing can be changed once the exporter has been instantiated. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants