-
Notifications
You must be signed in to change notification settings - Fork 631
feat: Stabilize more views - allow changing aggregation #3322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@ArniDagur Could you review, since you recently worked in this area! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3322 +/- ##
=======================================
+ Coverage 81.1% 81.8% +0.7%
=======================================
Files 129 129
Lines 23719 24366 +647
=======================================
+ Hits 19238 19938 +700
+ Misses 4481 4428 -53 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR stabilizes more of the metrics Views surface area by making aggregation customization available without the spec_unstable_metrics_views feature flag, and aligns view behavior with the spec by falling back to default aggregation when matching views are incompatible.
Changes:
- Make
AggregationandStreamBuilder::with_aggregation()usable withoutspec_unstable_metrics_views. - Update view resolution to “proceed as if the View did not match” when all matching views produce incompatible aggregators (with a warning).
- Add tests covering aggregation overrides via views (including exponential histogram) and incompatible aggregation fallback behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
opentelemetry-sdk/src/metrics/pipeline.rs |
Adjusts view matching behavior to ignore incompatible views and fall back to default aggregation; adds a warning log. |
opentelemetry-sdk/src/metrics/mod.rs |
Removes feature-gating around aggregation exports and adds multiple tests for view aggregation behavior. |
opentelemetry-sdk/src/metrics/internal/histogram.rs |
Removes feature-gated boundary sanitization logic now that boundaries are validated earlier. |
opentelemetry-sdk/src/metrics/instrument.rs |
Removes feature-gating for with_aggregation() and a related test gate. |
opentelemetry-sdk/CHANGELOG.md |
Documents stabilization of Aggregation and StreamBuilder::with_aggregation(). |
examples/metrics-advanced/Cargo.toml |
Updates the example to use stable metrics feature instead of the unstable views feature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // If at least one view matched and produced a valid aggregator, return it. | ||
| // If views matched but all failed (e.g., incompatible aggregation), fall through | ||
| // to apply the default view per the spec: "proceed as if the View did not [match]". | ||
| if matched && !measures.is_empty() { | ||
| return Ok(measures); |
Copilot
AI
Jan 24, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new early-return condition if matched && !measures.is_empty() breaks Aggregation::Drop views. When a view matches and selects Aggregation::Drop, cached_aggregator returns Ok(None) and the code continues, leaving measures empty and errs empty. This then falls through to the implicit default view and creates a default aggregator, so the instrument is no longer dropped.
Consider treating Ok(None) as a successful view application: only fall back to the default when matched && measures.is_empty() && !errs.is_empty() (i.e., all matching views failed), and otherwise return Ok(measures) even if empty.
| // LastValue aggregation is only valid for Gauge instruments. | ||
| // When applied to a Counter via a view, the view is ignored and | ||
| // the default aggregation (Sum) is used per the spec: | ||
| // "proceed as if the View did not match" |
Copilot
AI
Jan 24, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR description says we "restrict certain aggregations (Counters can be aggregated using LastValue...)", but this test (and is_aggregator_compatible) treats LastValue as incompatible for Counter and falls back to Sum. Please update the PR description to match the implemented behavior (or adjust the behavior if the description is the intent).
Was initially kept under feature flag to keep scope under control. Stabilizing more and more things now!
Also added additional tests as users can now change Aggregations -